juju: github.com/juju/juju/cmd/modelcmd Index | Files

package modelcmd

import "github.com/juju/juju/cmd/modelcmd"

Index

Package Files

apicontext.go base.go clientstore.go controller.go credentials.go modelcommand.go

Variables

var (
    ErrNoControllersDefined = errors.New("" /* 182 byte string literal not displayed */)

    ErrNoCurrentController = errors.New(`No selected controller.

Please use "juju switch" to select a controller.
`)
)
var (
    // ErrMultipleCredentials is the error returned by DetectCredential
    // if more than one credential is detected.
    ErrMultipleCredentials = errors.New("more than one credential detected")
)
var ErrNoModelSpecified = errors.New("" /* 200 byte string literal not displayed */)

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.

func AnnotateWithFinalizationError Uses

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

func BootstrapContext Uses

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

BootstrapContext returns a new BootstrapContext constructed from a command Context.

func BootstrapContextNoVerify Uses

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 Uses

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 DetermineCurrentController Uses

func DetermineCurrentController(store jujuclient.ClientStore) (string, error)

DetermineCurrentController returns current controller on this client. It considers commandline flags, environment variables, and current config.

func FinalizeFileContent Uses

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 Uses

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 Uses

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 IsModelMigratedError Uses

func IsModelMigratedError(err error) bool

IsModelMigratedError returns true if err is of type modelMigratedError.

func JoinModelName Uses

func JoinModelName(controller, model string) string

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

func NewGetBootstrapConfigParamsFunc Uses

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 Uses

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 Uses

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.

func VerifyCredentials Uses

func VerifyCredentials(ctx *cmd.Context, aCloud *cloud.Cloud, credential *cloud.Credential, credentialName string, regionName string) (_ *cloud.Credential, _ error)

VerifyCredentials ensures that a given credential complies with the provider/cloud understanding of what its valid credential looks like.

type AuthOpts Uses

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 Uses

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

type CAASOnlyCommand Uses

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 Uses

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 Uses

func WrapBase(c Command) Command

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

type CommandBase Uses

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 Uses

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 Uses

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 Uses

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) ControllerUUID Uses

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

ControllerUUID returns the controller UUID for specified controller name.

func (*CommandBase) CookieJar Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 current 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 Uses

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

SetAPIOpen sets the function used for opening an API connection.

func (*CommandBase) SetControllerModels Uses

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

func (*CommandBase) SetFlags Uses

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

SetFlags implements cmd.Command.SetFlags.

func (*CommandBase) SetModelAPI Uses

func (c *CommandBase) SetModelAPI(api ModelAPI)

SetModelAPI sets the api used to access model information.

func (*CommandBase) SetModelRefresh Uses

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

SetModelRefresh sets the function used for refreshing models.

type ControllerCommand Uses

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 Uses

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 Uses

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 Uses

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

func (*ControllerCommandBase) ClientStore Uses

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

ClientStore implements the ControllerCommand interface.

func (*ControllerCommandBase) ControllerName Uses

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

ControllerName implements the ControllerCommand interface.

func (*ControllerCommandBase) CookieJar Uses

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

func (*ControllerCommandBase) CurrentAccountDetails Uses

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

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

func (*ControllerCommandBase) ModelUUIDs Uses

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

ModelUUIDs returns the model UUIDs for the given model names.

func (*ControllerCommandBase) NewAPIRoot Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

SetClientStore implements the ControllerCommand interface.

func (*ControllerCommandBase) SetControllerName Uses

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

SetControllerName implements ControllerCommand.SetControllerName.

type GetCredentialsParams Uses

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 Uses

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 Uses

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

ModelAPI provides access to the model client facade methods.

type ModelCommand Uses

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

    // SetModelIdentifier sets the model identifier for this command.
    // Setting the model identifier 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.
    //
    // SetModelIdentifier is called prior to the wrapped command's Init method
    // with the active model name.
    // The model identifier is guaranteed to be non-empty at entry of Init.
    SetModelIdentifier(modelIdentifier string, allowDefault bool) error

    // ModelIdentifier returns a string identifying the target model.
    // It may be a model name, or a full or partial model UUID.
    ModelIdentifier() (string, error)

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

    // SetActiveBranch sets the branch to use for this command,
    // then updates the model's active branch in the local store.
    SetActiveBranch(string) error

    // ActiveBranch returns the current active branch for this model.
    ActiveBranch() (string, 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 Uses

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 Uses

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) ActiveBranch Uses

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

