summaryrefslogtreecommitdiffstats
path: root/fuel/deploy/environments/virtual_fuel.py
diff options
context:
space:
mode:
authorSzilard Cserey <szilard.cserey@ericsson.com>2015-05-21 15:57:35 +0200
committerSzilard Cserey <szilard.cserey@ericsson.com>2015-06-17 12:09:30 +0200
commit2654b0628e30f54b0b8e89208ab04204858cfae5 (patch)
treeba385d757efb92f7c8f8b13d55ae6a7c483e9dc4 /fuel/deploy/environments/virtual_fuel.py
parent321aff98523fbe442af7ca4d935c83e2196eacee (diff)
Fuel Config Reap + Additional Refactoring for Autodeployment
1. Refactor the whole autodeployment code in such a way that the preparation of Fuel VM + networking and the autodeployment itself can be executed all at once 2. Functionality added that allows reaping of Fuel configuration from an existing environment and create DHA and DEA configuration files from it JIRA: [BGS-2] Create Fuel deployment script Change-Id: I7101295ac4becfc5fa10eda757cec0c2ad127940 Signed-off-by: Szilard Cserey <szilard.cserey@ericsson.com>
Diffstat (limited to 'fuel/deploy/environments/virtual_fuel.py')
-rw-r--r--fuel/deploy/environments/virtual_fuel.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/fuel/deploy/environments/virtual_fuel.py b/fuel/deploy/environments/virtual_fuel.py
new file mode 100644
index 0000000..1f939f0
--- /dev/null
+++ b/fuel/deploy/environments/virtual_fuel.py
@@ -0,0 +1,60 @@
+from lxml import etree
+
+import common
+from execution_environment import ExecutionEnvironment
+
+exec_cmd = common.exec_cmd
+log = common.log
+check_file_exists = common.check_file_exists
+check_if_root = common.check_if_root
+
+class VirtualFuel(ExecutionEnvironment):
+
+ def __init__(self, storage_dir, pxe_bridge, dha_file, root_dir):
+ super(VirtualFuel, self).__init__(
+ storage_dir, dha_file, root_dir)
+ self.pxe_bridge = pxe_bridge
+
+ def set_vm_nic(self, temp_vm_file):
+ with open(temp_vm_file) as f:
+ vm_xml = etree.parse(f)
+ interfaces = vm_xml.xpath('/domain/devices/interface')
+ for interface in interfaces:
+ interface.getparent().remove(interface)
+ interface = etree.Element('interface')
+ interface.set('type', 'bridge')
+ source = etree.SubElement(interface, 'source')
+ source.set('bridge', self.pxe_bridge)
+ model = etree.SubElement(interface, 'model')
+ model.set('type', 'virtio')
+ devices = vm_xml.xpath('/domain/devices')
+ if devices:
+ device = devices[0]
+ device.append(interface)
+ with open(temp_vm_file, 'w') as f:
+ vm_xml.write(f, pretty_print=True, xml_declaration=True)
+
+ def create_vm(self):
+ temp_dir = exec_cmd('mktemp -d')
+ vm_name = self.dha.get_node_property(self.fuel_node_id, 'libvirtName')
+ vm_template = '%s/%s' % (self.root_dir,
+ self.dha.get_node_property(
+ self.fuel_node_id, 'libvirtTemplate'))
+ check_file_exists(vm_template)
+ disk_path = '%s/%s.raw' % (self.storage_dir, vm_name)
+ disk_sizes = self.dha.get_disks()
+ disk_size = disk_sizes['fuel']
+ exec_cmd('fallocate -l %s %s' % (disk_size, disk_path))
+ temp_vm_file = '%s/%s' % (temp_dir, vm_name)
+ exec_cmd('cp %s %s' % (vm_template, temp_vm_file))
+ self.set_vm_nic(temp_vm_file)
+ self.define_vm(vm_name, temp_vm_file, disk_path)
+ exec_cmd('rm -fr %s' % temp_dir)
+
+ def setup_environment(self):
+ check_if_root()
+ self.cleanup_environment()
+ self.create_vm()
+
+ def cleanup_environment(self):
+ self.delete_vm(self.fuel_node_id)