summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdeploy/deploy.py5
-rw-r--r--deploy/dha_adapters/libvirt_adapter.py31
-rw-r--r--deploy/environments/virtual_fuel.py56
-rw-r--r--deploy/install_fuel_master.py8
4 files changed, 95 insertions, 5 deletions
diff --git a/deploy/deploy.py b/deploy/deploy.py
index 742e76baa..179ee7bcb 100755
--- a/deploy/deploy.py
+++ b/deploy/deploy.py
@@ -245,6 +245,11 @@ class AutoDeploy(object):
def check_bridge(pxe_bridge, dha_path):
+ # Assume that bridges on remote nodes exists, we could ssh but
+ # the remote user might not have a login shell.
+ if os.environ.get('LIBVIRT_DEFAULT_URI'):
+ return
+
with io.open(dha_path) as yaml_file:
dha_struct = yaml.load(yaml_file)
if dha_struct['adapter'] != 'libvirt':
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
diff --git a/deploy/environments/virtual_fuel.py b/deploy/environments/virtual_fuel.py
index ac5fc5356..f9f9f7ab9 100644
--- a/deploy/environments/virtual_fuel.py
+++ b/deploy/environments/virtual_fuel.py
@@ -11,14 +11,36 @@
from lxml import etree
from execution_environment import ExecutionEnvironment
import tempfile
+import os
+import re
+import time
from common import (
exec_cmd,
check_file_exists,
check_if_root,
delete,
+ log,
)
+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'
+
+def get_size_and_unit(s):
+ p = re.compile('^(\d+)\s*(\D+)')
+ m = p.match(s)
+ if m == None:
+ return None, None
+ size = m.groups()[0]
+ unit = m.groups()[1]
+ return size, unit
class VirtualFuel(ExecutionEnvironment):
@@ -55,14 +77,42 @@ class VirtualFuel(ExecutionEnvironment):
with open(temp_vm_file, 'w') as f:
vm_xml.write(f, pretty_print=True, xml_declaration=True)
+ def create_volume(self, pool, name, su, img_type='qcow2'):
+ log('Creating image using Libvirt volumes in pool %s, name: %s' %
+ (pool, name))
+ size, unit = get_size_and_unit(su)
+ if size == None:
+ err('Could not determine size and unit of %s' % s)
+
+ vol_xml = VOL_XML_TEMPLATE.format(name=name, unit=unit, size=size,
+ format_type=img_type)
+ fname = os.path.join(self.temp_dir, '%s_vol.xml' % name)
+ with file(fname, 'w') as f:
+ f.write(vol_xml)
+
+ exec_cmd('virsh vol-create --pool %s %s' % (pool, fname))
+ vol_path = exec_cmd('virsh vol-path --pool %s %s' % (pool, name))
+
+ delete(fname)
+
+ return vol_path
+
def create_image(self, disk_path, disk_size):
- exec_cmd('qemu-img create -f qcow2 %s %s' % (disk_path, disk_size))
+ if os.environ.get('LIBVIRT_DEFAULT_URI') == None:
+ exec_cmd('qemu-img create -f qcow2 %s %s' % (disk_path, disk_size))
+ else:
+ pool = DEFAULT_POOL # FIXME
+ name = os.path.basename(disk_path)
+ disk_path = self.create_volume(pool, name, disk_size)
+
+ return disk_path
def create_vm(self):
- disk_path = '%s/%s.raw' % (self.storage_dir, self.vm_name)
+ stamp = time.strftime("%Y%m%d%H%M%S")
+ disk_path = '%s/%s-%s.raw' % (self.storage_dir, self.vm_name, stamp)
disk_sizes = self.dha.get_disks()
disk_size = disk_sizes['fuel']
- self.create_image(disk_path, disk_size)
+ disk_path = self.create_image(disk_path, disk_size)
temp_vm_file = '%s/%s' % (self.temp_dir, self.vm_name)
exec_cmd('cp %s %s' % (self.vm_template, temp_vm_file))
diff --git a/deploy/install_fuel_master.py b/deploy/install_fuel_master.py
index 631bf99b9..5adccefbf 100644
--- a/deploy/install_fuel_master.py
+++ b/deploy/install_fuel_master.py
@@ -54,8 +54,12 @@ class InstallFuelMaster(object):
self.dha.node_power_off(self.fuel_node_id)
- log('Zero the MBR')
- self.dha.node_zero_mbr(self.fuel_node_id)
+ if os.environ.get('LIBVIRT_DEFAULT_URI'):
+ log('Upload ISO to pool')
+ self.iso_file = self.dha.upload_iso(self.iso_file)
+ else:
+ log('Zero the MBR')
+ self.dha.node_zero_mbr(self.fuel_node_id)
self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso'])