github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/jujuclient/interface.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package jujuclient
     5  
     6  import (
     7  	"github.com/juju/juju/cloud"
     8  	"github.com/juju/juju/controller"
     9  )
    10  
    11  // ControllerDetails holds the details needed to connect to a controller.
    12  type ControllerDetails struct {
    13  	// UnresolvedAPIEndpoints holds a list of API addresses which may
    14  	// contain unresolved hostnames. It's used to compare more recent
    15  	// API addresses before resolving hostnames to determine if the
    16  	// cached addresses have changed and therefore perform (a possibly
    17  	// slow) local DNS resolution before comparing them against Addresses.
    18  	UnresolvedAPIEndpoints []string `yaml:"unresolved-api-endpoints,flow"`
    19  
    20  	// ControllerUUID is the unique ID for the controller.
    21  	ControllerUUID string `yaml:"uuid"`
    22  
    23  	// APIEndpoints holds a list of API addresses. It may not be
    24  	// current, and it will be empty if the environment has not been
    25  	// bootstrapped.
    26  	APIEndpoints []string `yaml:"api-endpoints,flow"`
    27  
    28  	// CACert is a security certificate for this controller.
    29  	CACert string `yaml:"ca-cert"`
    30  
    31  	// Cloud is the name of the cloud that this controller runs in.
    32  	Cloud string `yaml:"cloud"`
    33  
    34  	// CloudRegion is the name of the cloud region that this controller
    35  	// runs in. This will be empty for clouds without regions.
    36  	CloudRegion string `yaml:"region,omitempty"`
    37  
    38  	// AgentVersion is the version of the agent running on this controller.
    39  	// While this isn't strictly needed to connect to a controller, it is used
    40  	// in formatting show-controller output where this struct is also used.
    41  	AgentVersion string `yaml:"agent-version,omitempty"`
    42  
    43  	// ControllerMachineCount represents the number of controller machines
    44  	// It is cached here so under normal usage list-controllers
    45  	// does not need to hit the server.
    46  	ControllerMachineCount int `yaml:"controller-machine-count"`
    47  
    48  	// ActiveControllerMachineCount represents the number of controller machines
    49  	// and which are active in the HA cluster.
    50  	// It is cached here so under normal usage list-controllers
    51  	// does not need to hit the server.
    52  	ActiveControllerMachineCount int `yaml:"active-controller-machine-count"`
    53  
    54  	// ModelCount is the number of models to which a user has access.
    55  	// It is cached here so under normal usage list-controllers
    56  	// does not need to hit the server.
    57  	ModelCount *int `yaml:"model-count,omitempty"`
    58  
    59  	// MachineCount is the number of machines in all models to
    60  	// which a user has access. It is cached here so under normal
    61  	// usage list-controllers does not need to hit the server.
    62  	MachineCount *int `yaml:"machine-count,omitempty"`
    63  }
    64  
    65  // ModelDetails holds details of a model.
    66  type ModelDetails struct {
    67  	// ModelUUID is the unique ID for the model.
    68  	ModelUUID string `yaml:"uuid"`
    69  }
    70  
    71  // AccountDetails holds details of an account.
    72  type AccountDetails struct {
    73  	// User is the username for the account.
    74  	User string `yaml:"user"`
    75  
    76  	// Password is the password for the account.
    77  	Password string `yaml:"password,omitempty"`
    78  
    79  	// LastKnownAccess is the last known access level for the account.
    80  	LastKnownAccess string `yaml:"last-known-access,omitempty"`
    81  }
    82  
    83  // BootstrapConfig holds the configuration used to bootstrap a controller.
    84  //
    85  // This includes all non-sensitive information required to regenerate the
    86  // bootstrap configuration. A reference to the credential used will be
    87  // stored, rather than the credential itself.
    88  type BootstrapConfig struct {
    89  	// ControllerConfig is the controller configuration.
    90  	ControllerConfig controller.Config `yaml:"controller-config"`
    91  
    92  	// Config is the complete configuration for the provider.
    93  	Config map[string]interface{} `yaml:"model-config"`
    94  
    95  	// ControllerModelUUID is the controller model UUID.
    96  	ControllerModelUUID string `yaml:"controller-model-uuid"`
    97  
    98  	// Credential is the name of the credential used to bootstrap.
    99  	//
   100  	// This will be empty if an auto-detected credential was used.
   101  	Credential string `yaml:"credential,omitempty"`
   102  
   103  	// Cloud is the name of the cloud to create the Juju controller in.
   104  	Cloud string `yaml:"cloud"`
   105  
   106  	// CloudType is the type of the cloud to create the Juju controller in.
   107  	CloudType string `yaml:"type"`
   108  
   109  	// CloudRegion is the name of the region of the cloud to create
   110  	// the Juju controller in. This will be empty for clouds without
   111  	// regions.
   112  	CloudRegion string `yaml:"region,omitempty"`
   113  
   114  	// CloudEndpoint is the location of the primary API endpoint to
   115  	// use when communicating with the cloud.
   116  	CloudEndpoint string `yaml:"endpoint,omitempty"`
   117  
   118  	// CloudIdentityEndpoint is the location of the API endpoint to use
   119  	// when communicating with the cloud's identity service. This will
   120  	// be empty for clouds that have no identity-specific API endpoint.
   121  	CloudIdentityEndpoint string `yaml:"identity-endpoint,omitempty"`
   122  
   123  	// CloudStorageEndpoint is the location of the API endpoint to use
   124  	// when communicating with the cloud's storage service. This will
   125  	// be empty for clouds that have no storage-specific API endpoint.
   126  	CloudStorageEndpoint string `yaml:"storage-endpoint,omitempty"`
   127  }
   128  
   129  // ControllerUpdater stores controller details.
   130  type ControllerUpdater interface {
   131  	// AddController adds the given controller to the controller
   132  	// collection.
   133  	//
   134  	// Where UpdateController is concerned with the controller name,
   135  	// AddController uses the controller UUID and will not add a
   136  	// duplicate even if the name is different.
   137  	AddController(controllerName string, details ControllerDetails) error
   138  
   139  	// UpdateController updates the given controller in the controller
   140  	// collection.
   141  	//
   142  	// If a controller of controllerName exists it will be overwritten
   143  	// with the new details.
   144  	UpdateController(controllerName string, details ControllerDetails) error
   145  
   146  	// SetCurrentController sets the name of the current controller.
   147  	// If there exists no controller with the specified name, an error
   148  	// satisfying errors.IsNotFound will be returned.
   149  	SetCurrentController(controllerName string) error
   150  }
   151  
   152  // ControllerRemover removes controllers.
   153  type ControllerRemover interface {
   154  	// RemoveController removes the controller with the given name from the
   155  	// controllers collection. Any other controllers with matching UUIDs
   156  	// will also be removed.
   157  	//
   158  	// Removing controllers will remove all information related to those
   159  	// controllers (models, accounts, bootstrap config.)
   160  	RemoveController(controllerName string) error
   161  }
   162  
   163  // ControllerGetter gets controllers.
   164  type ControllerGetter interface {
   165  	// AllControllers gets all controllers.
   166  	AllControllers() (map[string]ControllerDetails, error)
   167  
   168  	// ControllerByName returns the controller with the specified name.
   169  	// If there exists no controller with the specified name, an error
   170  	// satisfying errors.IsNotFound will be returned.
   171  	ControllerByName(controllerName string) (*ControllerDetails, error)
   172  
   173  	// CurrentController returns the name of the current controller.
   174  	// If there is no current controller, an error satisfying
   175  	// errors.IsNotFound will be returned.
   176  	CurrentController() (string, error)
   177  }
   178  
   179  // ModelUpdater stores model details.
   180  type ModelUpdater interface {
   181  	// UpdateModel adds the given model to the model collection.
   182  	//
   183  	// If the model does not already exist, it will be added.
   184  	// Otherwise, it will be overwritten with the new details.
   185  	UpdateModel(controllerName, modelName string, details ModelDetails) error
   186  
   187  	// SetCurrentModel sets the name of the current model for
   188  	// the specified controller and account. If there exists no
   189  	// model with the specified names, an error satisfying
   190  	// errors.IsNotFound will be returned.
   191  	SetCurrentModel(controllerName, modelName string) error
   192  }
   193  
   194  // ModelRemover removes models.
   195  type ModelRemover interface {
   196  	// RemoveModel removes the model with the given controller, account,
   197  	// and model names from the models collection. If there is no model
   198  	// with the specified names, an errors satisfying errors.IsNotFound
   199  	// will be returned.
   200  	RemoveModel(controllerName, modelName string) error
   201  }
   202  
   203  // ModelGetter gets models.
   204  type ModelGetter interface {
   205  	// AllModels gets all models for the specified controller as a map
   206  	// from model name to its details.
   207  	//
   208  	// If there is no controller with the specified
   209  	// name, or no models cached for the controller and account,
   210  	// an error satisfying errors.IsNotFound will be returned.
   211  	AllModels(controllerName string) (map[string]ModelDetails, error)
   212  
   213  	// CurrentModel returns the name of the current model for
   214  	// the specified controller. If there is no current
   215  	// model for the controller, an error satisfying
   216  	// errors.IsNotFound is returned.
   217  	CurrentModel(controllerName string) (string, error)
   218  
   219  	// ModelByName returns the model with the specified controller,
   220  	// and model name. If a model with the specified name does not
   221  	// exist, an error satisfying errors.IsNotFound will be
   222  	// returned.
   223  	ModelByName(controllerName, modelName string) (*ModelDetails, error)
   224  }
   225  
   226  // AccountUpdater stores account details.
   227  type AccountUpdater interface {
   228  	// UpdateAccount updates the account associated with the
   229  	// given controller.
   230  	UpdateAccount(controllerName string, details AccountDetails) error
   231  }
   232  
   233  // AccountRemover removes accounts.
   234  type AccountRemover interface {
   235  	// RemoveAccount removes the account associated with the given controller.
   236  	// If there is no associated account with the
   237  	// specified names, an errors satisfying errors.IsNotFound will be
   238  	// returned.
   239  	RemoveAccount(controllerName string) error
   240  }
   241  
   242  // AccountGetter gets accounts.
   243  type AccountGetter interface {
   244  	// AccountByName returns the account associated with the given
   245  	// controller name. If no associated account exists, an error
   246  	// satisfying errors.IsNotFound will be returned.
   247  	AccountDetails(controllerName string) (*AccountDetails, error)
   248  }
   249  
   250  // CredentialGetter gets credentials.
   251  type CredentialGetter interface {
   252  	// CredentialForCloud gets credentials for the named cloud.
   253  	CredentialForCloud(string) (*cloud.CloudCredential, error)
   254  
   255  	// AllCredentials gets all credentials.
   256  	AllCredentials() (map[string]cloud.CloudCredential, error)
   257  }
   258  
   259  // CredentialUpdater stores credentials.
   260  type CredentialUpdater interface {
   261  	// UpdateCredential adds the given credentials to the credentials
   262  	// collection.
   263  	//
   264  	// If the cloud or credential name does not already exist, it will be added.
   265  	// Otherwise, it will be overwritten with the new details.
   266  	UpdateCredential(cloudName string, details cloud.CloudCredential) error
   267  }
   268  
   269  // BootstrapConfigUpdater stores bootstrap config.
   270  type BootstrapConfigUpdater interface {
   271  	// UpdateBootstrapConfig adds the given bootstrap config to the
   272  	// bootstrap config collection for the controller with the given
   273  	// name.
   274  	//
   275  	// If the bootstrap config does not already exist, it will be added.
   276  	// Otherwise, it will be overwritten with the new value.
   277  	UpdateBootstrapConfig(controller string, cfg BootstrapConfig) error
   278  }
   279  
   280  // BootstrapConfigGetter gets bootstrap config.
   281  type BootstrapConfigGetter interface {
   282  	// BootstrapConfigForController gets bootstrap config for the named
   283  	// controller.
   284  	BootstrapConfigForController(string) (*BootstrapConfig, error)
   285  }
   286  
   287  // ControllerStore is an amalgamation of ControllerUpdater, ControllerRemover,
   288  // and ControllerGetter.
   289  type ControllerStore interface {
   290  	ControllerUpdater
   291  	ControllerRemover
   292  	ControllerGetter
   293  }
   294  
   295  // ModelStore is an amalgamation of ModelUpdater, ModelRemover, and ModelGetter.
   296  type ModelStore interface {
   297  	ModelUpdater
   298  	ModelRemover
   299  	ModelGetter
   300  }
   301  
   302  // AccountStore is an amalgamation of AccountUpdater, AccountRemover, and AccountGetter.
   303  type AccountStore interface {
   304  	AccountUpdater
   305  	AccountRemover
   306  	AccountGetter
   307  }
   308  
   309  // CredentialStore is an amalgamation of CredentialsUpdater, and CredentialsGetter.
   310  type CredentialStore interface {
   311  	CredentialGetter
   312  	CredentialUpdater
   313  }
   314  
   315  // BootstrapConfigStore is an amalgamation of BootstrapConfigUpdater and
   316  // BootstrapConfigGetter.
   317  type BootstrapConfigStore interface {
   318  	BootstrapConfigUpdater
   319  	BootstrapConfigGetter
   320  }
   321  
   322  // ClientStore is an amalgamation of AccountStore, BootstrapConfigStore,
   323  // ControllerStore, CredentialStore, and ModelStore.
   324  type ClientStore interface {
   325  	AccountStore
   326  	BootstrapConfigStore
   327  	ControllerStore
   328  	CredentialStore
   329  	ModelStore
   330  }