Skip to content
Snippets Groups Projects
Commit dcc18468 authored by Antoine Millet's avatar Antoine Millet
Browse files

Now wrap volumes into a BoundVolumeProxy in guest iter_disks

parent cb11bdda
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment