modelcmd

package
v0.0.0-...-8ff1004 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoControllersDefined is returned by commands that operate on
	// a controller if there is no current controller, no controller has been
	// explicitly specified, and there is no default controller.
	ErrNoControllersDefined = errors.New(`No controllers registered.

Please either create a new controller using "juju bootstrap" or connect to
another controller that you have been given access to using "juju register".
`)
	// ErrNoCurrentController is returned by commands that operate on
	// a controller if there is no current controller, no controller has been
	// explicitly specified, and there is no default controller but there are
	// controllers that client knows about.
	ErrNoCurrentController = errors.New(`No selected controller.

Please use "juju switch" to select a controller.
`)
)
View Source
var (
	// ErrMultipleCredentials is the error returned by DetectCredential
	// if more than one credential is detected.
	ErrMultipleCredentials = errors.New("more than one credential detected")
)
View Source
var ErrNoModelSpecified = errors.New(`No model in focus.

Please use "juju models" to see models available to you.
You can set current model by running "juju switch"
or specify any other model on the command line using the "-m" option.
`)

ErrNoModelSpecified is returned by commands that operate on an environment if there is no current model, no model has been explicitly specified, and there is no default model.

Functions

func AnnotateWithFinalizationError

func AnnotateWithFinalizationError(err error, credentialName, cloudName string) error

func BootstrapContext

func BootstrapContext(cmdContext *cmd.Context) environs.BootstrapContext

BootstrapContext returns a new BootstrapContext constructed from a command Context.

func BootstrapContextNoVerify

func BootstrapContextNoVerify(cmdContext *cmd.Context) environs.BootstrapContext

BootstrapContextNoVerify returns a new BootstrapContext constructed from a command Context where the validation of credentials is false.

func DetectCredential

func DetectCredential(cloudName string, provider environs.EnvironProvider) (*cloud.CloudCredential, error)

DetectCredential detects credentials for the specified cloud type, and, if exactly one is detected, returns it.

If no credentials are detected, an error satisfying errors.IsNotFound will be returned. If more than one credential is detected, ErrMultipleCredentials will be returned.

func FinalizeFileContent

func FinalizeFileContent(credential *cloud.Credential, provider environs.EnvironProvider) (*cloud.Credential, error)

FinalizeFileContent replaces the path content of cloud credentials "file" attribute with its content.

func GetCredentials

func GetCredentials(
	ctx *cmd.Context,
	store jujuclient.CredentialGetter,
	args GetCredentialsParams,
) (_ *cloud.Credential, chosenCredentialName, regionName string, _ error)

GetCredentials returns a curated set of credential values for a given cloud. The credential key values are read from the credentials store and the provider finalises the values to resolve things like json files. If region is not specified, the default credential region is used.

func InnerCommand

func InnerCommand(c cmd.Command) cmd.Command

InnerCommand returns the command that has been wrapped by one of the Wrap functions. This is useful for tests that wish to inspect internal details of a command instance. If c isn't wrapping anything, it returns c.

func JoinModelName

func JoinModelName(controller, model string) string

JoinModelName joins a controller and model name into a qualified model name.

func NewGetBootstrapConfigParamsFunc

func NewGetBootstrapConfigParamsFunc(
	ctx *cmd.Context,
	store jujuclient.ClientStore,
	providerRegistry environs.ProviderRegistry,
) func(string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error)

NewGetBootstrapConfigParamsFunc returns a function that, given a controller name, returns the params needed to bootstrap a fresh copy of that controller in the given client store.

func RegisterCredentials

func RegisterCredentials(provider environs.EnvironProvider, args RegisterCredentialsParams) (map[string]*cloud.CloudCredential, error)

RegisterCredentials returns any credentials that need to be registered for a provider.

func SplitModelName

func SplitModelName(name string) (controller, model string)

SplitModelName splits a model name into its controller and model parts. If the model is unqualified, then the returned controller string will be empty, and the returned model string will be identical to the input.

Types

type AuthOpts

type AuthOpts struct {
	// NoBrowser specifies that web-browser-based auth should
	// not be used when authenticating.
	NoBrowser bool
}

AuthOpts holds flags relating to authentication.

func (*AuthOpts) SetFlags

func (o *AuthOpts) SetFlags(f *gnuflag.FlagSet)

type CAASOnlyCommand

type CAASOnlyCommand interface {
	// contains filtered or unexported methods
}

CAASOnlyCommand is used as a marker and is embedded by commands which should only run in CAAS models.

