diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-03-12 22:03:36 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-03-12 22:03:36 +0000 |
| commit | 7b749644c924f71c1030bfcbbd0ebb52d1e77fd3 (patch) | |
| tree | f3461260469122c06f06707d15012fb22f3150cb | |
| parent | d15fbe92e7d0cf7df72fa9c3cf21d31bd9d49df0 (diff) | |
| parent | 625c5e45db62c59691b16fadde464a192af3ac3f (diff) | |
| download | nova-7b749644c924f71c1030bfcbbd0ebb52d1e77fd3.tar.gz nova-7b749644c924f71c1030bfcbbd0ebb52d1e77fd3.tar.xz nova-7b749644c924f71c1030bfcbbd0ebb52d1e77fd3.zip | |
Merge "Fix libvirt get_console_output for Python < 2.7"
| -rw-r--r-- | nova/virt/libvirt/connection.py | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 9be1f9c62..8fd00457c 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -908,18 +908,39 @@ class LibvirtConnection(driver.ComputeDriver): xml = virt_dom.XMLDesc(0) tree = ElementTree.fromstring(xml) + console_types = {} + + # NOTE(comstud): We want to try 'file' types first, then try 'pty' + # types. We can't use Python 2.7 syntax of: + # tree.find("./devices/console[@type='file']/source") + # because we need to support 2.6. + console_nodes = tree.findall('./devices/console') + for console_node in console_nodes: + console_type = console_node.get('type') + console_types.setdefault(console_type, []) + console_types[console_type].append(console_node) + # If the guest has a console logging to a file prefer to use that - node = tree.find("./devices/console[@type='file']/source") - if node is not None: - fpath = node.get("path") - return libvirt_utils.load_file(fpath) - - # else if there is a PTY, then try to read latest data from that - node = tree.find("./devices/console[@type='pty']/source") - if node is None: - raise exception.Error(_("Guest does not have a console available")) + for file_console in console_types.get('file'): + source_node = file_console.find('./source') + if source_node is None: + continue + path = source_node.get("path") + if not path: + continue + return libvirt_utils.load_file(path) - pty = node.get("path") + # Try 'pty' types + for pty_console in console_types.get('pty'): + source_node = pty_console.find('./source') + if source_node is None: + continue + pty = source_node.get("path") + if not pty: + continue + break + else: + raise exception.Error(_("Guest does not have a console available")) console_log = os.path.join(FLAGS.instances_path, instance['name'], 'console.log') |
