Merge "Rework: Move nailgun timeout patch to postinstall"
[armband.git] / patches / opnfv-fuel / 0008-virtual_fuel-prepare-class-to-allow-multiple-bridges.patch
1 From: Josep Puigdemont <josep.puigdemont@enea.com>
2 Date: Fri, 20 May 2016 10:23:45 +0200
3 Subject: [PATCH] virtual_fuel: prepare class to allow multiple bridges
4
5 The VirtualFuel class has now two new methods:
6
7     del_vm_nics: Deletes all interfaces from the VM.
8
9     add_vm_nic: Adds a NIC to the VM, attached to the specified bridge.
10
11 The following method has been deleted:
12
13     set_vm_nic: implemented with the two new methods
14
15 Apart from the deleted method, no functionality has been changed. This
16 is just a small but necessary step towards adding support for supporting
17 more than one bridge in the fuel VM.
18
19 Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
20 ---
21  deploy/environments/virtual_fuel.py | 21 +++++++++++++--------
22  1 file changed, 13 insertions(+), 8 deletions(-)
23
24 diff --git a/deploy/environments/virtual_fuel.py b/deploy/environments/virtual_fuel.py
25 index 7dc9720..5a86c97 100644
26 --- a/deploy/environments/virtual_fuel.py
27 +++ b/deploy/environments/virtual_fuel.py
28 @@ -67,22 +67,25 @@ class VirtualFuel(ExecutionEnvironment):
29          with open(self.temp_vm_file, "wc") as f:
30              self.vm_xml.write(f, pretty_print=True, xml_declaration=True)
31  
32 -    def set_vm_nic(self):
33 +    def del_vm_nics(self):
34          interfaces = self.vm_xml.xpath('/domain/devices/interface')
35          for interface in interfaces:
36              interface.getparent().remove(interface)
37 +
38 +    def add_vm_nic(self, bridge):
39          interface = etree.Element('interface')
40          interface.set('type', 'bridge')
41          source = etree.SubElement(interface, 'source')
42 -        source.set('bridge', self.pxe_bridge)
43 +        source.set('bridge', bridge)
44          model = etree.SubElement(interface, 'model')
45          model.set('type', 'virtio')
46 +
47          devices = self.vm_xml.xpath('/domain/devices')
48          if devices:
49              device = devices[0]
50              device.append(interface)
51 -
52 -        self.update_vm_template_file()
53 +        else:
54 +            err('No devices!')
55  
56      def create_volume(self, pool, name, su, img_type='qcow2'):
57          log('Creating image using Libvirt volumes in pool %s, name: %s' %
58 @@ -121,11 +124,13 @@ class VirtualFuel(ExecutionEnvironment):
59          disk_size = disk_sizes['fuel']
60          disk_path = self.create_image(disk_path, disk_size)
61  
62 -        temp_vm_file = '%s/%s' % (self.temp_dir, self.vm_name)
63 -        exec_cmd('cp %s %s' % (self.vm_template, temp_vm_file))
64 -        self.set_vm_nic(temp_vm_file)
65 +        self.del_vm_nics()
66 +        self.add_vm_nic(self.pxe_bridge)
67 +        self.update_vm_template_file()
68 +
69          vm_definition_overwrite = self.dha.get_vm_definition('fuel')
70 -        self.define_vm(self.vm_name, temp_vm_file, disk_path,
71 +
72 +        self.define_vm(self.vm_name, self.temp_vm_file, disk_path,
73                         vm_definition_overwrite)
74  
75      def setup_environment(self):