From 2796f3e359226427894a3e939b3218bbd06c2a74 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Fri, 29 May 2015 15:23:13 +0200 Subject: [PATCH] Implement volumes disks --- .../node/hypervisor/domains/__init__.py | 17 +++++++++++------ cloudcontrol/node/hypervisor/lib.py | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cloudcontrol/node/hypervisor/domains/__init__.py b/cloudcontrol/node/hypervisor/domains/__init__.py index 345e6c0..fdbcb3f 100644 --- a/cloudcontrol/node/hypervisor/domains/__init__.py +++ b/cloudcontrol/node/hypervisor/domains/__init__.py @@ -235,10 +235,19 @@ class VirtualMachine(object): type_ = d.get('type') - if type_ not in ('file', 'block'): + if type_ in ('file', 'block'): + path = d.find('source').get(dict(file='file', block='dev')[type_]) + volume = self.hypervisor.storage.get_volume(path) + if volume is None: + continue + elif type_ == 'volume': + pool = d.find('source').get('pool') + vol = d.find('source').get('volume') + volume = self.hypervisor.storage.get_volume_by_pool(pool, vol) + else: continue - path = d.find('source').get(dict(file='file', block='dev')[type_]) + path = volume.path # update cache behaviour driver = d.find('driver') @@ -246,10 +255,6 @@ class VirtualMachine(object): driver = {} self.cache_behaviour[path] = driver.get('cache', 'default') - volume = self.hypervisor.storage.get_volume(path) - if volume is None: - continue - yield volume @property diff --git a/cloudcontrol/node/hypervisor/lib.py b/cloudcontrol/node/hypervisor/lib.py index fdbffa6..55f52a8 100644 --- a/cloudcontrol/node/hypervisor/lib.py +++ b/cloudcontrol/node/hypervisor/lib.py @@ -355,6 +355,10 @@ class StorageIndex(object): def get_volume(self, path): return self.paths.get(path) + def get_volume_by_pool(self, pool, vol): + storage = self.get_storage(pool) + return storage.volumes.get(vol) + def get_storage(self, name): return self.storages.get(name) -- GitLab