type Command

type Command interface {
	cmd.Command

	// SetAPIOpen sets the function used for opening an API connection.
	SetAPIOpen(opener api.OpenFunc)

	// SetModelAPI sets the api used to access model information.
	SetModelAPI(api ModelAPI)
	// contains filtered or unexported methods
}

Command extends cmd.Command with a closeContext method. It is implicitly implemented by any type that embeds CommandBase.

func WrapBase

func WrapBase(c Command) Command

WrapBase wraps the specified Command. This should be used by any command that embeds CommandBase.

type CommandBase

type CommandBase struct {
	cmd.CommandBase

	// CanClearCurrentModel indicates that this command can reset current model in local cache, aka client store.
	CanClearCurrentModel bool
	// contains filtered or unexported fields
}

CommandBase is a convenience type for embedding that need an API connection.

func (*CommandBase) APIOpen

func (c *CommandBase) APIOpen(info *api.Info, opts api.DialOpts) (api.Connection, error)

APIOpen establishes a connection to the API server using the the given api.Info and api.DialOpts, and associating any stored authorization tokens with the given controller name.

func (*CommandBase) BakeryClient

func (c *CommandBase) BakeryClient(store jujuclient.CookieStore, controllerName string) (*httpbakery.Client, error)

BakeryClient returns a macaroon bakery client that uses the same HTTP client returned by HTTPClient.

func (*CommandBase) ClearControllerMacaroons

func (c *CommandBase) ClearControllerMacaroons(store jujuclient.CookieStore, controllerName string) error

ClearControllerMacaroons will remove all macaroons stored for the given controller from the persistent cookie jar. This is called both from 'juju logout' and a failed 'juju register'.

func (*CommandBase) CookieJar

func (c *CommandBase) CookieJar(store jujuclient.CookieStore, controllerName string) (http.CookieJar, error)

CookieJar returns the cookie jar that is used to store auth credentials when connecting to the API.

func (*CommandBase) HTTPClient

func (c *CommandBase) HTTPClient(store jujuclient.ClientStore, controllerName string) (*http.Client, error)

HTTPClient returns an http.Client that contains the loaded persistent cookie jar. Note that this client is not good for connecting to the Juju API itself because it does not have the correct TLS setup - use api.Connection.HTTPClient for that.

func (*CommandBase) ModelUUIDs

func (c *CommandBase) ModelUUIDs(store jujuclient.ClientStore, controllerName string, modelNames []string) ([]string, error)

ModelUUIDs returns the model UUIDs for the given model names.

func (*CommandBase) NewAPIConnectionParams

func (c *CommandBase) NewAPIConnectionParams(
	store jujuclient.ClientStore,
	controllerName, modelName string,
	accountDetails *jujuclient.AccountDetails,
) (juju.NewAPIConnectionParams, error)

NewAPIConnectionParams returns a juju.NewAPIConnectionParams with the given arguments such that a call to juju.NewAPIConnection with the result behaves the same as a call to CommandBase.NewAPIRoot with the same arguments.

func (*CommandBase) NewAPIRoot

func (c *CommandBase) NewAPIRoot(
	store jujuclient.ClientStore,
	controllerName, modelName string,
) (api.Connection, error)

NewAPIRoot returns a new connection to the API server for the given model or controller.

func (*CommandBase) RefreshModels

func (c *CommandBase) RefreshModels(store jujuclient.ClientStore, controllerName string) error

RefreshModels refreshes the local models cache for the current user on the specified controller.

func (*CommandBase) RemoveModelFromClientStore

func (c *CommandBase) RemoveModelFromClientStore(store jujuclient.ClientStore, controllerName, modelName string)

RemoveModelFromClientStore removes given model from client cache, store, for a given controller. If this model has also been cached as current, it will be reset if the requesting command can modify current model. For example, commands such as add/destroy-model, login/register, etc. If the model was cached as currnet but the command is not expected to change current model, this call will still remove model details from the client cache but will keep current model name intact to allow subsequent calls to try to resolve model details on the controller.

func (*CommandBase) SetAPIOpen

func (c *CommandBase) SetAPIOpen(apiOpen api.OpenFunc)

SetAPIOpen sets the function used for opening an API connection.

func (*CommandBase) SetControllerModels

func (c *CommandBase) SetControllerModels(store jujuclient.ClientStore, controllerName string, models []base.UserModel) error

func (*CommandBase) SetFlags

