aboutsummaryrefslogtreecommitdiffstats
path: root/deploy
diff options
context:
space:
mode:
authorJosep Puigdemont <josep.puigdemont@enea.com>2016-05-20 10:05:11 +0200
committerJonas Bjurel <jonas.bjurel@ericsson.com>2016-06-16 18:23:23 +0000
commitb0670cfd013bf0ef4a1c1b3723fa3f5da6dd108d (patch)
treeeb23c37f9f94ea38875e04d232cd066a8f5e0c37 /deploy
parentb86d8e65f9a8a3e52a7f06f8ac9d32963c9df6d4 (diff)
virtual_fuel: add XML tree as attribute of VirtualFuel
With this patch, the VM XML definition tree is an attribute of the object, this way it can be used by all methods without having to re-read the file. Methods added: update_vm_template_file: Flushes the contents of the in-memory XML representation of the VM to the backing file. Change-Id: I18d3f606b0c02cd589cb0f657599e8b03b0e817e Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
Diffstat (limited to 'deploy')
-rw-r--r--deploy/environments/virtual_fuel.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/deploy/environments/virtual_fuel.py b/deploy/environments/virtual_fuel.py
index f9f9f7ab9..7dc972025 100644
--- a/deploy/environments/virtual_fuel.py
+++ b/deploy/environments/virtual_fuel.py
@@ -54,14 +54,21 @@ class VirtualFuel(ExecutionEnvironment):
self.dha.get_node_property(
self.fuel_node_id, 'libvirtTemplate'))
check_file_exists(self.vm_template)
+ with open(self.vm_template) as f:
+ self.vm_xml = etree.parse(f)
+
+ self.temp_vm_file = '%s/%s' % (self.temp_dir, self.vm_name)
+ self.update_vm_template_file()
def __del__(self):
delete(self.temp_dir)
- 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')
+ def update_vm_template_file(self):
+ with open(self.temp_vm_file, "wc") as f:
+ self.vm_xml.write(f, pretty_print=True, xml_declaration=True)
+
+ def set_vm_nic(self):
+ interfaces = self.vm_xml.xpath('/domain/devices/interface')
for interface in interfaces:
interface.getparent().remove(interface)
interface = etree.Element('interface')
@@ -70,12 +77,12 @@ class VirtualFuel(ExecutionEnvironment):
source.set('bridge', self.pxe_bridge)
model = etree.SubElement(interface, 'model')
model.set('type', 'virtio')
- devices = vm_xml.xpath('/domain/devices')
+ devices = self.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)
+
+ self.update_vm_template_file()
def create_volume(self, pool, name, su, img_type='qcow2'):
log('Creating image using Libvirt volumes in pool %s, name: %s' %