diff options
| author | John Garbutt <john@johngarbutt.com> | 2013-05-23 17:42:51 +0100 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-06-12 14:39:49 +0000 |
| commit | 6e93fefade26ddb6282e423af51f806a08efc8b0 (patch) | |
| tree | 1874de5751cc12efc0d72e3cecf8fceddb833d39 /nova/virt | |
| parent | 4461f20bd6187ec02e00cd862d754df38523f9ef (diff) | |
xenapi: implement get_console_output for XCP/XenServer
If an administrator has enabled the logging of guest
consoles on XCP/XenServer, this enables nova to return
the last MB of those logs to the user.
The management of the logs on the server is a little
tricky, and will be sorted in a later patch.
Change was based on this previous idea:
https://review.openstack.org/#/c/17959/
DocImpact
Part of blueprint xenapi-server-log
Change-Id: I23c83bcf8c648cc2714a0c78951acc29a16d5c31
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi/fake.py | 8 | ||||
| -rw-r--r-- | nova/virt/xenapi/vmops.py | 26 |
2 files changed, 28 insertions, 6 deletions
diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py index 69b0c2010..379671370 100644 --- a/nova/virt/xenapi/fake.py +++ b/nova/virt/xenapi/fake.py @@ -50,10 +50,12 @@ A fake XenAPI SDK. """ +import base64 import pickle import random import uuid from xml.sax import saxutils +import zlib import pprint @@ -608,6 +610,12 @@ class SessionBase(object): def _plugin_xenhost_host_uptime(self, method, args): return jsonutils.dumps({"uptime": "fake uptime"}) + def _plugin_console_get_console_log(self, method, args): + dom_id = args["dom_id"] + if dom_id == 0: + raise Failure('Guest does not have a console') + return base64.b64encode(zlib.compress("dom_id: %s" % dom_id)) + def host_call_plugin(self, _1, _2, plugin, method, args): func = getattr(self, '_plugin_%s_%s' % (plugin, method), None) if not func: diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 56a4b18d8..bf8aa3e52 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -19,9 +19,11 @@ Management class for VM-related functions (spawn, reboot, etc). """ +import base64 import functools import itertools import time +import zlib from eventlet import greenthread import netaddr @@ -1421,9 +1423,18 @@ class VMOps(object): return bw def get_console_output(self, instance): - """Return snapshot of console.""" - # TODO(armando-migliaccio): implement this to fix pylint! - return 'FAKE CONSOLE OUTPUT of instance' + """Return last few lines of instance console.""" + dom_id = self._get_dom_id(instance, check_rescue=True) + + try: + raw_console_data = self._session.call_plugin('console', + 'get_console_log', {'dom_id': dom_id}) + except self._session.XenAPI.Failure as exc: + LOG.exception(exc) + msg = _("Guest does not have a console available") + raise exception.NovaException(msg) + + return zlib.decompress(base64.b64decode(raw_console_data)) def get_vnc_console(self, instance): """Return connection info for a vnc console.""" @@ -1607,9 +1618,7 @@ class VMOps(object): """ args = {} if instance or vm_ref: - vm_ref = vm_ref or self._get_vm_opaque_ref(instance) - vm_rec = self._session.call_xenapi("VM.get_record", vm_ref) - args['dom_id'] = vm_rec['domid'] + args['dom_id'] = self._get_dom_id(instance, vm_ref) args.update(addl_args) try: return self._session.call_plugin(plugin, method, args) @@ -1630,6 +1639,11 @@ class VMOps(object): return {'returncode': 'error', 'message': err_msg} return None + def _get_dom_id(self, instance=None, vm_ref=None, check_rescue=False): + vm_ref = vm_ref or self._get_vm_opaque_ref(instance, check_rescue) + vm_rec = self._session.call_xenapi("VM.get_record", vm_ref) + return vm_rec['domid'] + def _add_to_param_xenstore(self, vm_ref, key, val): """ Takes a key/value pair and adds it to the xenstore parameter |
