juju.controller

Summary

Controller

Methods:

RemoveError
 

Reference

class juju.controller.Controller(loop=None, max_frame_size=None, bakery_client=None, jujudata=None)[source]

Bases: object

coroutine add_credential(name=None, credential=None, cloud=None, owner=None, force=False)[source]

Add or update a credential to the controller.

Parameters:
  • name (str) – Name of new credential. If None, the default local credential is used. Name must be provided if a credential is given.
  • credential (CloudCredential) – Credential to add. If not given, it will attempt to read from local data, if available.
  • cloud (str) – Name of cloud to associate the credential with. Defaults to the same cloud as the controller.
  • owner (str) – Username that will own the credential. Defaults to the current user.
  • force (bool) – Force indicates whether the update should be forced. It’s only supported for facade v3 or later. Defaults to false.
Returns:

Name of credential that was uploaded.

coroutine add_model(model_name, cloud_name=None, credential_name=None, owner=None, config=None, region=None)[source]

Add a model to this controller.

Parameters:
  • model_name (str) – Name to give the new model.
  • cloud_name (str) – Name of the cloud in which to create the model, e.g. ‘aws’. Defaults to same cloud as controller.
  • credential_name (str) – Name of the credential to use when creating the model. If not given, it will attempt to find a default credential.
  • owner (str) – Username that will own the model. Defaults to the current user.
  • config (dict) – Model configuration.
  • region (str) – Region in which to create the model.
Return Model:

A connection to the newly created model.

coroutine add_user(username, password=None, display_name=None)[source]

Add a user to this controller.

Parameters:
  • username (str) – Username
  • password (str) – Password
  • display_name (str) – Display name
Returns:

A User instance

coroutine change_user_password(username, password)[source]

Change the password for a user in this controller.

Parameters:
  • username (str) – Username
  • password (str) – New password
coroutine cloud(name=None)[source]

Get Cloud

Parameters:name (str) – Cloud name. If not specified, the cloud where the controller lives on is returned.
Returns:-> ~CloudResult
coroutine clouds()[source]

Get all the clouds in the controller

Returns:-> ~CloudsResult
coroutine connect(*args, **kwargs)[source]

Connect to a Juju controller.

This supports two calling conventions:

The controller and (optionally) authentication information can be taken from the data files created by the Juju CLI. This convention will be used if a controller_name is specified, or if the endpoint is not.

Otherwise, both the endpoint and authentication information (username and password, or bakery_client and/or macaroons) are required.

If a single positional argument is given, it will be assumed to be the controller_name. Otherwise, the first positional argument, if any, must be the endpoint.

Available parameters are:

Parameters:
  • controller_name (str) – Name of controller registered with the Juju CLI.
  • endpoint (str) – The hostname:port of the controller to connect to.
  • username (str) – The username for controller-local users (or None to use macaroon-based login.)
  • password (str) – The password for controller-local users.
  • cacert (str) – The CA certificate of the controller (PEM formatted).
  • bakery_client (httpbakery.Client) – The macaroon bakery client to to use when performing macaroon-based login. Macaroon tokens acquired when logging will be saved to bakery_client.cookies. If this is None, a default bakery_client will be used.
  • macaroons (list) – List of macaroons to load into the bakery_client.
  • loop (asyncio.BaseEventLoop) – The event loop to use for async operations.
  • max_frame_size (int) – The maximum websocket frame size to allow.
  • specified_facades – Overwrite the facades with a series of specified facades.
coroutine connect_controller(controller_name)[source]

Deprecated since version 0.7.3: Use connect(controller_name)() instead.

coroutine connect_current()[source]

Deprecated since version 0.7.3: Use connect() instead.

connection()[source]

Return the current Connection object. It raises an exception if the Controller is disconnected

controller_name
controller_uuid
coroutine create_offer(model_uuid, endpoint, offer_name=None, application_name=None)[source]

Offer a deployed application using a series of endpoints for use by consumers.

@param endpoint: holds the application and endpoint you want to offer @param offer_name: over ride the offer name to help the consumer

coroutine destroy(destroy_all_models=False, destroy_storage=False)[source]

Destroy this controller.

Parameters:
  • destroy_all_models (bool) – Destroy all hosted models in the controller.
  • destroy_storage (bool) – Destory all hosted storage in the controller.
coroutine destroy_model(*models, destroy_storage=False)

