Documentation
¶
Overview ¶
Package service contains the services required for interacting with the underlying models within a Juju controller. This includes the management of models and the respective information for each model.
Model status ¶
Juju considers a model's status as purely a user interface value and not a programmatic one that should be used for informing the operation of the business logic of the controller.
A model can be in one of the following states: - Available: the model is fully operational. - Suspended: the model's cloud credential is considered invalid and the model is unable to perform operations on the cloud/provider. - Destroying: the model and its resources are being destroyed and are about to go away. - Busy: the model is currently being migrated to another controller or the model is being migrated into the current controller.
Index ¶
- func ModelTypeForCloud(ctx context.Context, state ModelTypeState, cloudName string) (coremodel.ModelType, error)
- type AgentBinaryFinder
- type ControllerState
- type EnvironVersionProvider
- type EnvironVersionProviderFunc
- type ModelActivator
- type ModelDeleter
- type ModelService
- func (s *ModelService) CreateModel(ctx context.Context, controllerUUID uuid.UUID) error
- func (s *ModelService) DeleteModel(ctx context.Context) error
- func (s *ModelService) GetEnvironVersion(ctx context.Context) (int, error)
- func (s *ModelService) GetModelConstraints(ctx context.Context) (constraints.Value, error)
- func (s *ModelService) GetModelInfo(ctx context.Context) (coremodel.ModelInfo, error)
- func (s *ModelService) GetModelMetrics(ctx context.Context) (coremodel.ModelMetrics, error)
- func (s *ModelService) GetStatus(ctx context.Context) (model.StatusInfo, error)
- func (s *ModelService) SetModelConstraints(ctx context.Context, cons constraints.Value) error
- type ModelState
- type ModelTypeState
- type ProviderService
- type ProviderState
- type Service
- func (s *Service) ControllerModel(ctx context.Context) (coremodel.Model, error)
- func (s *Service) CreateModel(ctx context.Context, args model.GlobalModelCreationArgs) (coremodel.UUID, func(context.Context) error, error)
- func (s *Service) DefaultModelCloudNameAndCredential(ctx context.Context) (string, credential.Key, error)
- func (s *Service) DeleteModel(ctx context.Context, uuid coremodel.UUID, opts ...model.DeleteModelOption) error
- func (s *Service) GetModelUser(ctx context.Context, modelUUID coremodel.UUID, name coreuser.Name) (coremodel.ModelUserInfo, error)
- func (s *Service) GetModelUsers(ctx context.Context, modelUUID coremodel.UUID) ([]coremodel.ModelUserInfo, error)
- func (s *Service) ImportModel(ctx context.Context, args model.ModelImportArgs) (func(context.Context) error, error)
- func (s *Service) ListAllModelSummaries(ctx context.Context) ([]coremodel.ModelSummary, error)
- func (s *Service) ListAllModels(ctx context.Context) ([]coremodel.Model, error)
- func (s *Service) ListModelIDs(ctx context.Context) ([]coremodel.UUID, error)
- func (s *Service) ListModelSummariesForUser(ctx context.Context, userName coreuser.Name) ([]coremodel.UserModelSummary, error)
- func (s *Service) ListModelsForUser(ctx context.Context, userID coreuser.UUID) ([]coremodel.Model, error)
- func (s *Service) Model(ctx context.Context, uuid coremodel.UUID) (coremodel.Model, error)
- func (s *Service) ModelType(ctx context.Context, uuid coremodel.UUID) (coremodel.ModelType, error)
- func (s *Service) UpdateCredential(ctx context.Context, uuid coremodel.UUID, key credential.Key) error
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModelTypeForCloud ¶
func ModelTypeForCloud( ctx context.Context, state ModelTypeState, cloudName string, ) (coremodel.ModelType, error)
ModelTypeForCloud is responsible returning the model type based on the cloud name being used for the model. If no cloud exists for the provided name then an error of [clouderrors.NotFound] will be returned.
Types ¶
type AgentBinaryFinder ¶
type AgentBinaryFinder interface { // HasBinariesForVersion will interrogate the tools available in the system // and return true or false if agent binaries exist for the provided // version. Any errors finding the requested binaries will be returned // through error. HasBinariesForVersion(version.Number) (bool, error) }
AgentBinaryFinder represents a helper for establishing if agent binaries for a specific Juju version are available.
func DefaultAgentBinaryFinder ¶
func DefaultAgentBinaryFinder() AgentBinaryFinder
DefaultAgentBinaryFinder is a transition implementation of the agent binary finder that will true for any version. This will be removed and replaced soon.
type ControllerState ¶
type ControllerState interface { // GetModel returns the model with the given UUID. GetModel(context.Context, coremodel.UUID) (coremodel.Model, error) // GetModelState returns the model state for the given model. // It returns [modelerrors.NotFound] if the model does not exist for the given UUID. GetModelState(context.Context, coremodel.UUID) (model.ModelState, error) }
ControllerState is the controller state required by this service. This is the controller database, not the model state.
type EnvironVersionProvider ¶
type EnvironVersionProvider interface { // Version returns the version of the provider. This is recorded as the // environ version for each model, and used to identify which upgrade // operations to run when upgrading a model's environ. Version() int }
EnvironVersionProvider defines a minimal subset of the EnvironProvider interface that focuses specifically on the provider's versioning capabilities.
type EnvironVersionProviderFunc ¶
type EnvironVersionProviderFunc func(string) (EnvironVersionProvider, error)
EnvironVersionProviderFunc describes a type that is able to return a EnvironVersionProvider for the specified cloud type. If no environ version provider exists for the supplied cloud type then a coreerrors.NotFound error is returned. If the cloud type provider does not support the EnvironVersionProvider interface then a coreerrors.NotSupported error is returned.
func EnvironVersionProviderGetter ¶
func EnvironVersionProviderGetter() EnvironVersionProviderFunc
EnvironVersionProviderGetter returns a EnvironVersionProviderFunc for retrieving an EnvironVersionProvider
type ModelActivator ¶
ModelActivator describes a closure type that must be called after creating a new model to indicate that all model creation operations have been performed and the model is active within the controller.
This type may return an error satisfying modelerrors.AlreadyActivated if the model in question has been activated already.
type ModelDeleter ¶
type ModelDeleter interface { // DeleteDB is responsible for removing a model from Juju and all of it's // associated metadata. DeleteDB(string) error }
ModelDeleter is an interface for deleting models.
type ModelService ¶
type ModelService struct {
// contains filtered or unexported fields
}
ModelService defines a service for interacting with the underlying model state, as opposed to the controller state.
func NewModelService ¶
func NewModelService( modelID coremodel.UUID, controllerSt ControllerState, modelSt ModelState, environProviderGetter EnvironVersionProviderFunc, ) *ModelService
NewModelService returns a new Service for interacting with a models state.
func (*ModelService) CreateModel ¶
CreateModel is responsible for creating a new model within the model database.
The following error types can be expected to be returned: - modelerrors.AlreadyExists: When the model uuid is already in use.
func (*ModelService) DeleteModel ¶
func (s *ModelService) DeleteModel( ctx context.Context, ) error
DeleteModel is responsible for removing a model from the system.
The following error types can be expected to be returned: - modelerrors.NotFound: When the model does not exist.
func (*ModelService) GetEnvironVersion ¶
func (s *ModelService) GetEnvironVersion(ctx context.Context) (int, error)
GetEnvironVersion retrieves the version of the environment provider associated with the model.
The following error types can be expected: - modelerrors.NotFound: Returned if the model does not exist.
func (*ModelService) GetModelConstraints ¶
func (s *ModelService) GetModelConstraints(ctx context.Context) (constraints.Value, error)
GetModelConstraints returns the current model constraints. It returns an error satisfying modelerrors.NotFound if the model does not exist. It returns an empty Value if the model does not have any constraints configured.
func (*ModelService) GetModelInfo ¶
GetModelInfo returns the readonly model information for the model in question.
func (*ModelService) GetModelMetrics ¶
func (s *ModelService) GetModelMetrics(ctx context.Context) (coremodel.ModelMetrics, error)
GetModelMetrics returns the model metrics information set in the database.
func (*ModelService) GetStatus ¶
func (s *ModelService) GetStatus(ctx context.Context) (model.StatusInfo, error)
GetStatus returns the current status of the model.
The following error types can be expected to be returned: - modelerrors.NotFound: When the model does not exist.
func (*ModelService) SetModelConstraints ¶
func (s *ModelService) SetModelConstraints(ctx context.Context, cons constraints.Value) error
SetModelConstraints sets the model constraints to the new values removing any previously set constraints.
The following error types can be expected: - modelerrors.NotFound: when the model does not exist - github.com/juju/juju/domain/network/errors.SpaceNotFound: when the space being set in the model constraint doesn't exist. - github.com/juju/juju/domain/machine/errors.InvalidContainerType: when the container type being set in the model constraint isn't valid.
type ModelState ¶
type ModelState interface { // Create creates a new model with all of its associated metadata. Create(context.Context, model.ModelDetailArgs) error // Delete deletes a model. Delete(context.Context, coremodel.UUID) error // GetModel returns the read only model information set in the database. GetModel(context.Context) (coremodel.ModelInfo, error) // GetModelMetrics returns the model metrics information set in the // database. GetModelMetrics(context.Context) (coremodel.ModelMetrics, error) // GetModelCloudType returns the model cloud type set in the database. GetModelCloudType(context.Context) (string, 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. GetModelConstraints(context.Context) (model.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. SetModelConstraints(context.Context, model.Constraints) error }
ModelState is the model state required by this service. This is the model database state, not the controller state.
type ModelTypeState ¶
type ModelTypeState interface { // 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. CloudType(context.Context, string) (string, error) }
ModelTypeState represents the state required for determining the type of model based on the cloud being set for it.
type ProviderService ¶
type ProviderService struct {
// contains filtered or unexported fields
}
ProviderService defines a service for interacting with the underlying model state, as opposed to the controller state.
func NewProviderService ¶
func NewProviderService(st ProviderState) *ProviderService
NewProviderService returns a new Service for interacting with a models state.
func (*ProviderService) Model ¶
Model returns model info for the current service.
The following error types can be expected to be returned: - modelerrors.NotFound: When the model is not found for a given uuid.
type ProviderState ¶
type ProviderState interface { // GetModel returns a the model info. GetModel(context.Context) (coremodel.ModelInfo, error) }
ProviderState is the model state required by the provide service. This is the model database state, not the controller state.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service defines a service for interacting with the underlying state based information of a model.
func NewService ¶
func NewService( st State, modelDeleter ModelDeleter, agentBinaryFinder AgentBinaryFinder, logger logger.Logger, ) *Service
NewService returns a new Service for interacting with a models state.
func (*Service) ControllerModel ¶
ControllerModel returns the model used for housing the Juju controller. Should no model exist for the controller an error of modelerrors.NotFound will be returned.
func (*Service) CreateModel ¶
func (s *Service) CreateModel( ctx context.Context, args model.GlobalModelCreationArgs, ) (coremodel.UUID, func(context.Context) error, error)
CreateModel is responsible for creating a new model from start to finish with its associated metadata. The function will return the created model's id. If the GlobalModelCreationArgs does not have a credential name set then no cloud credential will be associated with model.
If the caller has not prescribed a specific agent version to use for the model the current controllers supported agent version will be used.
If no secret backend is defined for the created model then one will be determined for the new model.
Models created by this function must be activated using the returned ModelActivator.
The following error types can be expected to be returned: - modelerrors.AlreadyExists: When the model uuid is already in use or a model with the same name and owner already exists. - errors.NotFound: When the cloud, cloud region, or credential do not exist. - github.com/juju/juju/domain/access/errors.NotFound: When the owner of the model can not be found. - modelerrors.AgentVersionNotSupported: When the prescribed agent version cannot be used with this controller. - secretbackenderrors.NotFound When the secret backend for the model cannot be found.
func (*Service) DefaultModelCloudNameAndCredential ¶
func (s *Service) DefaultModelCloudNameAndCredential( ctx context.Context, ) (string, credential.Key, error)
DefaultModelCloudNameAndCredential returns the default cloud name and credential that should be used for newly created models that haven't had either cloud or credential specified. If no default credential is available the zero value of credential.UUID will be returned.
The defaults that are sourced come from the controller's default model. If there is a no controller model a modelerrors.NotFound error will be returned.
func (*Service) DeleteModel ¶
func (s *Service) DeleteModel( ctx context.Context, uuid coremodel.UUID, opts ...model.DeleteModelOption, ) error
DeleteModel is responsible for removing a model from Juju and all of it's associated metadata. - errors.NotValid: When the model uuid is not valid. - modelerrors.ModelNotFound: When the model does not exist.
func (*Service) GetModelUser ¶
func (s *Service) GetModelUser(ctx context.Context, modelUUID coremodel.UUID, name coreuser.Name) (coremodel.ModelUserInfo, error)
GetModelUser will retrieve basic information about the specified model user. If the model cannot be found it will return modelerrors.NotFound. If the user cannot be found it will return modelerrors.UserNotFoundOnModel.
func (*Service) GetModelUsers ¶
func (s *Service) GetModelUsers(ctx context.Context, modelUUID coremodel.UUID) ([]coremodel.ModelUserInfo, error)
GetModelUsers will retrieve basic information about users with permissions on the given model UUID. If the model cannot be found it will return modelerrors.NotFound.
func (*Service) ImportModel ¶
func (s *Service) ImportModel( ctx context.Context, args model.ModelImportArgs, ) (func(context.Context) error, error)
ImportModel is responsible for importing an existing model into this Juju controller. The caller must explicitly specify the agent version that is in use for the imported model.
Models created by this function must be activated using the returned ModelActivator.
The following error types can be expected to be returned: - modelerrors.AlreadyExists: When the model uuid is already in use or a model with the same name and owner already exists. - errors.NotFound: When the cloud, cloud region, or credential do not exist. - github.com/juju/juju/domain/access/errors.NotFound: When the owner of the model can not be found. - modelerrors.AgentVersionNotSupported: When the prescribed agent version cannot be used with this controller or the agent version is set to zero. - secretbackenderrors.NotFound When the secret backend for the model cannot be found.
func (*Service) ListAllModelSummaries ¶
ListAllModelSummaries returns a slice of model summaries for all models known to the controller.
func (*Service) ListAllModels ¶
ListAllModels lists all models in the controller. If no models exist then an empty slice is returned.
func (*Service) ListModelIDs ¶
ListModelIDs returns a list of all model UUIDs in the system that have not been deleted. This list does not represent one or more lifecycle states for models.
func (*Service) ListModelSummariesForUser ¶
func (s *Service) ListModelSummariesForUser(ctx context.Context, userName coreuser.Name) ([]coremodel.UserModelSummary, error)
ListModelSummariesForUser returns a slice of model summaries for a given user. If no models are found an empty slice is returned.
func (*Service) ListModelsForUser ¶
func (s *Service) ListModelsForUser(ctx context.Context, userID coreuser.UUID) ([]coremodel.Model, error)
ListModelsForUser lists the models that are either owned by the user or accessible by the user specified by the user id. If no user or models exists an empty slice of models will be returned.
func (*Service) Model ¶
Model returns the model associated with the provided uuid. The following error types can be expected to be returned: - modelerrors.ModelNotFound: When the model does not exist.
func (*Service) ModelType ¶
ModelType returns the current model type based on the cloud name being used for the model.
func (*Service) UpdateCredential ¶
func (s *Service) UpdateCredential( ctx context.Context, uuid coremodel.UUID, key credential.Key, ) error
UpdateCredential is responsible for updating the cloud credential associated with a model. The cloud credential must be of the same cloud type as that of the model. The following error types can be expected to be returned: - modelerrors.ModelNotFound: When the model does not exist. - errors.NotFound: When the cloud or credential cannot be found. - errors.NotValid: When the cloud credential is not of the same cloud as the model or the model uuid is not valid.
type State ¶
type State interface { ModelTypeState // Create creates a new model with all of its associated metadata. Create(context.Context, coremodel.UUID, coremodel.ModelType, model.GlobalModelCreationArgs) error // Activate is responsible for setting a model as fully constructed and // indicates the final system state for the model is ready for use. // 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. Activate(ctx context.Context, uuid coremodel.UUID) error // GetModel returns the model associated with the provided uuid. GetModel(context.Context, coremodel.UUID) (coremodel.Model, error) // GetModelByName returns the model associated with the given user and name. // If no model exists for the provided user or model name then an error of // [modelerrors.NotFound] will be returned. GetModelByName(context.Context, coreuser.Name, string) (coremodel.Model, error) // GetModelType returns the model type for a model with the provided uuid. GetModelType(context.Context, coremodel.UUID) (coremodel.ModelType, error) // GetControllerModel returns the model the controller is running in. GetControllerModel(ctx context.Context) (coremodel.Model, error) // Delete removes a model and all of it's associated data from Juju. Delete(context.Context, coremodel.UUID) error // ListAllModels returns all models registered in the controller. If no // models exist a zero value slice will be returned. ListAllModels(context.Context) ([]coremodel.Model, error) // ListModelIDs returns a list of all model UUIDs. ListModelIDs(context.Context) ([]coremodel.UUID, error) // ListModelsForUser returns a slice of models owned by the user // specified by user id. If no user or models are found an empty slice is // returned. ListModelsForUser(context.Context, coreuser.UUID) ([]coremodel.Model, 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. GetModelUsers(ctx context.Context, modelUUID coremodel.UUID) ([]coremodel.ModelUserInfo, error) // ListModelSummariesForUser returns a slice of model summaries for a given // user. If no models are found an empty slice is returned. ListModelSummariesForUser(ctx context.Context, userName coreuser.Name) ([]coremodel.UserModelSummary, error) // ListAllModelSummaries returns a slice of model summaries for all models // known to the controller. ListAllModelSummaries(ctx context.Context) ([]coremodel.ModelSummary, error) // ModelCloudNameAndCredential returns the cloud name and credential id for a // model identified by the model name and the owner. If no model exists for // the provided name and user a [modelerrors.NotFound] error is returned. ModelCloudNameAndCredential(context.Context, string, coreuser.Name) (string, credential.Key, error) // UpdateCredential updates a model's cloud credential. UpdateCredential(context.Context, coremodel.UUID, credential.Key) error }
State is the model state required by this service.