Clarified that params are optional.
[osm/N2VC.git] / juju / controller.py
1 import asyncio
2 import logging
3
4 from .client import client
5 from .client import connection
6 from .client import watcher
7 from .model import Model
8
9 log = logging.getLogger(__name__)
10
11
12 class Controller(object):
13 async def connect_current(self):
14 """Connect to the current Juju controller.
15
16 """
17 self.connection = (
18 await connection.Connection.connect_current_controller())
19
20 async def disconnect(self):
21 """Shut down the watcher task and close websockets.
22
23 """
24 if self.connection and self.connection.is_open:
25 log.debug('Closing controller connection')
26 await self.connection.close()
27 self.connection = None
28
29 async def add_model(
30 self, name, cloud, credential, owner=None,
31 config=None, region=None):
32 """Add a model to this controller.
33
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
38
39 """
40 model_facade = client.ModelManagerFacade()
41 model_facade.connect(self.connection)
42
43 log.debug('Creating model %s', name)
44
45 model_info = await model_facade.CreateModel(
46 cloud,
47 config,
48 credential,
49 name,
50 owner or self.connection.info['user-info']['identity'],
51 region,
52 )
53
54 model = Model()
55 await model.connect(
56 self.connection.endpoint,
57 model_info.uuid,
58 self.connection.username,
59 self.connection.password,
60 self.connection.cacert,
61 self.connection.macaroons,
62 )
63
64 return model
65
66 def add_user(self, username, display_name=None, acl=None, models=None):
67 """Add a user to this controller.
68
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
73
74 """
75 pass
76
77 def change_user_password(self, username, password):
78 """Change the password for a user in this controller.
79
80 :param str username: Username
81 :param str password: New password
82
83 """
84 pass
85
86 def destroy(self, destroy_all_models=False):
87 """Destroy this controller.
88
89 :param bool destroy_all_models: Destroy all hosted models in the
90 controller.
91
92 """
93 pass
94
95 def disable_user(self, username):
96 """Disable a user.
97
98 :param str username: Username
99
100 """
101 pass
102
103 def enable_user(self):
104 """Re-enable a previously disabled user.
105
106 """
107 pass
108
109 def kill(self):
110 """Forcibly terminate all machines and other associated resources for
111 this controller.
112
113 """
114 pass
115
116 def get_models(self, all_=False, username=None):
117 """Return list of available models on this controller.
118
119 :param bool all_: List all models, regardless of user accessibilty
120 (admin use only)
121 :param str username: User for which to list models (admin use only)
122
123 """
124 pass
125
126 def get_payloads(self, *patterns):
127 """Return list of known payloads.
128
129 :param str \*patterns: Patterns to match against
130
131 Each pattern will be checked against the following info in Juju::
132
133 - unit name
134 - machine id
135 - payload type
136 - payload class
137 - payload id
138 - payload tag
139 - payload status
140
141 """
142 pass
143
144 def get_users(self, all_=False):
145 """Return list of users that can connect to this controller.
146
147 :param bool all_: Include disabled users
148
149 """
150 pass
151
152 def login(self):
153 """Log in to this controller.
154
155 """
156 pass
157
158 def logout(self, force=False):
159 """Log out of this controller.
160
161 :param bool force: Don't fail even if user not previously logged in
162 with a password
163
164 """
165 pass
166
167 def get_model(self, name):
168 """Get a model by name.
169
170 :param str name: Model name
171
172 """
173 pass
174
175 def get_user(self, username):
176 """Get a user by name.
177
178 :param str username: Username
179
180 """
181 pass