diff --git a/cloudcontrol/node/hypervisor/domains/__init__.py b/cloudcontrol/node/hypervisor/domains/__init__.py index f84834d83b7340ab72a449c5f0f11da0a629638c..f93bd9fba78abcb434a13c916f37c62616d378cf 100644 --- a/cloudcontrol/node/hypervisor/domains/__init__.py +++ b/cloudcontrol/node/hypervisor/domains/__init__.py @@ -23,12 +23,13 @@ from StringIO import StringIO from xml.etree import cElementTree as et from collections import namedtuple from itertools import izip, count +from functools import partial import pyev import libvirt from cloudcontrol.common.client.tags import Tag, tag_inspector, TagDB -from cloudcontrol.node.hypervisor.lib import DOMAIN_STATES as STATE +from cloudcontrol.node.hypervisor.lib import DOMAIN_STATES as STATE, BoundVolumeProxy from cloudcontrol.node.hypervisor.domains import vm_tags from cloudcontrol.node.utils import SocketBuffer from cloudcontrol.node.exc import ConsoleAlreadyOpened, ConsoleError @@ -75,8 +76,10 @@ class VirtualMachine(object): Tag('disk%s_path' % i, v.path, 10), Tag('disk%s_pool' % i, v.storage.name, 10), # FIXME: change Tag('disk%s_vol' % i, v.name, 10), - Tag('disk%s_cache' % i, lambda: self.cache_behaviour.get(v.path), 10), - Tag('disk%s_shared' % i, lambda: {True: 'yes', False: 'no'}[v.storage.is_shared]) + Tag('disk%s_cache' % i, partial(lambda x: self.cache_behaviour.get(x.path), v), 10), + Tag('disk%s_shared' % i, partial(lambda x: {True: 'yes', False: 'no'}[x.storage.is_shared], v)), + Tag('disk%s_dev' % i, v.device, 10), + Tag('disk%s_bus' % i, v.bus, 10) ): self.tag_db.add_tag(t) @@ -278,13 +281,18 @@ class VirtualMachine(object): path = volume.path + # Get target device & bus + target = d.find('target') + device = target.get('dev') + bus = target.get('bus') + # update cache behaviour driver = d.find('driver') if driver is None: driver = {} self.cache_behaviour[path] = driver.get('cache', 'default') - yield volume + yield BoundVolumeProxy(volume, device, bus) @property def nics(self): diff --git a/cloudcontrol/node/hypervisor/lib.py b/cloudcontrol/node/hypervisor/lib.py index fdcf3d1a25f19917b3854a4fadcd29e99f647fbb..5a043dad544001d3549377ecdfc1f2faa9b67666 100644 --- a/cloudcontrol/node/hypervisor/lib.py +++ b/cloudcontrol/node/hypervisor/lib.py @@ -472,3 +472,15 @@ class Volume(object): def update(self): self.capacity, self.allocation = self.lv_volume.info()[1:] + + +class BoundVolumeProxy(object): + """Proxy object to an existing Volume when its bound to a VM.""" + + def __init__(self, volume, device, bus): + self.volume = volume + self.device = device + self.bus = bus + + def __getattr__(self, name): + return self.volume.__getattribute__(name)