Destroy one or more models.

Parameters:
  • *models (str) –

    Names or UUIDs of models to destroy

  • destroy_storage (bool) – Whether or not to destroy storage when destroying the models. Defaults to false.
coroutine destroy_models(*models, destroy_storage=False)[source]

Destroy one or more models.

Parameters:
  • *models (str) –

    Names or UUIDs of models to destroy

  • destroy_storage (bool) – Whether or not to destroy storage when destroying the models. Defaults to false.
coroutine disable_user(username)[source]

Disable a user.

Parameters:username (str) – Username
coroutine disconnect()[source]

Shut down the watcher task and close websockets.

coroutine enable_user(username)[source]

Re-enable a previously disabled user.

coroutine get_cloud()[source]

Get the name of the cloud that this controller lives on.

coroutine get_consume_details(endpoint)[source]

get_consume_details returns the details necessary to pass to another model to consume the specified offers represented by the urls.

coroutine get_model(model)[source]

Get a model by name or UUID.

Parameters:model (str) – Model name or UUID
Returns Model:Connected Model instance.
coroutine get_models(all_=False, username=None)[source]

Deprecated since version 0.7.0: Use list_models() instead.

get_payloads(*patterns)[source]

Return list of known payloads.

Parameters:*patterns (str) –

Patterns to match against

Each pattern will be checked against the following info in Juju:

- unit name
- machine id
- payload type
- payload class
- payload id
- payload tag
- payload status
coroutine get_user(username, secret_key=None)[source]

Get a user by name.

Parameters:
  • username (str) – Username
  • secret_key (str) – Issued by juju when add or reset user password
Returns:

A User instance

coroutine get_users(include_disabled=False)[source]

Return list of users that can connect to this controller.

Parameters:include_disabled (bool) – Include disabled users
Returns:A list of User instances
coroutine grant(username, acl='login')[source]

Grant access level of the given user on the controller. Note that if the user already has higher permissions than the provided ACL, this will do nothing (see revoke for a way to remove permissions). :param str username: Username :param str acl: Access control (‘login’, ‘add-model’ or ‘superuser’) :returns: True if new access was granted, False if user already had

requested access or greater. Raises JujuError if failed.
coroutine grant_model(username, model_uuid, acl='read')[source]

Grant a user access to a model. Note that if the user already has higher permissions than the provided ACL, this will do nothing (see revoke_model for a way to remove permissions).

Parameters:
  • username (str) – Username
  • model_uuid (str) – The UUID of the model to change.
  • acl (str) – Access control (‘read, ‘write’ or ‘admin’)
is_connected()[source]

Reports whether the Controller is currently connected.

kill()[source]

Forcibly terminate all machines and other associated resources for this controller.

coroutine list_models()[source]

Return list of names of the available models on this controller.

Equivalent to sorted((await self.model_uuids()).keys())

coroutine list_offers(model_name)[source]

Offers list information about applications’ endpoints that have been shared and who is connected.

login()[source]

Log in to this controller.

logout(force=False)[source]

Log out of this controller.

Parameters:force (bool) – Don’t fail even if user not previously logged in with a password
loop
coroutine model_uuids()[source]

Return a mapping of model names to UUIDs.

coroutine remove_offer(model_uuid, offer, force=False)[source]

Remove offer for an application.

Offers will also remove relations to those offers, use force to do so, without an error.

coroutine remove_user(username)[source]

Remove a user from this controller.

coroutine reset_user_password(username)[source]

Reset user password.

Parameters:username (str) – Username
Returns:A User instance
coroutine revoke(username, acl='login')[source]

Removes some or all access of a user to from a controller If ‘login’ access is revoked, the user will no longer have any permissions on the controller. Revoking a higher privilege from a user without that privilege will have no effect.

Parameters:
  • username (str) – username
  • acl (str) – Access to remove (‘login’, ‘add-model’ or ‘superuser’)
coroutine revoke_model(username, model_uuid, acl='read')[source]

Revoke some or all of a user’s access to a model. If ‘read’ access is revoked, the user will no longer have any permissions on the model. Revoking a higher privilege from a user without that privilege will have no effect.

Parameters:
  • username (str) – Username to revoke
  • model_uuid (str) – The UUID of the model to change.
  • acl (str) – Access control (‘read, ‘write’ or ‘admin’)
exception juju.controller.RemoveError(message)[source]

Bases: Exception