func (c *CommandBase) SetFlags(f *gnuflag.FlagSet)

SetFlags implements cmd.Command.SetFlags.

func (*CommandBase) SetModelAPI

func (c *CommandBase) SetModelAPI(api ModelAPI)

SetModelAPI sets the api used to access model information.

func (*CommandBase) SetModelRefresh

func (c *CommandBase) SetModelRefresh(refresh func(jujuclient.ClientStore, string) error)

SetModelRefresh sets the function used for refreshing models.

type ControllerCommand

type ControllerCommand interface {
	Command

	// SetClientStore is called prior to the wrapped command's Init method
	// with the default controller store. It may also be called to override the
	// default controller store for testing.
	SetClientStore(jujuclient.ClientStore)

	// ClientStore returns the controller store that the command is
	// associated with.
	ClientStore() jujuclient.ClientStore

	// SetControllerName sets the name of the current controller.
	SetControllerName(controllerName string, allowDefault bool) error

	// ControllerName returns the name of the controller
	// that the command should use. It must only be called
	// after Run has been called.
	ControllerName() (string, error)
	// contains filtered or unexported methods
}

ControllerCommand is intended to be a base for all commands that need to operate on controllers as opposed to models.

func WrapController

func WrapController(c ControllerCommand, options ...WrapControllerOption) ControllerCommand

WrapController wraps the specified ControllerCommand, returning a Command that proxies to each of the ControllerCommand methods.

type ControllerCommandBase

type ControllerCommandBase struct {
	CommandBase
	// contains filtered or unexported fields
}

ControllerCommandBase is a convenience type for embedding in commands that wish to implement ControllerCommand.

func (*ControllerCommandBase) BakeryClient

func (c *ControllerCommandBase) BakeryClient() (*httpbakery.Client, error)

func (*ControllerCommandBase) ClientStore

func (c *ControllerCommandBase) ClientStore() jujuclient.ClientStore

ClientStore implements the ControllerCommand interface.

func (*ControllerCommandBase) ControllerName

func (c *ControllerCommandBase) ControllerName() (string, error)

ControllerName implements the ControllerCommand interface.

func (*ControllerCommandBase) CookieJar

func (c *ControllerCommandBase) CookieJar() (http.CookieJar, error)

func (*ControllerCommandBase) CurrentAccountDetails

func (c *ControllerCommandBase) CurrentAccountDetails() (*jujuclient.AccountDetails, error)

CurrentAccountDetails returns details of the account associated with the current controller.

func (*ControllerCommandBase) ModelUUIDs

func (c *ControllerCommandBase) ModelUUIDs(modelNames []string) ([]string, error)

ModelUUIDs returns the model UUIDs for the given model names.

func (*ControllerCommandBase) NewAPIRoot

func (c *ControllerCommandBase) NewAPIRoot() (api.Connection, error)

NewAPIRoot returns a restricted API for the current controller using the current credentials. Only the UserManager and ModelManager may be accessed through this API connection.

func (*ControllerCommandBase) NewControllerAPIClient

func (c *ControllerCommandBase) NewControllerAPIClient() (*controller.Client, error)

NewControllerAPIClient returns an API client for the Controller on the current controller using the current credentials.

func (*ControllerCommandBase) NewModelAPIRoot

func (c *ControllerCommandBase) NewModelAPIRoot(modelName string) (api.Connection, error)

NewAPIRoot returns a new connection to the API server for the named model in the specified controller.

func (*ControllerCommandBase) NewModelManagerAPIClient

func (c *ControllerCommandBase) NewModelManagerAPIClient() (*modelmanager.Client, error)

NewModelManagerAPIClient returns an API client for the ModelManager on the current controller using the current credentials.

func (*ControllerCommandBase) NewUserManagerAPIClient

func (c *ControllerCommandBase) NewUserManagerAPIClient() (*usermanager.Client, error)

NewUserManagerAPIClient returns an API client for the UserManager on the current controller using the current credentials.

func (*ControllerCommandBase) SetClientStore

func (c *ControllerCommandBase) SetClientStore(store jujuclient.ClientStore)

SetClientStore implements the ControllerCommand interface.

func (*ControllerCommandBase) SetControllerName

func (c *ControllerCommandBase) SetControllerName(controllerName string, allowDefault bool) error

SetControllerName implements ControllerCommand.SetControllerName.

type GetCredentialsParams

