state

package
v0.0.0-...-c030021 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: AGPL-3.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type State

type State struct {
	*domain.StateBase
	// contains filtered or unexported fields
}

State describes retrieval and persistence methods for storage.

func NewState

func NewState(factory coredb.TxnRunnerFactory, clock clock.Clock, logger logger.Logger) *State

NewState returns a new state reference.

func (*State) AllMachineNames

func (st *State) AllMachineNames(ctx context.Context) ([]machine.Name, error)

AllMachineNames retrieves the names of all machines in the model.

func (*State) AppliedLXDProfileNames

func (st *State) AppliedLXDProfileNames(ctx context.Context, mUUID string) ([]string, error)

AppliedLXDProfileNames returns the names of the LXD profiles on the machine.

func (*State) AvailabilityZone

func (st *State) AvailabilityZone(
	ctx context.Context,
	machineUUID string,
) (string, error)

AvailabilityZone returns the availability zone for the specified machine. If no hardware characteristics are set for the machine, it returns machineerrors.AvailabilityZoneNotFound.

func (*State) ClearMachineReboot

func (st *State) ClearMachineReboot(ctx context.Context, uuid string) error

ClearMachineReboot removes the reboot flag of the machine referenced by its UUID if a reboot has previously been required.

It basically removes the uuid from the "machine_requires_reboot" table if present. This function is idempotent.

func (*State) CreateMachine

func (st *State) CreateMachine(ctx context.Context, machineName machine.Name, nodeUUID, machineUUID string) error

CreateMachine creates or updates the specified machine. Adds a row to machine table, as well as a row to the net_node table. It returns a MachineAlreadyExists error if a machine with the same name already exists.

func (*State) CreateMachineWithParent

func (st *State) CreateMachineWithParent(ctx context.Context, machineName, parentName machine.Name, nodeUUID, machineUUID string) error

CreateMachineWithParent creates or updates the specified machine with a parent. Adds a row to machine table, as well as a row to the net_node table, and adds a row to the machine_parent table for associating with the specified parent. It returns a MachineNotFound error if the parent machine does not exist. It returns a MachineAlreadyExists error if a machine with the same name already exists.

func (*State) DeleteMachine

func (st *State) DeleteMachine(ctx context.Context, mName machine.Name) error

DeleteMachine deletes the specified machine and any dependent child records. TODO - this just deals with child block devices for now.

func (*State) DeleteMachineCloudInstance

func (st *State) DeleteMachineCloudInstance(
	ctx context.Context,
	mUUID string,
) error

DeleteMachineCloudInstance removes an entry in the machine cloud instance table along with the instance tags and the link to a lxd profile if any, as well as any associated status data.

func (*State) GetAllMachineRemovals

func (st *State) GetAllMachineRemovals(ctx context.Context) ([]string, error)

GetAllMachineRemovals returns the UUIDs of all of the machines that need to be removed but need provider-level cleanup.

func (*State) GetInstanceStatus

GetInstanceStatus returns the cloud specific instance status for the given machine. It returns NotFound if the machine does not exist. It returns a StatusNotSet if the instance status is not set. Idempotent.

func (*State) GetMachineLife

func (st *State) GetMachineLife(ctx context.Context, mName machine.Name) (*life.Life, error)

GetMachineLife returns the life status of the specified machine. It returns a MachineNotFound if the given machine doesn't exist.

func (*State) GetMachineParentUUID

func (st *State) GetMachineParentUUID(ctx context.Context, uuid string) (string, error)

GetMachineParentUUID returns the parent UUID of the specified machine. It returns a MachineNotFound if the machine does not exist. It returns a MachineHasNoParent if the machine has no parent.

func (*State) GetMachineStatus

GetMachineStatus returns the status of the specified machine. It returns MachineNotFound if the machine does not exist. It returns a StatusNotSet if the status is not set. Idempotent.

func (*State) GetMachineUUID

func (st *State) GetMachineUUID(ctx context.Context, name machine.Name) (string, error)

GetMachineUUID returns the UUID of a machine identified by its name. It returns a MachineNotFound if the machine does not exist.

func (*State) HardwareCharacteristics

func (st *State) HardwareCharacteristics(
	ctx context.Context,
	machineUUID string,
) (*instance.HardwareCharacteristics, error)

HardwareCharacteristics returns the hardware characteristics struct with data retrieved from the machine cloud instance table.

func (*State) InitialWatchModelMachinesStatement

func (st *State) InitialWatchModelMachinesStatement() (string, string)

InitialWatchModelMachinesStatement returns the table and the initial watch statement for watching life changes of non-container machines.

func (*State) InitialWatchStatement

func (st *State) InitialWatchStatement() (string, string)

InitialWatchStatement returns the table and the initial watch statement for the machines.

