Commit dcc18468 authored by Antoine Millet's avatar Antoine Millet

Now wrap volumes into a BoundVolumeProxy in guest iter_disks

parent cb11bdda
......@@ -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 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,, 10), # FIXME: change
Tag('disk%s_vol' % i,, 10),
Tag('disk%s_cache' % i, lambda: self.cache_behaviour.get(v.path), 10),
Tag('disk%s_shared' % i, lambda: {True: 'yes', False: 'no'}[])
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'}[], v)),
Tag('disk%s_dev' % i, v.device, 10),
Tag('disk%s_bus' % i, v.bus, 10)
......@@ -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)
def nics(self):
......@@ -472,3 +472,15 @@ class Volume(object):
def update(self):
self.capacity, self.allocation =[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)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment