model

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteFirmwareUpdate

func DeleteFirmwareUpdate(ctx context.Context, db bun.IDB, pmcMac net.HardwareAddr, comp powershelf.Component) error

DeleteFirmwareUpdate deletes a FirmwareUpdate by composite PK.

func SetFirmwareUpdateState added in v1.2.0

func SetFirmwareUpdateState(ctx context.Context, db bun.IDB, pmcMac net.HardwareAddr, comp powershelf.Component, newState powershelf.FirmwareState, errMsg string) error

SetFirmwareUpdateState transitions a firmware update identified by (pmcMac, comp) to newState with an optional error message in a single UPDATE (no prior SELECT).

Types

type FirmwareUpdate

type FirmwareUpdate struct {
	bun.BaseModel `bun:"table:firmware_update,alias:fu"`

	PmcMacAddress      MacAddr                  `bun:"pmc_mac_address,pk,notnull,type:macaddr"` // MAC address of the target PMC (FK to pmc.mac_address)
	Component          powershelf.Component     `bun:"component,pk,notnull"`                    // Component being updated (e.g., "PMC", "PSU1")
	VersionFrom        string                   `bun:"version_from,notnull"`                    // Firmware version before upgrade
	VersionTo          string                   `bun:"version_to,notnull"`                      // Target firmware version after upgrade
	State              powershelf.FirmwareState `bun:"state,notnull"`                           // Upgrade state ("Queued", "Updating", "Completed", "Failed", etc.)
	LastTransitionTime time.Time                `bun:"last_transition_time,notnull"`            // When the state last changed
	JobID              string                   `bun:"job_id"`                                  // Device job/task ID, if provided by hardware
	ErrorMessage       string                   `bun:"error_message"`                           // Error message if the upgrade failed
	CreatedAt          time.Time                `bun:"created_at,notnull,default:now()"`        // When this record was created
	UpdatedAt          time.Time                `bun:"updated_at,notnull,default:now()"`        // When this record was last updated
}

FirmwareUpdate represents the latest firmware update operation for a specific component of a PMC (Power Management Controller). The composite primary key is (PmcMacAddress, Component).

func GetAllPendingFirmwareUpdates

func GetAllPendingFirmwareUpdates(ctx context.Context, db bun.IDB) ([]FirmwareUpdate, error)

GetAllPendingFirmwareUpdates lists all non-terminal firmware updates across all PMCs

func GetFirmwareUpdate

func GetFirmwareUpdate(ctx context.Context, db bun.IDB, pmcMac net.HardwareAddr, comp powershelf.Component) (*FirmwareUpdate, error)

GetFirmwareUpdate fetches a FirmwareUpdate by composite PK (pmcMac, comp).

func ListFirmwareUpdatesForPMC

func ListFirmwareUpdatesForPMC(ctx context.Context, db bun.IDB, pmcMac net.HardwareAddr, comp *powershelf.Component) ([]FirmwareUpdate, error)

ListFirmwareUpdatesForPMC lists all firmware updates for a given PMC (optionally filter by component).

func NewFirmwareUpdate

func NewFirmwareUpdate(ctx context.Context, db bun.IDB, pmcMac net.HardwareAddr, comp powershelf.Component, vStart, vTarget string) (*FirmwareUpdate, error)

NewFirmwareUpdate creates and inserts (or upserts) a FirmwareUpdate record using the composite PK. If a record already exists for (pmcMac, comp), it will be replaced.

func (*FirmwareUpdate) Create

func (fu *FirmwareUpdate) Create(ctx context.Context, tx bun.Tx) error

Create inserts a new FirmwareUpdate row.

func (*FirmwareUpdate) Get

func (fu *FirmwareUpdate) Get(
	ctx context.Context,
	idb bun.IDB,
) (*FirmwareUpdate, error)

Get retrieves a FirmwareUpdate by MAC and component (both must be specified).

func (*FirmwareUpdate) IsTerminal

