state

package
v0.0.0-...-c3d9892 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: 30 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloudSupportsAuthType

func CloudSupportsAuthType(
	ctx context.Context,
	preparer domain.Preparer,
	tx *sqlair.TX,
	cloudName string,
	authType cloud.AuthType,
) (bool, error)

CloudSupportsAuthType allows the caller to ask if a given auth type is currently supported by the given cloud name. If no cloud is found for name an error matching clouderrors.NotFound is returned.

func CloudType

func CloudType() func(context.Context, domain.Preparer, *sqlair.TX, string) (string, error)

CloudType returns a closure for reporting the type for a given cloud name. If no cloud exists for the provided name then an error of clouderrors.NotFound will be returned.

func Create

func Create(
	ctx context.Context,
	preparer domain.Preparer,
	tx *sqlair.TX,
	modelID coremodel.UUID,
	modelType coremodel.ModelType,
	input model.GlobalModelCreationArgs,
) error

Create is responsible for creating a new model from start to finish. It will register the model existence and associate all of the model metadata.

The following errors can be expected: - modelerrors.AlreadyExists when a model already exists with the same name and owner - errors.NotSupported When the new models type cannot be found. - errors.NotFound Should the provided cloud and region not be found. - [usererrors.NotFound] When the model owner does not exist. - secretbackenderrors.NotFound When the secret backend for the model cannot be found.

func GetModel

func GetModel(
	ctx context.Context,
	tx *sqlair.TX,
	uuid coremodel.UUID,
) (coremodel.Model, error)

GetModel returns the model associated with the provided uuid. If the model does not exist then an error satisfying modelerrors.NotFound will be returned.

func GetModelType

func GetModelType(
	ctx context.Context,
	preparer domain.Preparer,
	tx *sqlair.TX,
	uuid coremodel.UUID,
) (coremodel.ModelType, error)

GetModelType returns the model type for the provided model uuid. If the model does not exist then an error satisfying modelerrors.NotFound will be returned.

func InsertModelInfo

func InsertModelInfo(
	ctx context.Context, args model.ModelDetailArgs, preparer domain.Preparer, tx *sqlair.TX,
) error

InsertModelInfo is responsible for creating a new model within the model database. If the model already exists then an error satisfying modelerrors.AlreadyExists is returned.

func SetModelConstraints

func SetModelConstraints(
	ctx context.Context,
	preparer domain.Preparer,
	tx *sqlair.TX,
	cons constraints.Constraints,
) error

SetModelConstraints sets the model constraints to the new values removing any previously set values. The following error types can be expected: - networkerrors.SpaceNotFound: when a space constraint is set but the space does not exist. - machineerrors.InvalidContainerType: when the container type set on the constraints is invalid. - modelerrors.NotFound: when no model exists to set constraints for.

Types

type ActivatorFunc

type ActivatorFunc func(context.Context, domain.Preparer, *sqlair.TX, coremodel.UUID) error

ActivatorFunc is responsible for setting a model as fully constructed and indicates the final system state for the model is ready for use. This is used because the model creation process involves several transactions with which anyone could fail at a given time.

If no model exists for the provided id then a modelerrors.NotFound will be returned. If the model as previously been activated a modelerrors.AlreadyActivated error will be returned.

func GetActivator

func GetActivator() ActivatorFunc

GetActivator constructs a [ActivateFunc] that can safely be used over several transaction retries.

type ModelState

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

ModelState represents a type for interacting with the underlying model database state.

func NewModelState

func NewModelState(
	factory database.TxnRunnerFactory,
	logger logger.Logger,
) *ModelState

NewModelState returns a new State for interacting with the underlying model database state.

func (*ModelState) Create

func (s *ModelState) Create(ctx context.Context, args model.ModelDetailArgs) error

Create inserts all of the information about a newly created model.

func (*ModelState) Delete

func (s *ModelState) Delete(ctx context.Context, uuid coremodel.UUID) error

Delete deletes a model.

func (*ModelState) GetModel

func (s *ModelState) GetModel(ctx context.Context) (coremodel.ModelInfo, error)

GetModel returns model information that has been set in the database. If no model has been set then an error satisfying modelerrors.NotFound is returned.

func (*ModelState) GetModelCloudType

func (s *ModelState) GetModelCloudType(ctx context.Context) (string, error)

GetModelCloudType returns the cloud type from a model that has been set in the database. If no model exists then an error satisfying modelerrors.NotFound is returned.

