211
212
action_id = self._do_action("resume", unit.info["unit_name"])
212
213
return self._fetch_action(action_id)
215
def bootstrap_landscape(self, admin_name, admin_email, admin_password,
217
"""Execute the 'bootstrap' action on a Landscape unit.
219
The results of the action is returned.
221
unit = self._get_service_unit("landscape-server", unit=unit)
222
bootstrap_params = {"admin-name": admin_name,
223
"admin-email": admin_email,
224
"admin-password": admin_password}
225
action_id = self._do_action(
226
"bootstrap", unit.info["unit_name"], bootstrap_params)
227
return self._fetch_action(action_id)
214
229
def wait_landscape_cron_jobs(self, unit=None):
215
230
"""Wait for running cron jobs to finish on the given Landscape unit."""
216
231
unit = self._get_service_unit("landscape-server", unit=unit)
355
370
stdout, stderr = process.communicate()
356
371
return stdout.decode("utf-8"), stderr.decode("utf-8")
358
def _do_action(self, action, unit):
373
def _do_action(self, action, unit, action_params=None):
359
374
"""Execute an action on a unit, returning the id."""
360
result = json.loads(subprocess.check_output(
361
["juju", "action", "do", "--format=json",
362
unit, action]).decode("utf-8"))
375
command = ["juju", "action", "do", "--format=json", unit, action]
376
if action_params is not None:
377
sorted_action_params = sorted(
378
action_params.items(), key=itemgetter(0))
379
for key, value in sorted_action_params:
380
if value is not None:
381
command.append("%s=%s" % (key, value))
383
self._subprocess.check_output(command).decode("utf-8"))
363
384
return result["Action queued with id"]
365
386
def _fetch_action(self, action_id, wait=300):
366
387
"""Fetch the results of an action."""
367
return json.loads(subprocess.check_output(
388
return json.loads(self._subprocess.check_output(
368
389
["juju", "action", "fetch", "--format=json", "--wait", str(wait),
369
390
action_id]).decode("utf-8"))