func (fu *FirmwareUpdate) IsTerminal() bool

IsTerminal returns true if the firmware update is in a terminal state.

func (*FirmwareUpdate) SetJobID

func (fu *FirmwareUpdate) SetJobID(ctx context.Context, db bun.IDB, jobID string) error

SetJobID sets the job ID for a FirmwareUpdate and persists it.

func (*FirmwareUpdate) SetVersionTarget

func (fu *FirmwareUpdate) SetVersionTarget(ctx context.Context, db bun.IDB, vTarget string) error

SetVersionTarget sets the target version for a FirmwareUpdate and persists it.

func (*FirmwareUpdate) UpdateFirmwareUpdateState

func (fu *FirmwareUpdate) UpdateFirmwareUpdateState(ctx context.Context, db bun.IDB, newState powershelf.FirmwareState, errMsg string) error

UpdateFirmwareUpdateState sets the state and optional error message for a FirmwareUpdate. Only updates LastTransitionTime if the state actually changes.

type IPAddr

type IPAddr net.IP

IPAddr wraps net.IP to provide proper SQL driver support for PostgreSQL inet type.

func (IPAddr) Equal

func (ip IPAddr) Equal(other IPAddr) bool

Equal returns true if the two IPAddr are equal.

func (IPAddr) IP

func (ip IPAddr) IP() net.IP

IP returns the underlying net.IP.

func (*IPAddr) Scan

func (ip *IPAddr) Scan(src interface{}) error

Scan implements sql.Scanner for IPAddr. Handles both string and []byte inputs from PostgreSQL.

func (IPAddr) String

func (ip IPAddr) String() string

String returns the IP address as a string.

func (IPAddr) Value

func (ip IPAddr) Value() (driver.Value, error)

Value implements driver.Valuer for IPAddr. Converts the IP address to a string format that PostgreSQL's inet type expects.

type MacAddr

type MacAddr net.HardwareAddr

MacAddr wraps net.HardwareAddr to provide proper SQL driver support for PostgreSQL macaddr type.

func (MacAddr) HardwareAddr

func (m MacAddr) HardwareAddr() net.HardwareAddr

HardwareAddr returns the underlying net.HardwareAddr.

func (*MacAddr) Scan

func (m *MacAddr) Scan(src interface{}) error

Scan implements sql.Scanner for MacAddr. Handles both string and []byte inputs from PostgreSQL.

func (MacAddr) String

func (m MacAddr) String() string

String returns the MAC address as a string.

func (MacAddr) Value

func (m MacAddr) Value() (driver.Value, error)

Value implements driver.Valuer for MacAddr. Converts the MAC address to a string format that PostgreSQL's macaddr type expects.

type PMC

type PMC struct {
	bun.BaseModel `bun:"table:pmc,alias:p"`

	MacAddress MacAddr           `bun:"mac_address,pk,unique,notnull,type:macaddr"`
	Vendor     vendor.VendorCode `bun:"vendor,notnull"`
	IPAddress  IPAddr            `bun:"ip_address,unique,notnull,type:inet"`
}

PMC is the database model for a power shelf PMC with unique MAC and IP and a vendor code.

func (*PMC) BuildPatch

func (pmc *PMC) BuildPatch(cur *PMC) *PMC

BuildPatch copies changed patchable fields from cur; returns nil if no changes.

func (*PMC) Create

func (pmc *PMC) Create(ctx context.Context, tx bun.Tx) error

Create inserts a new PMC row.

func (*PMC) Get

func (pmc *PMC) Get(
	ctx context.Context,
	idb bun.IDB,
) (*PMC, error)

Get retrieves a PMC by MAC or IP (one must be specified).

func (*PMC) InvalidType

func (pmc *PMC) InvalidType() bool

InvalidType returns true if the PMC's vendor code is unsupported.

func (*PMC) Patch

func (pmc *PMC) Patch(ctx context.Context, idb bun.IDB) error

Patch updates the PMC row by MAC address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL