summaryrefslogtreecommitdiffstats
path: root/deploy/dha_adapters/libvirt_adapter.py
diff options
context:
space:
mode:
authorJonas Bjurel <jonas.bjurel@ericsson.com>2016-06-15 17:19:54 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-15 17:19:54 +0000
commit3cddf277c5966c5cc584a493d5923cc5dcdc7820 (patch)
tree2370a47da81ae080c195bff7e74815386413076a /deploy/dha_adapters/libvirt_adapter.py
parentf09f2e3c661b8fcb1c82151e1ad17eea7275b417 (diff)
parente9838d6a94d3b49c8a85d42fbf5cddc69af6cdc5 (diff)
Merge "virtual_fuel: initial support for remote libvirt"
Diffstat (limited to 'deploy/dha_adapters/libvirt_adapter.py')
-rw-r--r--deploy/dha_adapters/libvirt_adapter.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/deploy/dha_adapters/libvirt_adapter.py b/deploy/dha_adapters/libvirt_adapter.py
index 85913ac9e..466f134ae 100644
--- a/deploy/dha_adapters/libvirt_adapter.py
+++ b/deploy/dha_adapters/libvirt_adapter.py
@@ -11,6 +11,7 @@
from lxml import etree
from hardware_adapter import HardwareAdapter
import tempfile
+import os
from common import (
log,
@@ -23,6 +24,15 @@ DEV = {'pxe': 'network',
'disk': 'hd',
'iso': 'cdrom'}
+VOL_XML_TEMPLATE = '''<volume type='file'>
+ <name>{name}</name>
+ <capacity unit='{unit}'>{size!s}</capacity>
+ <target>
+ <format type='{format_type}'/>
+ </target>
+</volume>'''
+
+DEFAULT_POOL = 'jenkins'
class LibvirtAdapter(HardwareAdapter):
@@ -140,3 +150,24 @@ class LibvirtAdapter(HardwareAdapter):
def get_virt_net_conf_dir(self):
return self.dha_struct['virtNetConfDir']
+
+ def upload_iso(self, iso_file):
+ size = os.path.getsize(iso_file)
+ vol_name = os.path.basename(iso_file)
+ vol_xml = VOL_XML_TEMPLATE.format(name=vol_name, unit='bytes',
+ size=size, format_type='raw')
+ fd, fname = tempfile.mkstemp(text=True, suffix='deploy')
+ os.write(fd, vol_xml)
+ os.close(fd)
+
+ log(vol_xml)
+ pool = DEFAULT_POOL # FIXME
+ exec_cmd('virsh vol-create --pool %s %s' % (pool, fname))
+ vol_path = exec_cmd('virsh vol-path --pool %s %s' % (pool, vol_name))
+
+ exec_cmd('virsh vol-upload %s %s' % (vol_path, iso_file),
+ attempts=5, delay=10, verbose=True)
+
+ delete(fname)
+
+ return vol_path