ActiveBranch implements the ModelCommand interface.

func (*ModelCommandBase) BakeryClient Uses

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

func (*ModelCommandBase) ClientStore Uses

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

ClientStore implements the ModelCommand interface.

func (*ModelCommandBase) ControllerName Uses

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

ControllerName implements the ModelCommand interface.

func (*ModelCommandBase) CookieJar Uses

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

func (*ModelCommandBase) CurrentAccountDetails Uses

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

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

func (*ModelCommandBase) ModelDetails Uses

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

ModelDetails returns details from the file store for the model indicated by the currently set controller name and model identifier.

func (*ModelCommandBase) ModelIdentifier Uses

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

ModelName implements the ModelCommand interface.

func (*ModelCommandBase) ModelType Uses

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

ModelType implements the ModelCommand interface.

func (*ModelCommandBase) ModelUUIDs Uses

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

ModelUUIDs returns the model UUIDs for the given model names.

func (*ModelCommandBase) NewAPIClient Uses

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

func (*ModelCommandBase) NewAPIRoot Uses

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 Uses

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 Uses

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) SetActiveBranch Uses

func (c *ModelCommandBase) SetActiveBranch(branchName string) error

SetModelGeneration implements the ModelCommand interface.

func (*ModelCommandBase) SetClientStore Uses

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

SetClientStore implements the ModelCommand interface.

func (*ModelCommandBase) SetModelIdentifier Uses

func (c *ModelCommandBase) SetModelIdentifier(modelIdentifier string, allowDefault bool) error

SetModelIdentifier implements the ModelCommand interface.

type OptionalControllerCommand Uses

type OptionalControllerCommand struct {
    CommandBase
    Store jujuclient.ClientStore

    EnabledFlag string

    // Local stores whether a client side (aka local) copy is requested.
    Local bool

    // ClientOnly stores whether the command will ONLY operate on a client copy
    // without affecting controller copy.
    ClientOnly bool

    // ControllerOnly stores whether the command will ONLY operate on a controller copy
    // without affecting client copy.
    ControllerOnly bool

    // BothClientAndController indicates that the operation need to take place on
    // both client and controller. This is the default argument, only selected if
    // neither ClientOnly nor ControllerOnly specified.
    BothClientAndController bool

    ControllerName string

    SkipCurrentControllerPrompt bool
}

OptionalControllerCommand is used as a base for commands which can act locally or on a controller. It is primarily intended to be used by cloud and credential related commands which can either update a local client cache, or a running controller.

func (*OptionalControllerCommand) ControllerNameFromArg Uses

func (c *OptionalControllerCommand) ControllerNameFromArg() (string, error)

ControllerNameFromArg returns either a controller name or empty string. A non default controller can be chosen using the --controller option. Use the --local arg to return an empty string, meaning no controller is selected.

func (*OptionalControllerCommand) Init Uses

func (c *OptionalControllerCommand) Init(args []string) (err error)

Init populates the command with the args from the command line.

func (*OptionalControllerCommand) MaybePromptCurrentController Uses

func (c *OptionalControllerCommand) MaybePromptCurrentController(ctxt *cmd.Context, action string) (string, error)

MaybePromptCurrentController checks if there is a current controller on a client. If there is and the user did not want to be prompted, the current controller will be returned. Otherwise, the user will be prompted if the current controller should be used and based on the answer the current controller may or may not be returned.

func (*OptionalControllerCommand) SetFlags Uses

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

SetFlags initializes the flags supported by the command.

type QualifyingClientStore Uses

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 Uses

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

Implements jujuclient.ModelGetter.

func (QualifyingClientStore) QualifiedModelName Uses

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 Uses

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

Implements jujuclient.ModelRemover.

func (QualifyingClientStore) SetCurrentModel Uses

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

Implements jujuclient.ModelUpdater.

func (QualifyingClientStore) SetModels Uses

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

Implements jujuclient.ModelUpdater.

func (QualifyingClientStore) UpdateModel Uses

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

Implements jujuclient.ModelUpdater.

type RegisterCredentialsParams Uses

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

RegisterCredentialsParams contains parameters for the RegisterCredentials function.

type TestCloudProvider Uses

type TestCloudProvider interface {
    environs.EnvironProvider
    environs.ProviderCredentialsRegister
}

TestCloudProvider is used for testing.

type WrapControllerOption Uses

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 Uses

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.

Package modelcmd imports 36 packages (graph) and is imported by 698 packages. Updated 2019-10-22. Refresh now. Tools for package owners.