func (*State) InstanceID

func (st *State) InstanceID(ctx context.Context, mUUID string) (string, error)

InstanceID returns the cloud specific instance id for this machine. If the machine is not provisioned, it returns a machineerrors.NotProvisionedError.

func (*State) InstanceIDAndName

func (st *State) InstanceIDAndName(ctx context.Context, mUUID string) (string, string, error)

InstanceIDAndName returns the cloud specific instance ID and display name for this machine. If the machine is not provisioned, it returns a machineerrors.NotProvisionedError.

func (*State) IsMachineController

func (st *State) IsMachineController(ctx context.Context, mName machine.Name) (bool, error)

IsMachineController returns whether the machine is a controller machine. It returns a NotFound if the given machine doesn't exist.

func (*State) IsMachineRebootRequired

func (st *State) IsMachineRebootRequired(ctx context.Context, uuid string) (bool, error)

IsMachineRebootRequired checks if the specified machine requires a reboot.

It queries the "machine_requires_reboot" table for the machine UUID to determine if a reboot is required. Returns a boolean value indicating if a reboot is required, and an error if any occur during the process.

func (*State) MarkMachineForRemoval

func (st *State) MarkMachineForRemoval(ctx context.Context, mName machine.Name) error

MarkMachineForRemoval marks the specified machine for removal. It returns NotFound if the machine does not exist. TODO(cderici): use machineerrors.MachineNotFound on rebase after #17759 lands. Idempotent.

func (*State) RequireMachineReboot

func (st *State) RequireMachineReboot(ctx context.Context, uuid string) error

RequireMachineReboot sets the machine referenced by its UUID as requiring a reboot.

Reboot requests are handled through the "machine_requires_reboot" table which contains only machine UUID for which a reboot has been requested. This function is idempotent.

func (*State) SetAppliedLXDProfileNames

func (st *State) SetAppliedLXDProfileNames(ctx context.Context, mUUID string, profileNames []string) error

SetAppliedLXDProfileNames sets the list of LXD profile names to the lxd_profile table for the given machine. This method will overwrite the list of profiles for the given machine without any checks. machineerrors.MachineNotFound will be returned if the machine does not exist.

func (*State) SetInstanceStatus

func (st *State) SetInstanceStatus(ctx context.Context, mName machine.Name, newStatus domainmachine.StatusInfo[domainmachine.InstanceStatusType]) error

SetInstanceStatus sets the cloud specific instance status for this machine. It returns machineerrors.MachineNotFound if the machine does not exist.

func (*State) SetKeepInstance

func (st *State) SetKeepInstance(ctx context.Context, mName machine.Name, keep bool) error

SetKeepInstance sets whether the machine cloud instance will be retained when the machine is removed from Juju. This is only relevant if an instance exists.

func (*State) SetMachineCloudInstance

func (st *State) SetMachineCloudInstance(
	ctx context.Context,
	machineUUID string,
	instanceID instance.Id,
	displayName string,
	hardwareCharacteristics *instance.HardwareCharacteristics,
) error

SetMachineCloudInstance sets an entry in the machine cloud instance table along with the instance tags and the link to a lxd profile if any.

func (*State) SetMachineLife

func (st *State) SetMachineLife(ctx context.Context, mName machine.Name, life life.Life) error

SetMachineLife sets the life status of the specified machine. It returns a MachineNotFound if the provided machine doesn't exist.

func (*State) SetMachineStatus

func (st *State) SetMachineStatus(ctx context.Context, mName machine.Name, newStatus domainmachine.StatusInfo[domainmachine.MachineStatusType]) error

SetMachineStatus sets the status of the specified machine. It returns MachineNotFound if the machine does not exist.

func (*State) ShouldKeepInstance

func (st *State) ShouldKeepInstance(ctx context.Context, mName machine.Name) (bool, error)

ShouldKeepInstance reports whether a machine, when removed from Juju, should cause the corresponding cloud instance to be stopped.

func (*State) ShouldRebootOrShutdown

func (st *State) ShouldRebootOrShutdown(ctx context.Context, uuid string) (coremachine.RebootAction, error)

ShouldRebootOrShutdown determines if a machine should reboot or shutdown based on its state and parent's state.

The function first checks if a parent machine exists and requires a reboot. If so, it returns ShouldShutdown immediately.

If the parent machine does not require a reboot, the function checks if the current machine requires a reboot. If so, it returns ShouldReboot. If neither the parent machine nor the current machine require a reboot, it returns ShouldDoNothing.

The function also check if there is a grandparent machine, which is not supported. In this case, the function returns an errors.GrandParentNotSupported.

The function returns any error issued through interaction with the database, annotated with the UUID of the machine.

Jump to

Keyboard shortcuts

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