func (*ModelState) GetModelConstraints

func (s *ModelState) GetModelConstraints(
	ctx context.Context,
) (constraints.Constraints, error)

GetModelConstraints returns the currently set constraints for the model. The following error types can be expected: - modelerrors.NotFound: when no model exists to set constraints for. - modelerrors.ConstraintsNotFound: when no model constraints have been set for the model.

func (*ModelState) GetModelMetrics

func (s *ModelState) GetModelMetrics(ctx context.Context) (coremodel.ModelMetrics, error)

GetModelMetrics the current model info and its associated metrics. If no model has been set then an error satisfying modelerrors.NotFound is returned.

func (*ModelState) SetModelConstraints

func (s *ModelState) SetModelConstraints(
	ctx context.Context,
	cons constraints.Constraints,
) error

SetModelConstraints sets the model constraints to the new values removing any previously set values. The following error types can be expected: - networkerrors.SpaceNotFound: when a space constraint is set but the space does not exist. - machineerrors.InvalidContainerType: when the container type set on the constraints is invalid. - modelerrors.NotFound: when no model exists to set constraints for.

type State

type State struct {
	*domain.StateBase
}

State represents a type for interacting with the underlying model state.

func NewState

func NewState(
	factory database.TxnRunnerFactory,
) *State

NewState returns a new State for interacting with the underlying model state.

func (*State) Activate

func (s *State) Activate(ctx context.Context, uuid coremodel.UUID) error

Activate is responsible for setting a model as fully constructed and indicates the final system state for the model is ready for use. This is used because the model creation process involves several transactions with which anyone could fail at a given time.

If no model exists for the provided id then a modelerrors.NotFound will be returned. If the model has previously been activated a modelerrors.AlreadyActivated error will be returned.

func (*State) CloudSupportsAuthType

func (s *State) CloudSupportsAuthType(
	ctx context.Context,
	cloudName string,
	authType cloud.AuthType,
) (bool, error)

CloudSupportsAuthType allows the caller to ask if a given auth type is currently supported by the given cloud name. If no cloud is found for name an error matching clouderrors.NotFound is returned.

func (*State) CloudType

func (s *State) CloudType(
	ctx context.Context,
	name string,
) (string, error)

CloudType is responsible for reporting the type for a given cloud name. If no cloud exists for the provided name then an error of clouderrors.NotFound will be returned.

func (*State) Create

func (s *State) Create(
	ctx context.Context,
	modelID coremodel.UUID,
	modelType coremodel.ModelType,
	input model.GlobalModelCreationArgs,
) error

Create is responsible for creating a new model from start to finish. It will register the model existence and associate all of the model metadata.

The following errors can be expected: - modelerrors.AlreadyExists when a model already exists with the same name and owner - errors.NotSupported When the new models type cannot be found. - errors.NotFound Should the provided cloud and region not be found. - [usererrors.NotFound] When the model owner does not exist. - secretbackenderrors.NotFound When the secret backend for the model cannot be found.

func (*State) Delete

func (s *State) Delete(
	ctx context.Context,
	uuid coremodel.UUID,
) error

Delete will remove all data associated with the provided model uuid removing the models existence from Juju. If the model does not exist then a error satisfying modelerrors.NotFound will be returned. The following items are removed as part of deleting a model: - Authorized keys for a model. - Secret backends - Secret backend ref counting - Model agent information - Model permissions - Model login information

func (*State) GetControllerModel

func (s *State) GetControllerModel(ctx context.Context) (coremodel.Model, error)

GetControllerModel returns the model the controller is running in. If no controller model exists then an error satisfying modelerrors.NotFound is returned.

func (*State) GetControllerModelUUID

func (s *State) GetControllerModelUUID(ctx context.Context) (coremodel.UUID, error)

GetControllerModelUUID returns the model uuid for the controller model. If no controller model exists then an error satisfying modelerrors.NotFound is returned.

func (*State) GetModel

func (s *State) GetModel(ctx context.Context, uuid coremodel.UUID) (coremodel.Model, error)

GetModel returns the model associated with the provided uuid. If the model does not exist then an error satisfying modelerrors.NotFound will be returned.

func (*State) GetModelByName

func (s *State) GetModelByName(
	ctx context.Context,
	username user.Name,
	modelName string,
) (coremodel.Model, error)

