f0ef3b9e8f37474166f9d2df19ddb73cfacdd7f4
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 : <UUID> of the Model
71 param accepts string of <UUID> only OR `model-<UUID>`
75 model_facade
= client
.ModelManagerFacade()
76 model_facade
.connect(self
.connection
)
78 #Generate list of args, pre-pend 'model-'
79 prependarg
= list(args
)
80 for index
, item
in enumerate(prependarg
):
81 if not item
.startswith('model-'):
82 prependarg
[index
]="model-%s" % item
84 #Create list of objects to pass to DestroyModels()
86 for arg
in prependarg
:
87 arglist
.append(client
.Entity(arg
))
88 log
.debug('Destroying Model %s', arg
)
90 await model_facade
.DestroyModels(arglist
)
92 def add_user(self
, username
, display_name
=None, acl
=None, models
=None):
93 """Add a user to this controller.
95 :param str username: Username
96 :param str display_name: Display name
97 :param str acl: Access control, e.g. 'read'
98 :param list models: Models to which the user is granted access
103 def change_user_password(self
, username
, password
):
104 """Change the password for a user in this controller.
106 :param str username: Username
107 :param str password: New password
112 def destroy(self
, destroy_all_models
=False):
113 """Destroy this controller.
115 :param bool destroy_all_models: Destroy all hosted models in the
121 def disable_user(self
, username
):
124 :param str username: Username
129 def enable_user(self
):
130 """Re-enable a previously disabled user.
136 """Forcibly terminate all machines and other associated resources for
142 def get_models(self
, all_
=False, username
=None):
143 """Return list of available models on this controller.
145 :param bool all_: List all models, regardless of user accessibilty
147 :param str username: User for which to list models (admin use only)
152 def get_payloads(self
, *patterns
):
153 """Return list of known payloads.
155 :param str \*patterns: Patterns to match against
157 Each pattern will be checked against the following info in Juju::
170 def get_users(self
, all_
=False):
171 """Return list of users that can connect to this controller.
173 :param bool all_: Include disabled users
179 """Log in to this controller.
184 def logout(self
, force
=False):
185 """Log out of this controller.
187 :param bool force: Don't fail even if user not previously logged in
193 def get_model(self
, name
):
194 """Get a model by name.
196 :param str name: Model name
201 def get_user(self
, username
):
202 """Get a user by name.
204 :param str username: Username