diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-07-12 10:46:12 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-07-12 10:46:12 +0000 |
| commit | c2d33008f040fae7971646ad01a5d4e48a79c480 (patch) | |
| tree | 60e8deb358a0e6b8759a0c2b2294813f0390dbd0 /nova/virt | |
| parent | 7d00b664a4d74333f7cd9736ce6bb613ccddc814 (diff) | |
| parent | ad54ed53cf6a475ad0f8042f8b95454a8c0b35a4 (diff) | |
Merge "Adds diagnostics command for the libvirt driver."
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/libvirt/driver.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 0f62a9c52..94564a622 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -5,6 +5,7 @@ # All Rights Reserved. # Copyright (c) 2010 Citrix Systems, Inc. # Copyright (c) 2011 Piston Cloud Computing, Inc +# Copyright (c) 2012 University Of Minho # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -2723,6 +2724,80 @@ class LibvirtDriver(driver.ComputeDriver): """Confirms a resize, destroying the source VM""" self._cleanup_resize(instance) + def get_diagnostics(self, instance): + def get_io_devices(xml_doc): + """ get the list of io devices from the + xml document.""" + result = {"volumes": [], "ifaces": []} + try: + doc = etree.fromstring(xml_doc) + except Exception: + return result + blocks = [('./devices/disk', 'volumes'), + ('./devices/interface', 'ifaces')] + for block, key in blocks: + section = doc.findall(block) + for node in section: + for child in node.getchildren(): + if child.tag == 'target' and child.get('dev'): + result[key].append(child.get('dev')) + return result + + domain = self._lookup_by_name(instance['name']) + output = {} + # get cpu time, might launch an exception if the method + # is not supported by the underlying hypervisor being + # used by libvirt + try: + cputime = domain.vcpus()[0] + for i in range(len(cputime)): + output["cpu" + str(i) + "_time"] = cputime[i][2] + except libvirt.libvirtError: + pass + # get io status + xml = domain.XMLDesc(0) + dom_io = get_io_devices(xml) + for disk in dom_io["volumes"]: + try: + # blockStats might launch an exception if the method + # is not supported by the underlying hypervisor being + # used by libvirt + stats = domain.blockStats(disk) + output[disk + "_read_req"] = stats[0] + output[disk + "_read"] = stats[1] + output[disk + "_write_req"] = stats[2] + output[disk + "_write"] = stats[3] + output[disk + "_errors"] = stats[4] + except libvirt.libvirtError: + pass + for interface in dom_io["ifaces"]: + try: + # interfaceStats might launch an exception if the method + # is not supported by the underlying hypervisor being + # used by libvirt + stats = domain.interfaceStats(interface) + output[interface + "_rx"] = stats[0] + output[interface + "_rx_packets"] = stats[1] + output[interface + "_rx_errors"] = stats[2] + output[interface + "_rx_drop"] = stats[3] + output[interface + "_tx"] = stats[4] + output[interface + "_tx_packets"] = stats[5] + output[interface + "_tx_errors"] = stats[6] + output[interface + "_tx_drop"] = stats[7] + except libvirt.libvirtError: + pass + output["memory"] = domain.maxMemory() + # memoryStats might launch an exception if the method + # is not supported by the underlying hypervisor being + # used by libvirt + try: + mem = domain.memoryStats() + for key in mem.keys(): + output["memory-" + key] = mem[key] + except libvirt.libvirtError: + pass + return output + class HostState(object): """Manages information about the compute node through libvirt""" |