GetModelByName returns the model found for the given username and model name for which there can only be one. Should no model be found for the provided search criteria an error satisfying modelerrors.NotFound will be returned.

func (*State) GetModelCloudNameAndCredential

func (s *State) GetModelCloudNameAndCredential(
	ctx context.Context,
	uuid coremodel.UUID,
) (string, credential.Key, error)

GetModelCloudNameAndCredential returns the cloud name and credential id for a model identified by uuid. If no model exists for the provided uuid a modelerrors.NotFound error is returned.

func (*State) GetModelInfo

func (s *State) GetModelInfo(
	ctx context.Context,
	modelUUID coremodel.UUID,
) (coremodel.ModelInfo, error)

GetModelInfo returns the model associated with the provided uuid. This will return a model, even if it's not activated, so it can be used to determine the model's status. If the model does not exist then an error satisfying modelerrors.NotFound will be returned.

func (*State) GetModelState

func (s *State) GetModelState(ctx context.Context, uuid coremodel.UUID) (model.ModelState, error)

GetModelState is responsible for returning a set of boolean indicators for key aspects about a model so that a model's status can be derived from this information. If no model exists for the provided UUID then an error satisfying modelerrors.NotFound will be returned.

func (*State) GetModelType

func (s *State) GetModelType(ctx context.Context, uuid coremodel.UUID) (coremodel.ModelType, error)

GetModelType returns the model type for the provided model uuid. If the model does not exist then an error satisfying modelerrors.NotFound will be returned.

func (*State) GetModelTypes

func (s *State) GetModelTypes(ctx context.Context) ([]coremodel.ModelType, error)

GetModelTypes returns the slice of model.Type's supported by state.

func (*State) GetModelUsers

func (st *State) GetModelUsers(ctx context.Context, modelUUID coremodel.UUID) ([]coremodel.ModelUserInfo, error)

GetModelUsers will retrieve basic information about all users with permissions on the given model UUID. If the model cannot be found it will return modelerrors.NotFound.

func (*State) ListAllModelSummaries

func (s *State) ListAllModelSummaries(ctx context.Context) ([]coremodel.ModelSummary, error)

ListAllModelSummaries lists summaries of all the models known to the controller. It does not fill in the access or last model login since there is no subject user for the model summary. TODO(aflynn): 05-08-2024 - The ModelSummary struct includes a machine count, unit count and cpu core count, model status as well as migration status. This information has not yet been migrated over to the relational database. Once it has, it needs to be included here.

func (*State) ListAllModels

func (s *State) ListAllModels(ctx context.Context) ([]coremodel.Model, error)

ListAllModels returns a slice of all models in the controller. If no models exist an empty slice is returned.

func (*State) ListModelIDs

func (s *State) ListModelIDs(ctx context.Context) ([]coremodel.UUID, error)

ListModelIDs returns a list of all model UUIDs in the system that have not been deleted.

func (*State) ListModelSummariesForUser

func (s *State) ListModelSummariesForUser(ctx context.Context, userName user.Name) ([]coremodel.UserModelSummary, error)

ListModelSummariesForUser lists model summaries of all models the user has access to. If no models are found then a nil slice is returned. TODO(aflynn): 05-08-2024 - The ModelSummary struct includes a machine count, unit count and cpu core count, model status as well as migration status. This information has not yet been migrated over to the relational database. Once it has, it needs to be included here.

func (*State) ListModelsForUser

func (s *State) ListModelsForUser(
	ctx context.Context,
	userID user.UUID,
) ([]coremodel.Model, error)

ListModelsForUser returns a slice of models owned or accessible by the user specified by the user id. If No user or models are found an empty slice is returned.

func (*State) NamespaceForModel

func (s *State) NamespaceForModel(ctx context.Context, id coremodel.UUID) (string, error)

NamespaceForModel returns the database namespace that is provisioned for a model id. If no model is found for the given id then a modelerrors.NotFound error is returned. If no namespace has been provisioned for the model then a modelerrors.ModelNamespaceNotFound error is returned.

func (*State) UpdateCredential

func (s *State) UpdateCredential(
	ctx context.Context,
	uuid coremodel.UUID,
	key credential.Key,
) error

UpdateCredential is responsible for updating the cloud credential in use by model. If the cloud credential is not found an error that satisfies errors.NotFound is returned. If the credential being updated to is not of the same cloud that is currently set for the model then an error that satisfies errors.NotValid is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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