type GetCredentialsParams struct {
	// Cloud is the cloud definition.
	Cloud cloud.Cloud

	// CloudRegion is the name of the region that the user has specified.
	// If this is empty, then GetCredentials will determine the default
	// region, and return that. The default region is the one set by the
	// user in credentials.yaml, or if there is none set, the first region
	// in the cloud's list.
	CloudRegion string

	// CredentialName is the name of the credential to get.
	CredentialName string
}

GetCredentialsParams contains parameters for the GetCredentials function.

type IAASOnlyCommand

type IAASOnlyCommand interface {
	// contains filtered or unexported methods
}

IAASOnlyCommand is used as a marker and is embedded by commands which should only run in IAAS models.

type ModelAPI

type ModelAPI interface {
	ListModels(user string) ([]base.UserModel, error)
	Close() error
}

ModelAPI provides access to the model client facade methods.

type ModelCommand

type ModelCommand interface {
	Command

	// SetClientStore is called prior to the wrapped command's Init method
	// with the default controller store. It may also be called to override the
	// default controller store for testing.
	SetClientStore(jujuclient.ClientStore)

	// ClientStore returns the controller store that the command is
	// associated with.
	ClientStore() jujuclient.ClientStore

	// SetModelName sets the model name for this command. Setting the model
	// name will also set the related controller name. The model name can
	// be qualified with a controller name (controller:model), or
	// unqualified, in which case it will be assumed to be within the
	// current controller.
	//
	// Passing an empty model name will choose the default
	// model, or return an error if there isn't one.
	//
	// SetModelName is called prior to the wrapped command's Init method
	// with the active model name. The model name is guaranteed
	// to be non-empty at entry of Init.
	SetModelName(modelName string, allowDefault bool) error

	// ModelName returns the name of the model.
	ModelName() (string, error)

	// ModelType returns the type of the model.
	ModelType() (model.ModelType, error)

	// ModelGeneration sets the model generation for this command and updates
	// the store.
	SetModelGeneration(model.GenerationVersion) error

	// ModelGeneration returns the generation of the model.
	ModelGeneration() (model.GenerationVersion, error)

	// ControllerName returns the name of the controller that contains
	// the model returned by ModelName().
	ControllerName() (string, error)
	// contains filtered or unexported methods
}

ModelCommand extends cmd.Command with a SetModelName method.

func Wrap

func Wrap(c ModelCommand, options ...WrapOption) ModelCommand

Wrap wraps the specified ModelCommand, returning a ModelCommand that proxies to each of the ModelCommand methods. Any provided options are applied to the wrapped command before it is returned.

type ModelCommandBase

type ModelCommandBase struct {
	CommandBase
	// contains filtered or unexported fields
}

ModelCommandBase is a convenience type for embedding in commands that wish to implement ModelCommand.

func (*ModelCommandBase) BakeryClient

func (c *ModelCommandBase) BakeryClient() (*httpbakery.Client, error)

func (*ModelCommandBase) ClientStore

func (c *ModelCommandBase) ClientStore() jujuclient.ClientStore

ClientStore implements the ModelCommand interface.

func (*ModelCommandBase) ControllerName

func (c *ModelCommandBase) ControllerName() (string, error)

ControllerName implements the ModelCommand interface.

func (*ModelCommandBase) CookieJar

func (c *ModelCommandBase) CookieJar() (http.CookieJar, error)

func (*ModelCommandBase) CurrentAccountDetails

func (c *ModelCommandBase) CurrentAccountDetails() (*jujuclient.AccountDetails, error)

CurrentAccountDetails returns details of the account associated with the current controller.

func (*ModelCommandBase) ModelDetails

func (c *ModelCommandBase) ModelDetails() (string, *jujuclient.ModelDetails, error)

func (*ModelCommandBase) ModelGeneration

func (c *ModelCommandBase) ModelGeneration() (model.GenerationVersion, error)

ModelGeneration implements the ModelCommand interface.

func (*ModelCommandBase) ModelName

func (c *ModelCommandBase) ModelName() (string, error)

ModelName implements the ModelCommand interface.

func (*ModelCommandBase) ModelType

func (c *ModelCommandBase) ModelType() (model.ModelType, error)

ModelType implements the ModelCommand interface.

func (*ModelCommandBase) ModelUUIDs

func (c *ModelCommandBase) ModelUUIDs(modelNames []string) ([]string, error)

ModelUUIDs returns the model UUIDs for the given model names.

func (*ModelCommandBase) NewAPIClient

