github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/params/model.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package params
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/juju/version"
    10  )
    11  
    12  // ConfigValue encapsulates a configuration
    13  // value and its source.
    14  type ConfigValue struct {
    15  	Value  interface{} `json:"value"`
    16  	Source string      `json:"source"`
    17  }
    18  
    19  // ModelConfigResults contains the result of client API calls
    20  // to get model config values.
    21  type ModelConfigResults struct {
    22  	Config map[string]ConfigValue `json:"config"`
    23  }
    24  
    25  // HostedModelConfig contains the model config and the cloud spec
    26  // for the model, both things that a client needs to talk directly
    27  // with the provider. This is used to take down mis-behaving models
    28  // aggressively.
    29  type HostedModelConfig struct {
    30  	Name      string                 `json:"name"`
    31  	OwnerTag  string                 `json:"owner"`
    32  	Config    map[string]interface{} `json:"config,omitempty"`
    33  	CloudSpec *CloudSpec             `json:"cloud-spec,omitempty"`
    34  	Error     *Error                 `json:"error,omitempty"`
    35  }
    36  
    37  // HostedModelConfigsResults contains an entry for each hosted model
    38  // in the controller.
    39  type HostedModelConfigsResults struct {
    40  	Models []HostedModelConfig `json:"models"`
    41  }
    42  
    43  // ModelDefaultsResult contains the result of client API calls to get the
    44  // model default values.
    45  type ModelDefaultsResult struct {
    46  	Config map[string]ModelDefaults `json:"config"`
    47  }
    48  
    49  // ModelSequencesResult holds the map of sequence names to next value.
    50  type ModelSequencesResult struct {
    51  	Sequences map[string]int `json:"sequences"`
    52  }
    53  
    54  // ModelDefaults holds the settings for a given ModelDefaultsResult config
    55  // attribute.
    56  type ModelDefaults struct {
    57  	Default    interface{}      `json:"default,omitempty"`
    58  	Controller interface{}      `json:"controller,omitempty"`
    59  	Regions    []RegionDefaults `json:"regions,omitempty"`
    60  }
    61  
    62  // RegionDefaults contains the settings for regions in a ModelDefaults.
    63  type RegionDefaults struct {
    64  	RegionName string      `json:"region-name"`
    65  	Value      interface{} `json:"value"`
    66  }
    67  
    68  // ModelSet contains the arguments for ModelSet client API
    69  // call.
    70  type ModelSet struct {
    71  	Config map[string]interface{} `json:"config"`
    72  }
    73  
    74  // ModelUnset contains the arguments for ModelUnset client API
    75  // call.
    76  type ModelUnset struct {
    77  	Keys []string `json:"keys"`
    78  }
    79  
    80  // ModelSLA contains the arguments for the SetSLALevel client API
    81  // call.
    82  type ModelSLA struct {
    83  	ModelSLAInfo
    84  	Credentials []byte `json:"creds"`
    85  }
    86  
    87  // SetModelDefaults contains the arguments for SetModelDefaults
    88  // client API call.
    89  type SetModelDefaults struct {
    90  	Config []ModelDefaultValues `json:"config"`
    91  }
    92  
    93  // ModelDefaultValues contains the default model values for
    94  // a cloud/region.
    95  type ModelDefaultValues struct {
    96  	CloudTag    string                 `json:"cloud-tag,omitempty"`
    97  	CloudRegion string                 `json:"cloud-region,omitempty"`
    98  	Config      map[string]interface{} `json:"config"`
    99  }
   100  
   101  // ModelUnsetKeys contains the config keys to unset for
   102  // a cloud/region.
   103  type ModelUnsetKeys struct {
   104  	CloudTag    string   `json:"cloud-tag,omitempty"`
   105  	CloudRegion string   `json:"cloud-region,omitempty"`
   106  	Keys        []string `json:"keys"`
   107  }
   108  
   109  // UnsetModelDefaults contains the arguments for UnsetModelDefaults
   110  // client API call.
   111  type UnsetModelDefaults struct {
   112  	Keys []ModelUnsetKeys `json:"keys"`
   113  }
   114  
   115  // SetModelAgentVersion contains the arguments for
   116  // SetModelAgentVersion client API call.
   117  type SetModelAgentVersion struct {
   118  	Version             version.Number `json:"version"`
   119  	IgnoreAgentVersions bool           `json:"force,omitempty"`
   120  }
   121  
   122  // ModelMigrationStatus holds information about the progress of a (possibly
   123  // failed) migration.
   124  type ModelMigrationStatus struct {
   125  	Status string     `json:"status"`
   126  	Start  *time.Time `json:"start"`
   127  	End    *time.Time `json:"end,omitempty"`
   128  }
   129  
   130  // ModelInfo holds information about the Juju model.
   131  type ModelInfo struct {
   132  	Name               string `json:"name"`
   133  	Type               string `json:"type"`
   134  	UUID               string `json:"uuid"`
   135  	ControllerUUID     string `json:"controller-uuid"`
   136  	IsController       bool   `json:"is-controller"`
   137  	ProviderType       string `json:"provider-type,omitempty"`
   138  	DefaultSeries      string `json:"default-series,omitempty"`
   139  	CloudTag           string `json:"cloud-tag"`
   140  	CloudRegion        string `json:"cloud-region,omitempty"`
   141  	CloudCredentialTag string `json:"cloud-credential-tag,omitempty"`
   142  
   143  	// OwnerTag is the tag of the user that owns the model.
   144  	OwnerTag string `json:"owner-tag"`
   145  
   146  	// Life is the current lifecycle state of the model.
   147  	Life Life `json:"life"`
   148  
   149  	// Status is the current status of the model.
   150  	Status EntityStatus `json:"status,omitempty"`
   151  
   152  	// Users contains information about the users that have access
   153  	// to the model. Owners and administrators can see all users
   154  	// that have access; other users can only see their own details.
   155  	Users []ModelUserInfo `json:"users"`
   156  
   157  	// Machines contains information about the machines in the model.
   158  	// This information is available to owners and users with write
   159  	// access or greater.
   160  	Machines []ModelMachineInfo `json:"machines"`
   161  
   162  	// Migration contains information about the latest failed or
   163  	// currently-running migration. It'll be nil if there isn't one.
   164  	Migration *ModelMigrationStatus `json:"migration,omitempty"`
   165  
   166  	// SLA contains the information about the SLA for the model, if set.
   167  	SLA *ModelSLAInfo `json:"sla"`
   168  
   169  	// AgentVersion is the agent version for this model.
   170  	AgentVersion *version.Number `json:"agent-version"`
   171  }
   172  
   173  // ModelSummary holds summary about a Juju model.
   174  type ModelSummary struct {
   175  	Name               string `json:"name"`
   176  	UUID               string `json:"uuid"`
   177  	Type               string `json:"type"`
   178  	ControllerUUID     string `json:"controller-uuid"`
   179  	IsController       bool   `json:"is-controller"`
   180  	ProviderType       string `json:"provider-type,omitempty"`
   181  	DefaultSeries      string `json:"default-series,omitempty"`
   182  	CloudTag           string `json:"cloud-tag"`
   183  	CloudRegion        string `json:"cloud-region,omitempty"`
   184  	CloudCredentialTag string `json:"cloud-credential-tag,omitempty"`
   185  
   186  	// OwnerTag is the tag of the user that owns the model.
   187  	OwnerTag string `json:"owner-tag"`
   188  
   189  	// Life is the current lifecycle state of the model.
   190  	Life Life `json:"life"`
   191  
   192  	// Status is the current status of the model.
   193  	Status EntityStatus `json:"status,omitempty"`
   194  
   195  	// UserAccess is model access level for the  current user.
   196  	UserAccess UserAccessPermission `json:"user-access"`
   197  
   198  	// UserLastConnection contains the time when current user logged in
   199  	// into the model last.
   200  	UserLastConnection *time.Time `json:"last-connection"`
   201  
   202  	// Counts contains counts of interesting entities
   203  	// in the model, for example machines, cores, containers, units, etc.
   204  	Counts []ModelEntityCount `json:"counts"`
   205  
   206  	// Migration contains information about the latest failed or
   207  	// currently-running migration. It'll be nil if there isn't one.
   208  	Migration *ModelMigrationStatus `json:"migration,omitempty"`
   209  
   210  	// SLA contains the information about the SLA for the model, if set.
   211  	SLA *ModelSLAInfo `json:"sla"`
   212  
   213  	// AgentVersion is the agent version for this model.
   214  	AgentVersion *version.Number `json:"agent-version"`
   215  }
   216  
   217  // ModelEntityCount represent a count for a model entity where entities could be
   218  // machines, units, etc...
   219  type ModelEntityCount struct {
   220  	Entity CountedEntity `json:"entity"`
   221  	Count  int64         `json:"count"`
   222  }
   223  
   224  // CountedEntity identifies an entity that has a count.
   225  type CountedEntity string
   226  
   227  const (
   228  	Machines CountedEntity = "machines"
   229  	Cores    CountedEntity = "cores"
   230  )
   231  
   232  // ModelSLAInfo describes the SLA info for a model.
   233  type ModelSLAInfo struct {
   234  	Level string `json:"level"`
   235  	Owner string `json:"owner"`
   236  }
   237  
   238  // ModelSummaryResult holds the result of a ListModelsWithInfo call.
   239  type ModelSummaryResult struct {
   240  	Result *ModelSummary `json:"result,omitempty"`
   241  	Error  *Error        `json:"error,omitempty"`
   242  }
   243  
   244  // ModelSummaryResults holds the result of a bulk ListModelsWithInfo call.
   245  type ModelSummaryResults struct {
   246  	Results []ModelSummaryResult `json:"results"`
   247  }
   248  
   249  // ModelSummariesRequest encapsulates how we request a list of model summaries.
   250  type ModelSummariesRequest struct {
   251  	UserTag string `json:"user-tag"`
   252  	All     bool   `json:"all,omitempty"`
   253  }
   254  
   255  // ModelInfoResult holds the result of a ModelInfo call.
   256  type ModelInfoResult struct {
   257  	Result *ModelInfo `json:"result,omitempty"`
   258  	Error  *Error     `json:"error,omitempty"`
   259  }
   260  
   261  // ModelInfoResults holds the result of a bulk ModelInfo call.
   262  type ModelInfoResults struct {
   263  	Results []ModelInfoResult `json:"results"`
   264  }
   265  
   266  // ModelInfoList holds a list of ModelInfo structures.
   267  type ModelInfoList struct {
   268  	Models []ModelInfo `json:"models,omitempty"`
   269  }
   270  
   271  // ModelInfoListResult holds the result of a call that returns a list
   272  // of ModelInfo structures.
   273  type ModelInfoListResult struct {
   274  	Result *ModelInfoList `json:"result,omitempty"`
   275  	Error  *Error         `json:"error,omitempty"`
   276  }
   277  
   278  // ModelInfoListResults holds the result of a bulk call that returns
   279  // multiple lists of ModelInfo structures.
   280  type ModelInfoListResults struct {
   281  	Results []ModelInfoListResult `json:"results"`
   282  }
   283  
   284  // ModelMachineInfo holds information about a machine in a model.
   285  type ModelMachineInfo struct {
   286  	Id          string           `json:"id"`
   287  	Hardware    *MachineHardware `json:"hardware,omitempty"`
   288  	InstanceId  string           `json:"instance-id,omitempty"`
   289  	DisplayName string           `json:"display-name,omitempty"`
   290  	Status      string           `json:"status,omitempty"`
   291  	Message     string           `json:"message,omitempty"`
   292  	HasVote     bool             `json:"has-vote,omitempty"`
   293  	WantsVote   bool             `json:"wants-vote,omitempty"`
   294  }
   295  
   296  // MachineHardware holds information about a machine's hardware characteristics.
   297  type MachineHardware struct {
   298  	Arch             *string   `json:"arch,omitempty"`
   299  	Mem              *uint64   `json:"mem,omitempty"`
   300  	RootDisk         *uint64   `json:"root-disk,omitempty"`
   301  	Cores            *uint64   `json:"cores,omitempty"`
   302  	CpuPower         *uint64   `json:"cpu-power,omitempty"`
   303  	Tags             *[]string `json:"tags,omitempty"`
   304  	AvailabilityZone *string   `json:"availability-zone,omitempty"`
   305  }
   306  
   307  // ModelVolumeInfo holds information about a volume in a model.
   308  type ModelVolumeInfo struct {
   309  	Id         string `json:"id"`
   310  	ProviderId string `json:"provider-id,omitempty"`
   311  	Status     string `json:"status,omitempty"`
   312  	Message    string `json:"message,omitempty"`
   313  	Detachable bool   `json:"detachable,omitempty"`
   314  }
   315  
   316  // ModelFilesystemInfo holds information about a filesystem in a model.
   317  type ModelFilesystemInfo struct {
   318  	Id         string `json:"id"`
   319  	ProviderId string `json:"provider-id,omitempty"`
   320  	Status     string `json:"status,omitempty"`
   321  	Message    string `json:"message,omitempty"`
   322  	Detachable bool   `json:"detachable,omitempty"`
   323  }
   324  
   325  // ModelUserInfo holds information on a user who has access to a
   326  // model. Owners of a model can see this information for all users
   327  // who have access, so it should not include sensitive information.
   328  type ModelUserInfo struct {
   329  	UserName       string               `json:"user"`
   330  	DisplayName    string               `json:"display-name"`
   331  	LastConnection *time.Time           `json:"last-connection"`
   332  	Access         UserAccessPermission `json:"access"`
   333  }
   334  
   335  // ModelUserInfoResult holds the result of an ModelUserInfo call.
   336  type ModelUserInfoResult struct {
   337  	Result *ModelUserInfo `json:"result,omitempty"`
   338  	Error  *Error         `json:"error,omitempty"`
   339  }
   340  
   341  // ModelUserInfoResults holds the result of a bulk ModelUserInfo API call.
   342  type ModelUserInfoResults struct {
   343  	Results []ModelUserInfoResult `json:"results"`
   344  }
   345  
   346  // ModifyModelAccessRequest holds the parameters for making grant and revoke model calls.
   347  type ModifyModelAccessRequest struct {
   348  	Changes []ModifyModelAccess `json:"changes"`
   349  }
   350  
   351  type ModifyModelAccess struct {
   352  	UserTag  string               `json:"user-tag"`
   353  	Action   ModelAction          `json:"action"`
   354  	Access   UserAccessPermission `json:"access"`
   355  	ModelTag string               `json:"model-tag"`
   356  }
   357  
   358  // ModelAction is an action that can be performed on a model.
   359  type ModelAction string
   360  
   361  // Actions that can be preformed on a model.
   362  const (
   363  	GrantModelAccess  ModelAction = "grant"
   364  	RevokeModelAccess ModelAction = "revoke"
   365  )
   366  
   367  // UserAccessPermission is the type of permission that a user has to access a
   368  // model.
   369  type UserAccessPermission string
   370  
   371  // Model access permissions that may be set on a user.
   372  const (
   373  	ModelAdminAccess UserAccessPermission = "admin"
   374  	ModelReadAccess  UserAccessPermission = "read"
   375  	ModelWriteAccess UserAccessPermission = "write"
   376  )
   377  
   378  // DestroyModelsParams holds the arguments for destroying models.
   379  type DestroyModelsParams struct {
   380  	Models []DestroyModelParams `json:"models"`
   381  }
   382  
   383  // DestroyModelParams holds the arguments for destroying a model.
   384  type DestroyModelParams struct {
   385  	// ModelTag is the tag of the model to destroy.
   386  	ModelTag string `json:"model-tag"`
   387  
   388  	// DestroyStorage controls whether or not storage in the model.
   389  	//
   390  	// This is ternary: nil, false, or true. If nil and there is persistent
   391  	// storage in the model, an error with the code
   392  	// params.CodeHasPersistentStorage will be returned.
   393  	DestroyStorage *bool `json:"destroy-storage,omitempty"`
   394  }
   395  
   396  // ModelCredential stores information about cloud credential that a model uses:
   397  // what credential is being used, is it valid for this model, etc.
   398  type ModelCredential struct {
   399  	// Model is a tag for the model.
   400  	Model string `json:"model-tag"`
   401  
   402  	// Exists indicates whether credential was set on the model.
   403  	// It is valid for model not to have a credential if it is on the
   404  	// cloud that does not require auth.
   405  	Exists bool `json:"exists,omitempty"`
   406  
   407  	// CloudCredential is the tag for the cloud credential that the model uses.
   408  	CloudCredential string `json:"credential-tag"`
   409  
   410  	// Valid stores whether this credential is valid, for example, not expired,
   411  	// and whether this credential works for this model, i.e. all model
   412  	// machines can be accessed with this credential.
   413  	Valid bool `json:"valid,omitempty"`
   414  }
   415  
   416  // ChangeModelCredentialParams holds the argument to replace cloud credential
   417  // used by a model.
   418  type ChangeModelCredentialParams struct {
   419  	// ModelTag is a tag for the model where cloud credential change takes place.
   420  	ModelTag string `json:"model-tag"`
   421  
   422  	// CloudCredentialTag is the tag for the new cloud credential.
   423  	CloudCredentialTag string `json:"credential-tag"`
   424  }
   425  
   426  // ChangeModelCredentialsParams holds the arguments for changing
   427  // cloud credentials on models.
   428  type ChangeModelCredentialsParams struct {
   429  	Models []ChangeModelCredentialParams `json:"model-credentials"`
   430  }