diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-02-17 00:16:26 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-02-17 00:16:26 +0000 |
| commit | 844035b6c0f725c685cdff56a7bb77efe7825a5f (patch) | |
| tree | 8fc52730c5dcaefc25b97f1868a71a0db2bd1462 /nova/virt | |
| parent | 7162ee5077f73f35be1488c413ae485897fc68e7 (diff) | |
| parent | 00c77e0e9af6ae16484e4bee5f33de1eeb812227 (diff) | |
Merge "bug 931604: improve how xenapi RRD records are retrieved"
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi/vm_utils.py | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 24584d5e4..dc9340e6b 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -28,6 +28,7 @@ import re import tempfile import time import urllib +import urlparse import uuid from decimal import Decimal, InvalidOperation from xml.dom import minidom @@ -1035,14 +1036,8 @@ class VMHelper(HelperBase): def compile_diagnostics(cls, session, record): """Compile VM diagnostics data""" try: - host = session.get_xenapi_host() - host_ip = session.call_xenapi("host.get_record", host)["address"] - except (cls.XenAPI.Failure, KeyError) as e: - return {"Unable to retrieve diagnostics": e} - - try: diags = {} - xml = get_rrd(host_ip, record["uuid"]) + xml = get_rrd(get_rrd_server(), record["uuid"]) if xml: rrd = minidom.parseString(xml) for i, node in enumerate(rrd.firstChild.childNodes): @@ -1062,13 +1057,8 @@ class VMHelper(HelperBase): """Compile bandwidth usage, cpu, and disk metrics for all VMs on this host""" start_time = int(start_time) - try: - host = session.get_xenapi_host() - host_ip = session.call_xenapi("host.get_record", host)["address"] - except (cls.XenAPI.Failure, KeyError) as e: - raise exception.CouldNotFetchMetrics() - xml = get_rrd_updates(host_ip, start_time) + xml = get_rrd_updates(get_rrd_server(), start_time) if xml: doc = minidom.parseString(xml) return parse_rrd_update(doc, start_time, stop_time) @@ -1177,29 +1167,41 @@ class VMHelper(HelperBase): return None -def get_rrd(host, vm_uuid): +def get_rrd_server(): + """Return server's scheme and address to use for retrieving RRD XMLs.""" + xs_url = urlparse.urlparse(FLAGS.xenapi_connection_url) + return [xs_url.scheme, xs_url.netloc] + + +def get_rrd(server, vm_uuid): """Return the VM RRD XML as a string""" try: - xml = urllib.urlopen("http://%s:%s@%s/vm_rrd?uuid=%s" % ( + xml = urllib.urlopen("%s://%s:%s@%s/vm_rrd?uuid=%s" % ( + server[0], FLAGS.xenapi_connection_username, FLAGS.xenapi_connection_password, - host, + server[1], vm_uuid)) return xml.read() except IOError: + LOG.exception(_('Unable to obtain RRD XML for VM %(vm_uuid)s with ' + 'server details: %(server)s.') % locals()) return None -def get_rrd_updates(host, start_time): +def get_rrd_updates(server, start_time): """Return the RRD updates XML as a string""" try: - xml = urllib.urlopen("http://%s:%s@%s/rrd_updates?start=%s" % ( + xml = urllib.urlopen("%s://%s:%s@%s/rrd_updates?start=%s" % ( + server[0], FLAGS.xenapi_connection_username, FLAGS.xenapi_connection_password, - host, + server[1], start_time)) return xml.read() except IOError: + LOG.exception(_('Unable to obtain RRD XML updates with ' + 'server details: %(server)s.') % locals()) return None |
