blob: 06f1ff69e38c77b10d762fd9dac8ce28ac967440 [file] [log] [blame]
Adam Israel5e08a0e2018-09-06 19:22:47 -04001import asyncio
Adam Israelc3e6c2e2018-03-01 09:31:50 -05002import logging
3import os
4import os.path
5import re
Adam Israelfa329072018-09-14 11:26:13 -04006import shlex
Adam Israelc3e6c2e2018-03-01 09:31:50 -05007import ssl
Adam Israelfa329072018-09-14 11:26:13 -04008import subprocess
Adam Israelc3e6c2e2018-03-01 09:31:50 -05009import sys
Adam Israel5e08a0e2018-09-06 19:22:47 -040010# import time
Adam Israelc3e6c2e2018-03-01 09:31:50 -050011
12# FIXME: this should load the juju inside or modules without having to
13# explicitly install it. Check why it's not working.
14# Load our subtree of the juju library
15path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
16path = os.path.join(path, "modules/libjuju/")
17if path not in sys.path:
18 sys.path.insert(1, path)
19
20from juju.controller import Controller
Adam Israel5e08a0e2018-09-06 19:22:47 -040021from juju.model import ModelObserver
Adam Israel136186e2018-09-14 12:01:12 -040022from juju.errors import JujuAPIError
Adam Israelc3e6c2e2018-03-01 09:31:50 -050023
24# We might need this to connect to the websocket securely, but test and verify.
25try:
26 ssl._create_default_https_context = ssl._create_unverified_context
27except AttributeError:
28 # Legacy Python doesn't verify by default (see pep-0476)
29 # https://www.python.org/dev/peps/pep-0476/
30 pass
31
32
33# Custom exceptions
34class JujuCharmNotFound(Exception):
35 """The Charm can't be found or is not readable."""
36
37
38class JujuApplicationExists(Exception):
39 """The Application already exists."""
40
Adam Israelb5214512018-05-03 10:00:04 -040041
Adam Israel88a49632018-04-10 13:04:57 -060042class N2VCPrimitiveExecutionFailed(Exception):
43 """Something failed while attempting to execute a primitive."""
44
Adam Israelc3e6c2e2018-03-01 09:31:50 -050045
46# Quiet the debug logging
47logging.getLogger('websockets.protocol').setLevel(logging.INFO)
48logging.getLogger('juju.client.connection').setLevel(logging.WARN)
49logging.getLogger('juju.model').setLevel(logging.WARN)
50logging.getLogger('juju.machine').setLevel(logging.WARN)
51
Adam Israelb5214512018-05-03 10:00:04 -040052
Adam Israelc3e6c2e2018-03-01 09:31:50 -050053class VCAMonitor(ModelObserver):
54 """Monitor state changes within the Juju Model."""
Adam Israelc3e6c2e2018-03-01 09:31:50 -050055 log = None
56 ns_name = None
Adam Israel28a43c02018-04-23 16:04:54 -040057 applications = {}
Adam Israelc3e6c2e2018-03-01 09:31:50 -050058
Adam Israel28a43c02018-04-23 16:04:54 -040059 def __init__(self, ns_name):
Adam Israelc3e6c2e2018-03-01 09:31:50 -050060 self.log = logging.getLogger(__name__)
61
62 self.ns_name = ns_name
Adam Israel28a43c02018-04-23 16:04:54 -040063
64 def AddApplication(self, application_name, callback, *callback_args):
65 if application_name not in self.applications:
66 self.applications[application_name] = {
67 'callback': callback,
68 'callback_args': callback_args
69 }
70
71 def RemoveApplication(self, application_name):
72 if application_name in self.applications:
73 del self.applications[application_name]
Adam Israelc3e6c2e2018-03-01 09:31:50 -050074
75 async def on_change(self, delta, old, new, model):
76 """React to changes in the Juju model."""
77
78 if delta.entity == "unit":
Adam Israel28a43c02018-04-23 16:04:54 -040079 # Ignore change events from other applications
80 if delta.data['application'] not in self.applications.keys():
81 return
82
Adam Israelc3e6c2e2018-03-01 09:31:50 -050083 try:
Adam Israel28a43c02018-04-23 16:04:54 -040084
85 application_name = delta.data['application']
86
87 callback = self.applications[application_name]['callback']
Adam Israel5e08a0e2018-09-06 19:22:47 -040088 callback_args = \
89 self.applications[application_name]['callback_args']
Adam Israel28a43c02018-04-23 16:04:54 -040090
Adam Israelc3e6c2e2018-03-01 09:31:50 -050091 if old and new:
Adam Israelfc511ed2018-09-21 14:20:55 +020092 # Fire off a callback with the application state
93 if callback:
94 callback(
95 self.ns_name,
96 delta.data['application'],
97 new.workload_status,
98 new.workload_status_message,
99 *callback_args)
Adam Israel28a43c02018-04-23 16:04:54 -0400100
101 if old and not new:
102 # This is a charm being removed
103 if callback:
104 callback(
105 self.ns_name,
106 delta.data['application'],
107 "removed",
Adam Israel9562f432018-05-09 13:55:28 -0400108 "",
Adam Israel28a43c02018-04-23 16:04:54 -0400109 *callback_args)
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500110 except Exception as e:
Adam Israel5e08a0e2018-09-06 19:22:47 -0400111 self.log.debug("[1] notify_callback exception: {}".format(e))
112
Adam Israel88a49632018-04-10 13:04:57 -0600113 elif delta.entity == "action":
114 # TODO: Decide how we want to notify the user of actions
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500115
Adam Israel88a49632018-04-10 13:04:57 -0600116 # uuid = delta.data['id'] # The Action's unique id
117 # msg = delta.data['message'] # The output of the action
118 #
119 # if delta.data['status'] == "pending":
120 # # The action is queued
121 # pass
122 # elif delta.data['status'] == "completed""
123 # # The action was successful
124 # pass
125 # elif delta.data['status'] == "failed":
126 # # The action failed.
127 # pass
128
129 pass
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500130
131########
132# TODO
133#
134# Create unique models per network service
135# Document all public functions
136
Adam Israelb5214512018-05-03 10:00:04 -0400137
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500138class N2VC:
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500139 def __init__(self,
140 log=None,
141 server='127.0.0.1',
142 port=17070,
143 user='admin',
144 secret=None,
Adam Israel5e08a0e2018-09-06 19:22:47 -0400145 artifacts=None,
146 loop=None,
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500147 ):
148 """Initialize N2VC
149
150 :param vcaconfig dict A dictionary containing the VCA configuration
151
152 :param artifacts str The directory where charms required by a vnfd are
153 stored.
154
155 :Example:
156 n2vc = N2VC(vcaconfig={
157 'secret': 'MzI3MDJhOTYxYmM0YzRjNTJiYmY1Yzdm',
158 'user': 'admin',
159 'ip-address': '10.44.127.137',
160 'port': 17070,
161 'artifacts': '/path/to/charms'
162 })
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500163 """
164
Adam Israel5e08a0e2018-09-06 19:22:47 -0400165 # Initialize instance-level variables
166 self.api = None
167 self.log = None
168 self.controller = None
169 self.connecting = False
170 self.authenticated = False
171
Adam Israelfc511ed2018-09-21 14:20:55 +0200172 # For debugging
173 self.refcount = {
174 'controller': 0,
175 'model': 0,
176 }
177
Adam Israel5e08a0e2018-09-06 19:22:47 -0400178 self.models = {}
179 self.default_model = None
180
181 # Model Observers
182 self.monitors = {}
183
184 # VCA config
185 self.hostname = ""
186 self.port = 17070
187 self.username = ""
188 self.secret = ""
189
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500190 if log:
191 self.log = log
192 else:
193 self.log = logging.getLogger(__name__)
194
195 # Quiet websocket traffic
196 logging.getLogger('websockets.protocol').setLevel(logging.INFO)
197 logging.getLogger('juju.client.connection').setLevel(logging.WARN)
198 logging.getLogger('model').setLevel(logging.WARN)
199 # logging.getLogger('websockets.protocol').setLevel(logging.DEBUG)
200
201 self.log.debug('JujuApi: instantiated')
202
203 self.server = server
204 self.port = port
205
206 self.secret = secret
207 if user.startswith('user-'):
208 self.user = user
209 else:
210 self.user = 'user-{}'.format(user)
211
212 self.endpoint = '%s:%d' % (server, int(port))
213
214 self.artifacts = artifacts
215
Adam Israel5e08a0e2018-09-06 19:22:47 -0400216 self.loop = loop or asyncio.get_event_loop()
217
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500218 def __del__(self):
219 """Close any open connections."""
220 yield self.logout()
221
Adam Israel5e08a0e2018-09-06 19:22:47 -0400222 def notify_callback(self, model_name, application_name, status, message,
223 callback=None, *callback_args):
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500224 try:
225 if callback:
Adam Israel5e08a0e2018-09-06 19:22:47 -0400226 callback(
227 model_name,
228 application_name,
229 status, message,
230 *callback_args,
231 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500232 except Exception as e:
233 self.log.error("[0] notify_callback exception {}".format(e))
Adam Israel88a49632018-04-10 13:04:57 -0600234 raise e
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500235 return True
236
237 # Public methods
238 async def CreateNetworkService(self, nsd):
239 """Create a new model to encapsulate this network service.
240
241 Create a new model in the Juju controller to encapsulate the
242 charms associated with a network service.
243
244 You can pass either the nsd record or the id of the network
245 service, but this method will fail without one of them.
246 """
247 if not self.authenticated:
248 await self.login()
249
250 # Ideally, we will create a unique model per network service.
251 # This change will require all components, i.e., LCM and SO, to use
252 # N2VC for 100% compatibility. If we adopt unique models for the LCM,
253 # services deployed via LCM would't be manageable via SO and vice versa
254
255 return self.default_model
256
Adam Israel136186e2018-09-14 12:01:12 -0400257 async def Relate(self, ns_name, vnfd):
258 """Create a relation between the charm-enabled VDUs in a VNF.
259
260 The Relation mapping has two parts: the id of the vdu owning the endpoint, and the name of the endpoint.
261
262 vdu:
263 ...
264 relation:
265 - provides: dataVM:db
266 requires: mgmtVM:app
267
268 This tells N2VC that the charm referred to by the dataVM vdu offers a relation named 'db', and the mgmtVM vdu has an 'app' endpoint that should be connected to a database.
269
270 :param str ns_name: The name of the network service.
271 :param dict vnfd: The parsed yaml VNF descriptor.
272 """
273
274 # Currently, the call to Relate() is made automatically after the
275 # deployment of each charm; if the relation depends on a charm that
276 # hasn't been deployed yet, the call will fail silently. This will
277 # prevent an API breakage, with the intent of making this an explicitly
278 # required call in a more object-oriented refactor of the N2VC API.
279
280 configs = []
281 vnf_config = vnfd.get("vnf-configuration")
282 if vnf_config:
283 juju = vnf_config['juju']
284 if juju:
285 configs.append(vnf_config)
286
287 for vdu in vnfd['vdu']:
288 vdu_config = vdu.get('vdu-configuration')
289 if vdu_config:
290 juju = vdu_config['juju']
291 if juju:
292 configs.append(vdu_config)
293
294 def _get_application_name(name):
295 """Get the application name that's mapped to a vnf/vdu."""
296 vnf_member_index = 0
297 vnf_name = vnfd['name']
298
299 for vdu in vnfd.get('vdu'):
300 # Compare the named portion of the relation to the vdu's id
301 if vdu['id'] == name:
302 application_name = self.FormatApplicationName(
303 ns_name,
304 vnf_name,
305 str(vnf_member_index),
306 )
307 return application_name
308 else:
309 vnf_member_index += 1
310
311 return None
312
313 # Loop through relations
314 for cfg in configs:
315 if 'juju' in cfg:
316 if 'relation' in juju:
317 for rel in juju['relation']:
318 try:
319
320 # get the application name for the provides
321 (name, endpoint) = rel['provides'].split(':')
322 application_name = _get_application_name(name)
323
324 provides = "{}:{}".format(
325 application_name,
326 endpoint
327 )
328
329 # get the application name for thr requires
330 (name, endpoint) = rel['requires'].split(':')
331 application_name = _get_application_name(name)
332
333 requires = "{}:{}".format(
334 application_name,
335 endpoint
336 )
337 self.log.debug("Relation: {} <-> {}".format(
338 provides,
339 requires
340 ))
341 await self.add_relation(
342 ns_name,
343 provides,
344 requires,
345 )
346 except Exception as e:
347 self.log.debug("Exception: {}".format(e))
348
349 return
350
Adam Israel5e08a0e2018-09-06 19:22:47 -0400351 async def DeployCharms(self, model_name, application_name, vnfd,
352 charm_path, params={}, machine_spec={},
353 callback=None, *callback_args):
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500354 """Deploy one or more charms associated with a VNF.
355
356 Deploy the charm(s) referenced in a VNF Descriptor.
357
Adam Israelc9df96f2018-05-03 14:49:56 -0400358 :param str model_name: The name of the network service.
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500359 :param str application_name: The name of the application
360 :param dict vnfd: The name of the application
361 :param str charm_path: The path to the Juju charm
362 :param dict params: A dictionary of runtime parameters
363 Examples::
364 {
Adam Israel88a49632018-04-10 13:04:57 -0600365 'rw_mgmt_ip': '1.2.3.4',
366 # Pass the initial-config-primitives section of the vnf or vdu
367 'initial-config-primitives': {...}
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500368 }
Adam Israel5e08a0e2018-09-06 19:22:47 -0400369 :param dict machine_spec: A dictionary describing the machine to
370 install to
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500371 Examples::
372 {
373 'hostname': '1.2.3.4',
374 'username': 'ubuntu',
375 }
376 :param obj callback: A callback function to receive status changes.
Adam Israel5e08a0e2018-09-06 19:22:47 -0400377 :param tuple callback_args: A list of arguments to be passed to the
378 callback
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500379 """
380
381 ########################################################
382 # Verify the path to the charm exists and is readable. #
383 ########################################################
384 if not os.path.exists(charm_path):
385 self.log.debug("Charm path doesn't exist: {}".format(charm_path))
Adam Israel5e08a0e2018-09-06 19:22:47 -0400386 self.notify_callback(
387 model_name,
388 application_name,
389 "failed",
390 callback,
391 *callback_args,
392 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500393 raise JujuCharmNotFound("No artifacts configured.")
394
395 ################################
396 # Login to the Juju controller #
397 ################################
398 if not self.authenticated:
399 self.log.debug("Authenticating with Juju")
400 await self.login()
401
402 ##########################################
403 # Get the model for this network service #
404 ##########################################
405 # TODO: In a point release, we will use a model per deployed network
406 # service. In the meantime, we will always use the 'default' model.
407 model_name = 'default'
408 model = await self.get_model(model_name)
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500409
410 ########################################
411 # Verify the application doesn't exist #
412 ########################################
413 app = await self.get_application(model, application_name)
414 if app:
Adam Israel42d88e62018-07-16 14:18:41 -0400415 raise JujuApplicationExists("Can't deploy application \"{}\" to model \"{}\" because it already exists.".format(application_name, model_name))
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500416
Adam Israel28a43c02018-04-23 16:04:54 -0400417 ################################################################
418 # Register this application with the model-level event monitor #
419 ################################################################
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500420 if callback:
Adam Israel28a43c02018-04-23 16:04:54 -0400421 self.monitors[model_name].AddApplication(
422 application_name,
423 callback,
424 *callback_args
425 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500426
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500427 ########################################################
428 # Check for specific machine placement (native charms) #
429 ########################################################
430 to = ""
431 if machine_spec.keys():
Adam Israel5963cb42018-09-14 11:26:13 -0400432 if all(k in machine_spec for k in ['host', 'user']):
433 # Enlist an existing machine as a Juju unit
434 machine = await model.add_machine(spec='ssh:{}@{}:{}'.format(
435 machine_spec['user'],
436 machine_spec['host'],
437 self.GetPrivateKeyPath(),
438 ))
Adam Israelfa329072018-09-14 11:26:13 -0400439 to = machine.id
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500440
441 #######################################
442 # Get the initial charm configuration #
443 #######################################
444
445 rw_mgmt_ip = None
446 if 'rw_mgmt_ip' in params:
447 rw_mgmt_ip = params['rw_mgmt_ip']
448
Adam Israel5afe0542018-08-08 12:54:55 -0400449 if 'initial-config-primitive' not in params:
450 params['initial-config-primitive'] = {}
451
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500452 initial_config = self._get_config_from_dict(
Adam Israel88a49632018-04-10 13:04:57 -0600453 params['initial-config-primitive'],
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500454 {'<rw_mgmt_ip>': rw_mgmt_ip}
455 )
456
Adam Israel88a49632018-04-10 13:04:57 -0600457 self.log.debug("JujuApi: Deploying charm ({}) from {}".format(
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500458 application_name,
459 charm_path,
460 to=to,
461 ))
462
463 ########################################################
464 # Deploy the charm and apply the initial configuration #
465 ########################################################
466 app = await model.deploy(
Adam Israel88a49632018-04-10 13:04:57 -0600467 # We expect charm_path to be either the path to the charm on disk
468 # or in the format of cs:series/name
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500469 charm_path,
Adam Israel88a49632018-04-10 13:04:57 -0600470 # This is the formatted, unique name for this charm
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500471 application_name=application_name,
Adam Israel88a49632018-04-10 13:04:57 -0600472 # Proxy charms should use the current LTS. This will need to be
473 # changed for native charms.
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500474 series='xenial',
Adam Israel88a49632018-04-10 13:04:57 -0600475 # Apply the initial 'config' primitive during deployment
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500476 config=initial_config,
Adam Israelfa329072018-09-14 11:26:13 -0400477 # Where to deploy the charm to.
478 to=to,
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500479 )
480
Adam Israel136186e2018-09-14 12:01:12 -0400481 # Map the vdu id<->app name,
482 #
483 await self.Relate(model_name, vnfd)
484
Adam Israel88a49632018-04-10 13:04:57 -0600485 # #######################################
486 # # Execute initial config primitive(s) #
487 # #######################################
Adam Israelcf253202018-10-31 16:29:09 -0700488 uuids = await self.ExecuteInitialPrimitives(
Adam Israel5e08a0e2018-09-06 19:22:47 -0400489 model_name,
490 application_name,
491 params,
492 )
Adam Israelcf253202018-10-31 16:29:09 -0700493 return uuids
Adam Israel5e08a0e2018-09-06 19:22:47 -0400494
495 # primitives = {}
496 #
497 # # Build a sequential list of the primitives to execute
498 # for primitive in params['initial-config-primitive']:
499 # try:
500 # if primitive['name'] == 'config':
501 # # This is applied when the Application is deployed
502 # pass
503 # else:
504 # seq = primitive['seq']
505 #
506 # params = {}
507 # if 'parameter' in primitive:
508 # params = primitive['parameter']
509 #
510 # primitives[seq] = {
511 # 'name': primitive['name'],
512 # 'parameters': self._map_primitive_parameters(
513 # params,
514 # {'<rw_mgmt_ip>': rw_mgmt_ip}
515 # ),
516 # }
517 #
518 # for primitive in sorted(primitives):
519 # await self.ExecutePrimitive(
520 # model_name,
521 # application_name,
522 # primitives[primitive]['name'],
523 # callback,
524 # callback_args,
525 # **primitives[primitive]['parameters'],
526 # )
527 # except N2VCPrimitiveExecutionFailed as e:
528 # self.log.debug(
529 # "[N2VC] Exception executing primitive: {}".format(e)
530 # )
531 # raise
532
533 async def GetPrimitiveStatus(self, model_name, uuid):
534 """Get the status of an executed Primitive.
535
536 The status of an executed Primitive will be one of three values:
537 - completed
538 - failed
539 - running
540 """
541 status = None
542 try:
543 if not self.authenticated:
544 await self.login()
545
546 # FIXME: This is hard-coded until model-per-ns is added
547 model_name = 'default'
548
549 model = await self.get_model(model_name)
550
551 results = await model.get_action_status(uuid)
552
553 if uuid in results:
554 status = results[uuid]
555
556 except Exception as e:
557 self.log.debug(
558 "Caught exception while getting primitive status: {}".format(e)
559 )
560 raise N2VCPrimitiveExecutionFailed(e)
561
562 return status
563
564 async def GetPrimitiveOutput(self, model_name, uuid):
565 """Get the output of an executed Primitive.
566
567 Note: this only returns output for a successfully executed primitive.
568 """
569 results = None
570 try:
571 if not self.authenticated:
572 await self.login()
573
574 # FIXME: This is hard-coded until model-per-ns is added
575 model_name = 'default'
576
577 model = await self.get_model(model_name)
578 results = await model.get_action_output(uuid, 60)
579 except Exception as e:
580 self.log.debug(
581 "Caught exception while getting primitive status: {}".format(e)
582 )
583 raise N2VCPrimitiveExecutionFailed(e)
584
585 return results
586
Adam Israelfa329072018-09-14 11:26:13 -0400587 # async def ProvisionMachine(self, model_name, hostname, username):
588 # """Provision machine for usage with Juju.
589 #
590 # Provisions a previously instantiated machine for use with Juju.
591 # """
592 # try:
593 # if not self.authenticated:
594 # await self.login()
595 #
596 # # FIXME: This is hard-coded until model-per-ns is added
597 # model_name = 'default'
598 #
599 # model = await self.get_model(model_name)
600 # model.add_machine(spec={})
601 #
602 # machine = await model.add_machine(spec='ssh:{}@{}:{}'.format(
603 # "ubuntu",
604 # host['address'],
605 # private_key_path,
606 # ))
607 # return machine.id
608 #
609 # except Exception as e:
610 # self.log.debug(
611 # "Caught exception while getting primitive status: {}".format(e)
612 # )
613 # raise N2VCPrimitiveExecutionFailed(e)
614
615 def GetPrivateKeyPath(self):
616 homedir = os.environ['HOME']
617 sshdir = "{}/.ssh".format(homedir)
618 private_key_path = "{}/id_n2vc_rsa".format(sshdir)
619 return private_key_path
620
621 async def GetPublicKey(self):
622 """Get the N2VC SSH public key.abs
623
624 Returns the SSH public key, to be injected into virtual machines to
625 be managed by the VCA.
626
627 The first time this is run, a ssh keypair will be created. The public
628 key is injected into a VM so that we can provision the machine with
629 Juju, after which Juju will communicate with the VM directly via the
630 juju agent.
631 """
632 public_key = ""
633
634 # Find the path to where we expect our key to live.
635 homedir = os.environ['HOME']
636 sshdir = "{}/.ssh".format(homedir)
637 if not os.path.exists(sshdir):
638 os.mkdir(sshdir)
639
640 private_key_path = "{}/id_n2vc_rsa".format(sshdir)
641 public_key_path = "{}.pub".format(private_key_path)
642
643 # If we don't have a key generated, generate it.
644 if not os.path.exists(private_key_path):
645 cmd = "ssh-keygen -t {} -b {} -N '' -f {}".format(
646 "rsa",
647 "4096",
648 private_key_path
649 )
650 subprocess.check_output(shlex.split(cmd))
651
652 # Read the public key
653 with open(public_key_path, "r") as f:
654 public_key = f.readline()
655
656 return public_key
657
Adam Israel5e08a0e2018-09-06 19:22:47 -0400658 async def ExecuteInitialPrimitives(self, model_name, application_name,
659 params, callback=None, *callback_args):
660 """Execute multiple primitives.
661
662 Execute multiple primitives as declared in initial-config-primitive.
663 This is useful in cases where the primitives initially failed -- for
664 example, if the charm is a proxy but the proxy hasn't been configured
665 yet.
666 """
667 uuids = []
Adam Israel88a49632018-04-10 13:04:57 -0600668 primitives = {}
669
670 # Build a sequential list of the primitives to execute
671 for primitive in params['initial-config-primitive']:
672 try:
673 if primitive['name'] == 'config':
Adam Israel88a49632018-04-10 13:04:57 -0600674 pass
675 else:
Adam Israel88a49632018-04-10 13:04:57 -0600676 seq = primitive['seq']
677
Adam Israel42d88e62018-07-16 14:18:41 -0400678 params = {}
679 if 'parameter' in primitive:
680 params = primitive['parameter']
681
Adam Israel88a49632018-04-10 13:04:57 -0600682 primitives[seq] = {
683 'name': primitive['name'],
684 'parameters': self._map_primitive_parameters(
Adam Israel42d88e62018-07-16 14:18:41 -0400685 params,
Adam Israel5e08a0e2018-09-06 19:22:47 -0400686 {'<rw_mgmt_ip>': None}
Adam Israel88a49632018-04-10 13:04:57 -0600687 ),
688 }
689
690 for primitive in sorted(primitives):
Adam Israel5e08a0e2018-09-06 19:22:47 -0400691 uuids.append(
692 await self.ExecutePrimitive(
693 model_name,
694 application_name,
695 primitives[primitive]['name'],
696 callback,
697 callback_args,
698 **primitives[primitive]['parameters'],
699 )
Adam Israel88a49632018-04-10 13:04:57 -0600700 )
701 except N2VCPrimitiveExecutionFailed as e:
Adam Israel7d871fb2018-07-17 12:17:06 -0400702 self.log.debug(
Adam Israel88a49632018-04-10 13:04:57 -0600703 "[N2VC] Exception executing primitive: {}".format(e)
704 )
705 raise
Adam Israel5e08a0e2018-09-06 19:22:47 -0400706 return uuids
Adam Israel88a49632018-04-10 13:04:57 -0600707
Adam Israel5e08a0e2018-09-06 19:22:47 -0400708 async def ExecutePrimitive(self, model_name, application_name, primitive,
709 callback, *callback_args, **params):
Adam Israelc9df96f2018-05-03 14:49:56 -0400710 """Execute a primitive of a charm for Day 1 or Day 2 configuration.
Adam Israel6817f612018-04-13 08:41:43 -0600711
Adam Israelc9df96f2018-05-03 14:49:56 -0400712 Execute a primitive defined in the VNF descriptor.
713
714 :param str model_name: The name of the network service.
715 :param str application_name: The name of the application
716 :param str primitive: The name of the primitive to execute.
717 :param obj callback: A callback function to receive status changes.
Adam Israel5e08a0e2018-09-06 19:22:47 -0400718 :param tuple callback_args: A list of arguments to be passed to the
719 callback function.
720 :param dict params: A dictionary of key=value pairs representing the
721 primitive's parameters
Adam Israelc9df96f2018-05-03 14:49:56 -0400722 Examples::
723 {
724 'rw_mgmt_ip': '1.2.3.4',
725 # Pass the initial-config-primitives section of the vnf or vdu
726 'initial-config-primitives': {...}
727 }
Adam Israel6817f612018-04-13 08:41:43 -0600728 """
Adam Israel5e08a0e2018-09-06 19:22:47 -0400729 self.log.debug("Executing {}".format(primitive))
Adam Israel6817f612018-04-13 08:41:43 -0600730 uuid = None
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500731 try:
732 if not self.authenticated:
733 await self.login()
734
735 # FIXME: This is hard-coded until model-per-ns is added
736 model_name = 'default'
737
Adam Israel5e08a0e2018-09-06 19:22:47 -0400738 model = await self.get_model(model_name)
Adam Israelb5214512018-05-03 10:00:04 -0400739
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500740 if primitive == 'config':
741 # config is special, and expecting params to be a dictionary
Adam Israelb0943662018-08-02 15:32:00 -0400742 await self.set_config(
743 model,
744 application_name,
745 params['params'],
746 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500747 else:
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500748 app = await self.get_application(model, application_name)
749 if app:
750 # Run against the first (and probably only) unit in the app
751 unit = app.units[0]
752 if unit:
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500753 action = await unit.run_action(primitive, **params)
Adam Israel6817f612018-04-13 08:41:43 -0600754 uuid = action.id
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500755 except Exception as e:
Adam Israelb0943662018-08-02 15:32:00 -0400756 self.log.debug(
757 "Caught exception while executing primitive: {}".format(e)
758 )
Adam Israel7d871fb2018-07-17 12:17:06 -0400759 raise N2VCPrimitiveExecutionFailed(e)
Adam Israel6817f612018-04-13 08:41:43 -0600760 return uuid
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500761
Adam Israel5e08a0e2018-09-06 19:22:47 -0400762 async def RemoveCharms(self, model_name, application_name, callback=None,
763 *callback_args):
Adam Israelc9df96f2018-05-03 14:49:56 -0400764 """Remove a charm from the VCA.
765
766 Remove a charm referenced in a VNF Descriptor.
767
768 :param str model_name: The name of the network service.
769 :param str application_name: The name of the application
770 :param obj callback: A callback function to receive status changes.
Adam Israel5e08a0e2018-09-06 19:22:47 -0400771 :param tuple callback_args: A list of arguments to be passed to the
772 callback function.
Adam Israelc9df96f2018-05-03 14:49:56 -0400773 """
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500774 try:
775 if not self.authenticated:
776 await self.login()
777
778 model = await self.get_model(model_name)
779 app = await self.get_application(model, application_name)
780 if app:
Adam Israel28a43c02018-04-23 16:04:54 -0400781 # Remove this application from event monitoring
782 self.monitors[model_name].RemoveApplication(application_name)
783
784 # self.notify_callback(model_name, application_name, "removing", callback, *callback_args)
Adam Israel5e08a0e2018-09-06 19:22:47 -0400785 self.log.debug(
786 "Removing the application {}".format(application_name)
787 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500788 await app.remove()
Adam Israel28a43c02018-04-23 16:04:54 -0400789
790 # Notify the callback that this charm has been removed.
Adam Israel5e08a0e2018-09-06 19:22:47 -0400791 self.notify_callback(
792 model_name,
793 application_name,
794 "removed",
795 callback,
796 *callback_args,
797 )
Adam Israel28a43c02018-04-23 16:04:54 -0400798
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500799 except Exception as e:
800 print("Caught exception: {}".format(e))
Adam Israel88a49632018-04-10 13:04:57 -0600801 self.log.debug(e)
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500802 raise e
803
804 async def DestroyNetworkService(self, nsd):
805 raise NotImplementedError()
806
Adam Israelb5214512018-05-03 10:00:04 -0400807 async def GetMetrics(self, model_name, application_name):
808 """Get the metrics collected by the VCA.
809
810 :param model_name The name of the model
811 :param application_name The name of the application
812 """
813 metrics = {}
814 model = await self.get_model(model_name)
815 app = await self.get_application(model, application_name)
816 if app:
817 metrics = await app.get_metrics()
818
819 return metrics
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500820
Adam Israelfa329072018-09-14 11:26:13 -0400821 async def HasApplication(self, model_name, application_name):
822 model = await self.get_model(model_name)
823 app = await self.get_application(model, application_name)
824 if app:
825 return True
826 return False
827
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500828 # Non-public methods
Adam Israel136186e2018-09-14 12:01:12 -0400829 async def add_relation(self, model_name, relation1, relation2):
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500830 """
831 Add a relation between two application endpoints.
832
Adam Israel136186e2018-09-14 12:01:12 -0400833 :param str model_name Name of the network service.
834 :param str relation1 '<application>[:<relation_name>]'
835 :param str relation12 '<application>[:<relation_name>]'
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500836 """
Adam Israel136186e2018-09-14 12:01:12 -0400837
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500838 if not self.authenticated:
839 await self.login()
840
Adam Israel136186e2018-09-14 12:01:12 -0400841 m = await self.get_model(model_name)
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500842 try:
Adam Israel136186e2018-09-14 12:01:12 -0400843 await m.add_relation(relation1, relation2)
844 except JujuAPIError as e:
845 # If one of the applications in the relationship doesn't exist,
846 # or the relation has already been added, let the operation fail
847 # silently.
848 if 'not found' in e.message:
849 return
850 if 'already exists' in e.message:
851 return
852
853 raise e
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500854
Adam Israelb5214512018-05-03 10:00:04 -0400855 # async def apply_config(self, config, application):
856 # """Apply a configuration to the application."""
857 # print("JujuApi: Applying configuration to {}.".format(
858 # application
859 # ))
860 # return await self.set_config(application=application, config=config)
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500861
862 def _get_config_from_dict(self, config_primitive, values):
Adam Israel88a49632018-04-10 13:04:57 -0600863 """Transform the yang config primitive to dict.
864
865 Expected result:
866
867 config = {
868 'config':
869 }
870 """
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500871 config = {}
872 for primitive in config_primitive:
873 if primitive['name'] == 'config':
Adam Israel88a49632018-04-10 13:04:57 -0600874 # config = self._map_primitive_parameters()
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500875 for parameter in primitive['parameter']:
876 param = str(parameter['name'])
877 if parameter['value'] == "<rw_mgmt_ip>":
878 config[param] = str(values[parameter['value']])
879 else:
880 config[param] = str(parameter['value'])
881
882 return config
883
Adam Israel88a49632018-04-10 13:04:57 -0600884 def _map_primitive_parameters(self, parameters, values):
885 params = {}
886 for parameter in parameters:
887 param = str(parameter['name'])
tierno40047482018-10-26 14:54:26 +0200888 value = None
Adam Israel5e08a0e2018-09-06 19:22:47 -0400889
890 # Typecast parameter value, if present
891 if 'data-type' in parameter:
892 paramtype = str(parameter['data-type']).lower()
Adam Israel5e08a0e2018-09-06 19:22:47 -0400893
894 if paramtype == "integer":
895 value = int(parameter['value'])
896 elif paramtype == "boolean":
897 value = bool(parameter['value'])
898 else:
899 value = str(parameter['value'])
900
Adam Israel88a49632018-04-10 13:04:57 -0600901 if parameter['value'] == "<rw_mgmt_ip>":
902 params[param] = str(values[parameter['value']])
903 else:
Adam Israel5e08a0e2018-09-06 19:22:47 -0400904 params[param] = value
Adam Israel88a49632018-04-10 13:04:57 -0600905 return params
906
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500907 def _get_config_from_yang(self, config_primitive, values):
908 """Transform the yang config primitive to dict."""
909 config = {}
910 for primitive in config_primitive.values():
911 if primitive['name'] == 'config':
912 for parameter in primitive['parameter'].values():
913 param = str(parameter['name'])
914 if parameter['value'] == "<rw_mgmt_ip>":
915 config[param] = str(values[parameter['value']])
916 else:
917 config[param] = str(parameter['value'])
918
919 return config
920
921 def FormatApplicationName(self, *args):
922 """
923 Generate a Juju-compatible Application name
924
925 :param args tuple: Positional arguments to be used to construct the
926 application name.
927
928 Limitations::
929 - Only accepts characters a-z and non-consequitive dashes (-)
930 - Application name should not exceed 50 characters
931
932 Examples::
933
934 FormatApplicationName("ping_pong_ns", "ping_vnf", "a")
935 """
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500936 appname = ""
937 for c in "-".join(list(args)):
938 if c.isdigit():
939 c = chr(97 + int(c))
940 elif not c.isalpha():
941 c = "-"
942 appname += c
943 return re.sub('\-+', '-', appname.lower())
944
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500945 # def format_application_name(self, nsd_name, vnfr_name, member_vnf_index=0):
946 # """Format the name of the application
947 #
948 # Limitations:
949 # - Only accepts characters a-z and non-consequitive dashes (-)
950 # - Application name should not exceed 50 characters
951 # """
952 # name = "{}-{}-{}".format(nsd_name, vnfr_name, member_vnf_index)
953 # new_name = ''
954 # for c in name:
955 # if c.isdigit():
956 # c = chr(97 + int(c))
957 # elif not c.isalpha():
958 # c = "-"
959 # new_name += c
960 # return re.sub('\-+', '-', new_name.lower())
961
962 def format_model_name(self, name):
963 """Format the name of model.
964
965 Model names may only contain lowercase letters, digits and hyphens
966 """
967
968 return name.replace('_', '-').lower()
969
970 async def get_application(self, model, application):
971 """Get the deployed application."""
972 if not self.authenticated:
973 await self.login()
974
975 app = None
976 if application and model:
977 if model.applications:
978 if application in model.applications:
979 app = model.applications[application]
980
981 return app
982
983 async def get_model(self, model_name='default'):
984 """Get a model from the Juju Controller.
985
986 Note: Model objects returned must call disconnected() before it goes
987 out of scope."""
988 if not self.authenticated:
989 await self.login()
990
991 if model_name not in self.models:
Adam Israel5e08a0e2018-09-06 19:22:47 -0400992 self.models[model_name] = await self.controller.get_model(
993 model_name,
994 )
Adam Israelfc511ed2018-09-21 14:20:55 +0200995 self.refcount['model'] += 1
Adam Israelc3e6c2e2018-03-01 09:31:50 -0500996
Adam Israel28a43c02018-04-23 16:04:54 -0400997 # Create an observer for this model
998 self.monitors[model_name] = VCAMonitor(model_name)
999 self.models[model_name].add_observer(self.monitors[model_name])
1000
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001001 return self.models[model_name]
1002
1003 async def login(self):
1004 """Login to the Juju controller."""
1005
1006 if self.authenticated:
1007 return
1008
1009 self.connecting = True
1010
1011 self.log.debug("JujuApi: Logging into controller")
1012
1013 cacert = None
Adam Israel5e08a0e2018-09-06 19:22:47 -04001014 self.controller = Controller(loop=self.loop)
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001015
1016 if self.secret:
Adam Israel5e08a0e2018-09-06 19:22:47 -04001017 self.log.debug(
1018 "Connecting to controller... ws://{}:{} as {}/{}".format(
1019 self.endpoint,
1020 self.port,
1021 self.user,
1022 self.secret,
1023 )
1024 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001025 await self.controller.connect(
1026 endpoint=self.endpoint,
1027 username=self.user,
1028 password=self.secret,
1029 cacert=cacert,
1030 )
Adam Israelfc511ed2018-09-21 14:20:55 +02001031 self.refcount['controller'] += 1
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001032 else:
1033 # current_controller no longer exists
1034 # self.log.debug("Connecting to current controller...")
1035 # await self.controller.connect_current()
Adam Israel88a49632018-04-10 13:04:57 -06001036 # await self.controller.connect(
1037 # endpoint=self.endpoint,
1038 # username=self.user,
1039 # cacert=cacert,
1040 # )
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001041 self.log.fatal("VCA credentials not configured.")
1042
1043 self.authenticated = True
1044 self.log.debug("JujuApi: Logged into controller")
1045
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001046 async def logout(self):
1047 """Logout of the Juju controller."""
1048 if not self.authenticated:
1049 return
1050
1051 try:
1052 if self.default_model:
Adam Israel5e08a0e2018-09-06 19:22:47 -04001053 self.log.debug("Disconnecting model {}".format(
1054 self.default_model
1055 ))
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001056 await self.default_model.disconnect()
Adam Israelfc511ed2018-09-21 14:20:55 +02001057 self.refcount['model'] -= 1
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001058 self.default_model = None
1059
1060 for model in self.models:
1061 await self.models[model].disconnect()
Adam Israelfc511ed2018-09-21 14:20:55 +02001062 self.refcount['model'] -= 1
1063 self.models[model] = None
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001064
1065 if self.controller:
Adam Israel5e08a0e2018-09-06 19:22:47 -04001066 self.log.debug("Disconnecting controller {}".format(
1067 self.controller
1068 ))
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001069 await self.controller.disconnect()
Adam Israelfc511ed2018-09-21 14:20:55 +02001070 self.refcount['controller'] -= 1
Adam Israel5e08a0e2018-09-06 19:22:47 -04001071 self.controller = None
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001072
1073 self.authenticated = False
Adam Israelfc511ed2018-09-21 14:20:55 +02001074
1075 self.log.debug(self.refcount)
1076
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001077 except Exception as e:
Adam Israel5e08a0e2018-09-06 19:22:47 -04001078 self.log.fatal(
1079 "Fatal error logging out of Juju Controller: {}".format(e)
1080 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001081 raise e
1082
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001083 # async def remove_application(self, name):
1084 # """Remove the application."""
1085 # if not self.authenticated:
1086 # await self.login()
1087 #
1088 # app = await self.get_application(name)
1089 # if app:
1090 # self.log.debug("JujuApi: Destroying application {}".format(
1091 # name,
1092 # ))
1093 #
1094 # await app.destroy()
1095
1096 async def remove_relation(self, a, b):
1097 """
1098 Remove a relation between two application endpoints
1099
1100 :param a An application endpoint
1101 :param b An application endpoint
1102 """
1103 if not self.authenticated:
1104 await self.login()
1105
1106 m = await self.get_model()
1107 try:
1108 m.remove_relation(a, b)
1109 finally:
1110 await m.disconnect()
1111
1112 async def resolve_error(self, application=None):
1113 """Resolve units in error state."""
1114 if not self.authenticated:
1115 await self.login()
1116
1117 app = await self.get_application(self.default_model, application)
1118 if app:
Adam Israel5e08a0e2018-09-06 19:22:47 -04001119 self.log.debug(
1120 "JujuApi: Resolving errors for application {}".format(
1121 application,
1122 )
1123 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001124
1125 for unit in app.units:
1126 app.resolved(retry=True)
1127
1128 async def run_action(self, application, action_name, **params):
1129 """Execute an action and return an Action object."""
1130 if not self.authenticated:
1131 await self.login()
1132 result = {
1133 'status': '',
1134 'action': {
1135 'tag': None,
1136 'results': None,
1137 }
1138 }
1139 app = await self.get_application(self.default_model, application)
1140 if app:
1141 # We currently only have one unit per application
1142 # so use the first unit available.
1143 unit = app.units[0]
1144
Adam Israel5e08a0e2018-09-06 19:22:47 -04001145 self.log.debug(
1146 "JujuApi: Running Action {} against Application {}".format(
1147 action_name,
1148 application,
1149 )
1150 )
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001151
1152 action = await unit.run_action(action_name, **params)
1153
1154 # Wait for the action to complete
1155 await action.wait()
1156
1157 result['status'] = action.status
1158 result['action']['tag'] = action.data['id']
1159 result['action']['results'] = action.results
1160
1161 return result
1162
Adam Israelb5214512018-05-03 10:00:04 -04001163 async def set_config(self, model_name, application, config):
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001164 """Apply a configuration to the application."""
1165 if not self.authenticated:
1166 await self.login()
1167
Adam Israelb5214512018-05-03 10:00:04 -04001168 app = await self.get_application(model_name, application)
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001169 if app:
1170 self.log.debug("JujuApi: Setting config for Application {}".format(
1171 application,
1172 ))
1173 await app.set_config(config)
1174
1175 # Verify the config is set
1176 newconf = await app.get_config()
1177 for key in config:
1178 if config[key] != newconf[key]['value']:
1179 self.log.debug("JujuApi: Config not set! Key {} Value {} doesn't match {}".format(key, config[key], newconf[key]))
1180
Adam Israelb5214512018-05-03 10:00:04 -04001181 # async def set_parameter(self, parameter, value, application=None):
1182 # """Set a config parameter for a service."""
1183 # if not self.authenticated:
1184 # await self.login()
1185 #
1186 # self.log.debug("JujuApi: Setting {}={} for Application {}".format(
1187 # parameter,
1188 # value,
1189 # application,
1190 # ))
1191 # return await self.apply_config(
1192 # {parameter: value},
1193 # application=application,
1194 # )
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001195
Adam Israel5e08a0e2018-09-06 19:22:47 -04001196 async def wait_for_application(self, model_name, application_name,
1197 timeout=300):
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001198 """Wait for an application to become active."""
1199 if not self.authenticated:
1200 await self.login()
1201
Adam Israel5e08a0e2018-09-06 19:22:47 -04001202 # TODO: In a point release, we will use a model per deployed network
1203 # service. In the meantime, we will always use the 'default' model.
1204 model_name = 'default'
1205 model = await self.get_model(model_name)
1206
1207 app = await self.get_application(model, application_name)
1208 self.log.debug("Application: {}".format(app))
1209 # app = await self.get_application(model_name, application_name)
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001210 if app:
1211 self.log.debug(
1212 "JujuApi: Waiting {} seconds for Application {}".format(
1213 timeout,
Adam Israel5e08a0e2018-09-06 19:22:47 -04001214 application_name,
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001215 )
1216 )
1217
Adam Israel5e08a0e2018-09-06 19:22:47 -04001218 await model.block_until(
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001219 lambda: all(
Adam Israel5e08a0e2018-09-06 19:22:47 -04001220 unit.agent_status == 'idle' and unit.workload_status in
1221 ['active', 'unknown'] for unit in app.units
Adam Israelc3e6c2e2018-03-01 09:31:50 -05001222 ),
1223 timeout=timeout
1224 )