modelcmd

package
v0.0.0-...-2608902 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2016 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CurrentControllerFilename = "current-controller"
)

Variables

View Source
var (
	// ErrNoControllerSpecified 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.
	ErrNoControllerSpecified = errors.New(`no controller specified

There is no current controller. Please use "juju switch" to
set the current controller/model, or create a new controller
using "juju bootstrap".
`)

	// ErrNoAccountSpecified is returned by commands that operate on a
	// controller if there is no current account associated with the
	// controller.
	ErrNoAccountSpecified = errors.New("no account specified")
)
View Source
var ErrConnTimedOut = errors.New("open connection timed out")
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 specified

There is no current model specified for the current controller,
and none specified on the command line. Please use "juju switch"
to set the current model, or specify a model on the command line
using the "-m" flag.
`)

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 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 ControllerSkipDefault

func ControllerSkipDefault(w *sysCommandWrapper)

ControllerSkipDefault instructs the wrapper not to use the default controller name.

func ControllerSkipFlags

func ControllerSkipFlags(w *sysCommandWrapper)

ControllerSkipFlags instructs the wrapper to skip -c and --controller flag definition.

func DetectCredential

func DetectCredential(cloudName, cloudType string) (*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 GetCredentials

func GetCredentials(
	store jujuclient.CredentialGetter, region, credentialName, cloudName, cloudType string,
) (_ *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 GetCurrentModel

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

GetCurrentModel returns the name of the current Juju model.

If $JUJU_MODEL is set, use that. Otherwise, get the current controller by reading $XDG_DATA_HOME/juju/current-controller, and then identifying the current model for that controller in models.yaml. If there is no current controller, or no current model for that controller, then an empty string is returned. It is not an error to have no default model.

func JoinModelName

func JoinModelName(controller, model string) string

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

func ModelSkipDefault

func ModelSkipDefault(w *modelCommandWrapper)

ModelSkipDefault instructs the wrapper not to use the default model.

func ModelSkipFlags

func ModelSkipFlags(w *modelCommandWrapper)

ModelSkipFlags instructs the wrapper to skip --m and --model flag definition.

func NewGetBootstrapConfigFunc

func NewGetBootstrapConfigFunc(store jujuclient.ClientStore) func(string) (*config.Config, error)

NewGetBootstrapConfigFunc returns a function that, given a controller name, returns the bootstrap config for that controller in the given client store.

func ReadCurrentController

func ReadCurrentController() (string, error)

ReadCurrentController reads the file $JUJU_DATA/current-controller and return the value stored there. If the file doesn't exist an empty string is returned and no error.

func ResolveControllerName

func ResolveControllerName(store jujuclient.ControllerStore, controllerName string) (string, error)

ResolveControllerName returns the canonical name of a controller given an unambiguous identifier for that controller. Locally created controllers (i.e. those whose names begin with "local.") may be identified with or without the "local." prefix if there exists no other controller in the store with the same unprefixed name.

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.

func Wrap

func Wrap(c ModelCommand, options ...WrapEnvOption) cmd.Command

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

func WrapBase

func WrapBase(c CommandBase) cmd.Command

WrapBase wraps the specified CommandBase, returning a Command that proxies to each of the CommandBase methods.

func WrapController

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

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

func WriteCurrentController

func WriteCurrentController(controllerName string) error

WriteCurrentController writes the controllerName to the file $JUJU_DATA/current-controller file.

Types

type APIContext

type APIContext struct {
	Jar          *cookiejar.Jar
	BakeryClient *httpbakery.Client
}

APIContext holds the context required for making connections to APIs used by juju.

func NewAPIContext

func NewAPIContext(ctxt *cmd.Context) (*APIContext, error)

NewAPIContext returns an API context that will use the given context for user interactions when authorizing. The returned API context must be closed after use.

If ctxt is nil, no command-line authorization will be supported.

This function is provided for use by commands that cannot use JujuCommandBase. Most clients should use that instead.

func (*APIContext) Close

func (ctxt *APIContext) Close() error

Close closes the API context, saving any cookies to the persistent cookie jar.

type APIOpener

type APIOpener interface {
	Open(store jujuclient.ClientStore, controllerName, accountName, modelName string) (api.Connection, error)
}

APIOpener provides a way to open a connection to the Juju API Server through the named connection.

func NewTimeoutOpener

func NewTimeoutOpener(opener APIOpener, clock clock.Clock, timeout time.Duration) APIOpener

NewTimeoutOpener will call the opener when Open is called, but if the opener does not return by the specified timeout, ErrConnTimeOut is returned.

type CommandBase

type CommandBase interface {
	cmd.Command
	// contains filtered or unexported methods
}

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

type ControllerCommand

type ControllerCommand interface {
	CommandBase

	// 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 is called prior to the wrapped command's Init method with
	// the active controller name. The controller name is guaranteed to be non-empty
	// at entry of Init. It records the current model name in the
	// ControllerCommandBase.
	SetControllerName(controllerName string) error

	// ControllerName returns the name of the controller or model used to
	// determine that API end point.
	ControllerName() string

	// SetAPIOpener allows the replacement of the default API opener,
	// which ends up calling NewAPIRoot
	SetAPIOpener(opener APIOpener)
}

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

type ControllerCommandBase

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

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

func (*ControllerCommandBase) AccountName

func (c *ControllerCommandBase) AccountName() string

AccountName implements the ControllerCommand interface.

func (*ControllerCommandBase) ClientStore

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

ClientStore implements the ControllerCommand interface.

func (*ControllerCommandBase) ControllerName

func (c *ControllerCommandBase) ControllerName() string

ControllerName implements the ControllerCommand interface.

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) 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) SetAPIOpener

func (c *ControllerCommandBase) SetAPIOpener(opener APIOpener)

SetAPIOpener specifies the strategy used by the command to open the API connection.

func (*ControllerCommandBase) SetClientStore

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

SetClientStore implements the ControllerCommand interface.

func (*ControllerCommandBase) SetControllerName

func (c *ControllerCommandBase) SetControllerName(controllerName string) error

SetControllerName implements the ControllerCommand interface.

type JujuCommandBase

type JujuCommandBase struct {
	cmd.CommandBase
	// contains filtered or unexported fields
}

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

func (*JujuCommandBase) APIOpen

func (c *JujuCommandBase) 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.

func (*JujuCommandBase) BakeryClient

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

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

func (*JujuCommandBase) HTTPClient

func (c *JujuCommandBase) HTTPClient() (*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 (*JujuCommandBase) NewAPIConnectionParams

func (c *JujuCommandBase) NewAPIConnectionParams(
	store jujuclient.ClientStore,
	controllerName, accountName, modelName string,
) (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 JujuCommandBase.NewAPIRoot with the same arguments.

func (*JujuCommandBase) NewAPIRoot

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

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

func (*JujuCommandBase) RefreshModels

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

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

func (*JujuCommandBase) SetModelApi

func (c *JujuCommandBase) SetModelApi(api ModelAPI)

SetModelApi sets the api used to access model information.

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 {
	CommandBase

	// 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.
	//
	// 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) error

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

	// ControllerName returns the name of the controller that contains
	// the model returned by ModelName().
	ControllerName() string

	// SetAPIOpener allows the replacement of the default API opener,
	// which ends up calling NewAPIRoot
	SetAPIOpener(opener APIOpener)
}

ModelCommand extends cmd.Command with a SetModelName method.

type ModelCommandBase

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

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

func (*ModelCommandBase) AccountName

func (c *ModelCommandBase) AccountName() string

AccountName implements the ModelCommand interface.

func (*ModelCommandBase) ClientStore

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

ClientStore implements the ModelCommand interface.

func (*ModelCommandBase) ConnectionName

func (c *ModelCommandBase) ConnectionName() string

ConnectionName returns the name of the connection if there is one. It is possible that the name of the connection is empty if the connection information is supplied through command line arguments or environment variables.

func (*ModelCommandBase) ControllerName

func (c *ModelCommandBase) ControllerName() string

ControllerName implements the ModelCommand interface.

func (*ModelCommandBase) ModelName

func (c *ModelCommandBase) ModelName() string

ModelName implements the ModelCommand interface.

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.

func (*ModelCommandBase) SetAPIOpener

func (c *ModelCommandBase) SetAPIOpener(opener APIOpener)

SetAPIOpener specifies the strategy used by the command to open the API connection.

func (*ModelCommandBase) SetClientStore

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

SetClientStore implements the ModelCommand interface.

func (*ModelCommandBase) SetModelName

func (c *ModelCommandBase) SetModelName(modelName string) error

SetModelName implements the ModelCommand interface.

type ModelGetter

type ModelGetter interface {
	ModelGet() (map[string]interface{}, error)
	Close() error
}

type OpenFunc

func (OpenFunc) Open

func (f OpenFunc) Open(store jujuclient.ClientStore, controllerName, accountName, modelName string) (api.Connection, error)

type WrapControllerOption

type WrapControllerOption func(*sysCommandWrapper)

WrapControllerOption sets various parameters of the ControllerCommand wrapper.

func ControllerAPIOpener

func ControllerAPIOpener(opener APIOpener) WrapControllerOption

ControllerAPIOpener instructs the underlying controller command to use a different APIOpener strategy.

type WrapEnvOption

type WrapEnvOption func(*modelCommandWrapper)

WrapControllerOption sets various parameters of the ModelCommand wrapper.

Jump to

Keyboard shortcuts

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