func (c *ModelCommandBase) NewAPIClient() (*api.Client, error)

func (*ModelCommandBase) NewAPIRoot

func (c *ModelCommandBase) NewAPIRoot() (api.Connection, error)

NewAPIRoot returns a new connection to the API server for the environment directed to the model specified on the command line.

func (*ModelCommandBase) NewControllerAPIRoot

func (c *ModelCommandBase) NewControllerAPIRoot() (api.Connection, error)

NewControllerAPIRoot returns a new connection to the API server for the environment directed to the controller specified on the command line. This is for the use of model-centered commands that still want to talk to controller-only APIs.

func (*ModelCommandBase) NewModelManagerAPIClient

func (c *ModelCommandBase) NewModelManagerAPIClient() (*modelmanager.Client, error)

NewModelManagerAPIClient returns an API client for the ModelManager on the current controller using the current credentials.

func (*ModelCommandBase) SetClientStore

func (c *ModelCommandBase) SetClientStore(store jujuclient.ClientStore)

SetClientStore implements the ModelCommand interface.

func (*ModelCommandBase) SetModelGeneration

func (c *ModelCommandBase) SetModelGeneration(generation model.GenerationVersion) error

SetModelGeneration implements the ModelCommand interface.

func (*ModelCommandBase) SetModelName

func (c *ModelCommandBase) SetModelName(modelName string, allowDefault bool) error

SetModelName implements the ModelCommand interface.

type QualifyingClientStore

type QualifyingClientStore struct {
	jujuclient.ClientStore
}

QualifyingClientStore wraps a jujuclient.ClientStore, modifying model-related methods such that they accept unqualified model names, and automatically qualify them with the logged-in user name as necessary.

func (QualifyingClientStore) ModelByName

func (s QualifyingClientStore) ModelByName(controllerName, modelName string) (*jujuclient.ModelDetails, error)

Implements jujuclient.ModelGetter.

func (QualifyingClientStore) QualifiedModelName

func (s QualifyingClientStore) QualifiedModelName(controllerName, modelName string) (string, error)

QualifiedModelName returns a Qualified model name, given either an unqualified or qualified model name. If the input is a fully qualified name, it is returned untouched; otherwise it is return qualified with the logged-in user name.

func (QualifyingClientStore) RemoveModel

func (s QualifyingClientStore) RemoveModel(controllerName, modelName string) error

Implements jujuclient.ModelRemover.

func (QualifyingClientStore) SetCurrentModel

func (s QualifyingClientStore) SetCurrentModel(controllerName, modelName string) error

Implements jujuclient.ModelUpdater.

func (QualifyingClientStore) SetModels

func (s QualifyingClientStore) SetModels(controllerName string, models map[string]jujuclient.ModelDetails) error

Implements jujuclient.ModelUpdater.

func (QualifyingClientStore) UpdateModel

func (s QualifyingClientStore) UpdateModel(controllerName, modelName string, details jujuclient.ModelDetails) error

Implements jujuclient.ModelUpdater.

type RegisterCredentialsParams

type RegisterCredentialsParams struct {
	// Cloud is the cloud definition.
	Cloud cloud.Cloud
}

RegisterCredentialsParams contains parameters for the RegisterCredentials function.

type TestCloudProvider

type TestCloudProvider interface {
	environs.EnvironProvider
	environs.ProviderCredentialsRegister
}

TestCloudProvider is used for testing.

type WrapControllerOption

type WrapControllerOption func(*controllerCommandWrapper)

WrapControllerOption specifies an option to the WrapController function.

var (
	// WrapControllerSkipControllerFlags specifies that the -c
	// and --controller flag flags should not be defined.
	WrapControllerSkipControllerFlags WrapControllerOption = wrapControllerSkipControllerFlags

	// WrapSkipDefaultModel specifies that no default controller should
	// be used.
	WrapControllerSkipDefaultController WrapControllerOption = wrapControllerSkipDefaultController
)

Options for the WrapController call.

type WrapOption

type WrapOption func(*modelCommandWrapper)

WrapOption specifies an option to the Wrap function.

var (
	// WrapSkipModelFlags specifies that the -m and --model flags
	// should not be defined.
	WrapSkipModelFlags WrapOption = wrapSkipModelFlags

	// WrapSkipDefaultModel specifies that no default model should
	// be used.
	WrapSkipDefaultModel WrapOption = wrapSkipDefaultModel
)

Options for the Wrap function.

Jump to

Keyboard shortcuts

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