4 from .client
import client
5 from .client
import connection
6 from .client
import watcher
7 from .model
import Model
9 log
= logging
.getLogger(__name__
)
12 class Controller(object):
13 async def connect_current(self
):
14 """Connect to the current Juju controller.
18 await connection
.Connection
.connect_current_controller())
20 async def disconnect(self
):
21 """Shut down the watcher task and close websockets.
24 if self
.connection
and self
.connection
.is_open
:
25 log
.debug('Closing controller connection')
26 await self
.connection
.close()
27 self
.connection
= None
30 self
, name
, cloud
, credential
, owner
=None,
31 config
=None, region
=None):
32 """Add a model to this controller.
34 :param str name: Name of the model
35 :param dict config: Model configuration
36 :param str credential: e.g. '<cloud>:<credential>'
37 :param str owner: Owner username
40 model_facade
= client
.ModelManagerFacade()
41 model_facade
.connect(self
.connection
)
43 log
.debug('Creating model %s', name
)
45 model_info
= await model_facade
.CreateModel(
50 owner
or self
.connection
.info
['user-info']['identity'],
56 self
.connection
.endpoint
,
58 self
.connection
.username
,
59 self
.connection
.password
,
60 self
.connection
.cacert
,
61 self
.connection
.macaroons
,
66 def add_user(self
, username
, display_name
=None, acl
=None, models
=None):
67 """Add a user to this controller.
69 :param str username: Username
70 :param str display_name: Display name
71 :param str acl: Access control, e.g. 'read'
72 :param list models: Models to which the user is granted access
77 def change_user_password(self
, username
, password
):
78 """Change the password for a user in this controller.
80 :param str username: Username
81 :param str password: New password
86 def destroy(self
, destroy_all_models
=False):
87 """Destroy this controller.
89 :param bool destroy_all_models: Destroy all hosted models in the
95 def disable_user(self
, username
):
98 :param str username: Username
103 def enable_user(self
):
104 """Re-enable a previously disabled user.
110 """Forcibly terminate all machines and other associated resources for
116 def get_models(self
, all_
=False, username
=None):
117 """Return list of available models on this controller.
119 :param bool all_: List all models, regardless of user accessibilty
121 :param str username: User for which to list models (admin use only)
126 def get_payloads(self
, *patterns
):
127 """Return list of known payloads.
129 :param str \*patterns: Patterns to match against
131 Each pattern will be checked against the following info in Juju::
144 def get_users(self
, all_
=False):
145 """Return list of users that can connect to this controller.
147 :param bool all_: Include disabled users
153 """Log in to this controller.
158 def logout(self
, force
=False):
159 """Log out of this controller.
161 :param bool force: Don't fail even if user not previously logged in
167 def get_model(self
, name
):
168 """Get a model by name.
170 :param str name: Model name
175 def get_user(self
, username
):
176 """Get a user by name.
178 :param str username: Username