From 00c77e0e9af6ae16484e4bee5f33de1eeb812227 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Mon, 13 Feb 2012 18:46:57 +0000 Subject: bug 931604: improve how xenapi RRD records are retrieved switch to using FLAGS.xenapi_connection_url to obtain scheme and address to talk to in order to fetch RRD XMLs. See bug report for more info. Change-Id: Iad6520cdb15f32e9e50ab0d42026282e57aaa30d --- nova/tests/test_xenapi.py | 6 ++++++ nova/virt/xenapi/vm_utils.py | 40 +++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 6fc7fdf7d..9423c3f1f 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -236,6 +236,12 @@ class XenAPIVMTestCase(test.TestCase): instances = self.conn.list_instances() self.assertEquals(instances, []) + def test_get_rrd_server(self): + self.flags(xenapi_connection_url='myscheme://myaddress/') + server_info = vm_utils.get_rrd_server() + self.assertEqual(server_info[0], 'myscheme') + self.assertEqual(server_info[1], 'myaddress') + def test_get_diagnostics(self): instance = self._create_instance() self.conn.get_diagnostics(instance) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 1853bad2f..a7af3e206 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -29,6 +29,7 @@ import sys import tempfile import time import urllib +import urlparse import uuid from decimal import Decimal, InvalidOperation from xml.dom import minidom @@ -1035,15 +1036,9 @@ class VMHelper(HelperBase): @classmethod 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): @@ -1063,13 +1058,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) @@ -1178,29 +1168,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 -- cgit