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 async def destroy_models(self
, *args
):
68 """Destroy a model to this controller.
70 :param str : model-<UUID>
73 model_facade
= client
.ModelManagerFacade()
74 model_facade
.connect(self
.connection
)
77 log
.debug('Destroying Model %s', arg
)
78 await model_facade
.DestroyModels([client
.Entity(arg
)])
80 def add_user(self
, username
, display_name
=None, acl
=None, models
=None):
81 """Add a user to this controller.
83 :param str username: Username
84 :param str display_name: Display name
85 :param str acl: Access control, e.g. 'read'
86 :param list models: Models to which the user is granted access
91 def change_user_password(self
, username
, password
):
92 """Change the password for a user in this controller.
94 :param str username: Username
95 :param str password: New password
100 def destroy(self
, destroy_all_models
=False):
101 """Destroy this controller.
103 :param bool destroy_all_models: Destroy all hosted models in the
109 def disable_user(self
, username
):
112 :param str username: Username
117 def enable_user(self
):
118 """Re-enable a previously disabled user.
124 """Forcibly terminate all machines and other associated resources for
130 def get_models(self
, all_
=False, username
=None):
131 """Return list of available models on this controller.
133 :param bool all_: List all models, regardless of user accessibilty
135 :param str username: User for which to list models (admin use only)
140 def get_payloads(self
, *patterns
):
141 """Return list of known payloads.
143 :param str \*patterns: Patterns to match against
145 Each pattern will be checked against the following info in Juju::
158 def get_users(self
, all_
=False):
159 """Return list of users that can connect to this controller.
161 :param bool all_: Include disabled users
167 """Log in to this controller.
172 def logout(self
, force
=False):
173 """Log out of this controller.
175 :param bool force: Don't fail even if user not previously logged in
181 def get_model(self
, name
):
182 """Get a model by name.
184 :param str name: Model name
189 def get_user(self
, username
):
190 """Get a user by name.
192 :param str username: Username