Configure the infra VMs over DHA 21/11421/2
authorNikolas Hermanns <nikolas.hermanns@ericsson.com>
Fri, 18 Mar 2016 09:26:37 +0000 (10:26 +0100)
committerNikolas Hermanns <nikolas.hermanns@ericsson.com>
Fri, 18 Mar 2016 12:28:54 +0000 (13:28 +0100)
This commit enables the full configuration
of the VM(fuel/controller/compute)
defintion through the dha file.

Change-Id: I4e78334d1e5aec1e98667343390283587f0b3ea5

deploy/config/labs/devel-pipeline/elx/fuel/config/dha.yaml
deploy/dha_adapters/hardware_adapter.py
deploy/environments/execution_environment.py
deploy/environments/libvirt_environment.py
deploy/environments/virtual_fuel.py

index 8515098..07faeb1 100644 (file)
@@ -37,7 +37,47 @@ disks:
   controller: 100G
   compute: 100G
 
-number_cpus:
-  # Entry is not mandatory! If it is left empty
-  # the default is 2 cpus per node
-  controller: 2
+# Here the infrastructure VMs can be defined.
+# The entries are not mandatory! If it is left empty
+# the default defined in deploy/templates will
+# be used.
+define_vms:
+  fuel:
+    vcpu:
+      value: 2
+    memory:
+      attribute_equlas:
+        unit: KiB
+      value: 8388608
+    currentMemory:
+      attribute_equlas:
+        unit: KiB
+      value: 8388608
+    devices:
+      interface:
+        # With attribute_equlas someone can define which
+        # interface type is meant
+        attribute_equlas:
+          type: network
+        # This will overwrite the type of the model of
+        # the interface
+        model:
+          attribute:
+            type: e1000
+  controller:
+    devices:
+      interface:
+        attribute_equlas:
+          type: network
+        model:
+          attribute:
+            type: e1000
+  compute:
+    devices:
+      interface:
+        attribute_equlas:
+          type: network
+        model:
+          attribute:
+            type: e1000
+
index 55bb400..aa59581 100644 (file)
@@ -59,7 +59,7 @@ class HardwareAdapter(object):
     def get_disks(self):
         return self.dha_struct['disks']
 
-    def get_number_cpus(self, role):
-        role_cpus_dict = self.dha_struct.get('number_cpus')
-        if role_cpus_dict:
-            return role_cpus_dict.get(role)
+    def get_vm_definition(self, role):
+        vm_definition = self.dha_struct.get('define_vms')
+        if vm_definition:
+            return vm_definition.get(role)
index c2e7a0b..2a4e39e 100644 (file)
@@ -50,7 +50,30 @@ class ExecutionEnvironment(object):
         for file in disk_files:
             delete(file)
 
-    def define_vm(self, vm_name, temp_vm_file, disk_path, number_cpus):
+    def overwrite_xml(self, vm_xml, vm_definition_overwrite):
+        for key, value in vm_definition_overwrite.iteritems():
+            if key == 'attribute_equlas':
+                continue
+            if key == 'value':
+                vm_xml.text = str(value)
+                return
+            if key == 'attribute':
+                for attr_key, attr_value in value.iteritems():
+                    vm_xml.set(attr_key, str(attr_value))
+                return
+
+            if isinstance(value, dict):
+                only_when_attribute = value.get('attribute_equlas')
+            for xml_element in vm_xml.xpath(key):
+                if only_when_attribute:
+                    for attr_key, attr_value in \
+                            only_when_attribute.iteritems():
+                        if attr_value != xml_element.get(attr_key):
+                            continue
+                self.overwrite_xml(xml_element, value)
+
+    def define_vm(self, vm_name, temp_vm_file, disk_path,
+                  vm_definition_overwrite):
         log('Creating VM %s with disks %s' % (vm_name, disk_path))
         with open(temp_vm_file) as f:
             vm_xml = etree.parse(f)
@@ -60,10 +83,8 @@ class ExecutionEnvironment(object):
         uuids = vm_xml.xpath('/domain/uuid')
         for uuid in uuids:
             uuid.getparent().remove(uuid)
-        if number_cpus:
-            vcpus = vm_xml.xpath('/domain/vcpu')
-            for vcpu in vcpus:
-                vcpu.text = str(number_cpus)
+        self.overwrite_xml(vm_xml.xpath('/domain')[0],
+                           vm_definition_overwrite)
         disks = vm_xml.xpath('/domain/devices/disk')
         for disk in disks:
             if (disk.get('type') == 'file' and
index 380262c..c9fa41f 100644 (file)
@@ -49,11 +49,12 @@ class LibvirtEnvironment(ExecutionEnvironment):
             check_file_exists(vm_template)
             disk_path = '%s/%s.raw' % (self.storage_dir, vm_name)
             self.create_storage(node_id, disk_path, disk_sizes)
-            number_cpus = self.dha.get_number_cpus(
-                self.dea.get_node_main_role(node_id, self.fuel_node_id))
             temp_vm_file = '%s/%s' % (temp_dir, vm_name)
             exec_cmd('cp %s %s' % (vm_template, temp_vm_file))
-            self.define_vm(vm_name, temp_vm_file, disk_path, number_cpus)
+            vm_definition_overwrite = self.dha.get_vm_definition(
+                 self.dea.get_node_main_role(node_id, self.fuel_node_id))
+            self.define_vm(vm_name, temp_vm_file, disk_path,
+                           vm_definition_overwrite)
         delete(temp_dir)
 
     def start_vms(self):
index 6208218..cb3bc6c 100644 (file)
@@ -55,12 +55,13 @@ class VirtualFuel(ExecutionEnvironment):
         disk_path = '%s/%s.raw' % (self.storage_dir, vm_name)
         disk_sizes = self.dha.get_disks()
         disk_size = disk_sizes['fuel']
-        number_cpus = self.dha.get_number_cpus('fuel')
         exec_cmd('qemu-img create -f qcow2 %s %s' % (disk_path, disk_size))
         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, number_cpus)
+        vm_definition_overwrite = self.dha.get_vm_definition('fuel')
+        self.define_vm(vm_name, temp_vm_file, disk_path,
+                       vm_definition_overwrite)
         delete(temp_dir)
 
     def setup_environment(self):