diff options
author | Alex Yang <yangyang1@zte.com.cn> | 2017-09-13 21:10:40 +0800 |
---|---|---|
committer | Zhijiang Hu <hu.zhijiang@zte.com.cn> | 2017-09-25 06:07:18 +0000 |
commit | 6c26da419ff6fd6f82377e8e19187af37fe8d783 (patch) | |
tree | 0eb0259e41adc2d6b6c61dd5412f72dae351b20c /deploy | |
parent | 459282da6a51520ed3a255f80569a437881a047a (diff) |
Use pxe bridge to replace the bridge in VM template
1. Eliminate hard code about pxe bridge
2. Replace the bridge in daisy VM template with the pxe bridge
provided by jenkins
Change-Id: I7a8463181847417d10705ce9ff4db6e68d505c6d
Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
(cherry picked from commit 56975272e92efa3f5f6f719028dc147c1d90e9ce)
Diffstat (limited to 'deploy')
-rw-r--r-- | deploy/deploy.py | 16 | ||||
-rw-r--r-- | deploy/environment.py | 5 | ||||
-rw-r--r-- | deploy/libvirt_utils.py | 24 |
3 files changed, 32 insertions, 13 deletions
diff --git a/deploy/deploy.py b/deploy/deploy.py index 71c39742..42a9d2f7 100644 --- a/deploy/deploy.py +++ b/deploy/deploy.py @@ -11,11 +11,11 @@ # TODO: # [ ] 1. specify VM templates (Server, Controller & Compute) in deploy.yml # [ ] 2. specify network templates in deploy.yml -# [ ] 3. specify adapter(ipmi, libvirt) in deploy.yml -# [ ] 4. get ipmi user/password from PDF (Pod Descriptor File) -# [ ] 5. get pxe bridge from jjb -# [ ] 6. enlarge the vm size of Controller & Compute in deploy.yml -# [ ] 7. support scenarios options and configuration +# [x] 3. specify adapter(ipmi, libvirt) in deploy.yml +# [x] 4. get ipmi user/password from PDF (Pod Descriptor File) +# [x] 5. get pxe bridge from jjb +# [x] 6. enlarge the vm size of Controller & Compute in deploy.yml +# [x] 7. support scenarios options and configuration ############################################################################## import argparse @@ -85,11 +85,11 @@ class DaisyDeployment(object): self.adapter = self._get_adapter_info() LI('The adapter is %s' % self.adapter) - # TODO: modify the jjb code to provide bridge name + # Virtual deployment always uses 'daisy1' as default bridge. if self.adapter == 'libvirt': self.pxe_bridge = 'daisy1' - else: - self.pxe_bridge = 'br7' + + LI('Use %s as the bridge name in daisy deployment.' % self.pxe_bridge) self.daisy_server_info = self._get_daisy_server_info() diff --git a/deploy/environment.py b/deploy/environment.py index 5371e6ca..14240549 100644 --- a/deploy/environment.py +++ b/deploy/environment.py @@ -135,7 +135,6 @@ class BareMetalEnvironment(DaisyEnvironmentBase): def create_daisy_server_vm(self): # TODO: refactor the structure of deploy.yml, add VM template param of Daisy Server - # add self.pxe_bridge into the vm template if 'template' in self.deploy_struct: # get VM name of Daisy Server from the template template = self.deploy_struct['template'] @@ -144,7 +143,8 @@ class BareMetalEnvironment(DaisyEnvironmentBase): create_vm(template, name=self.daisy_server_info['name'], - disks=[self.daisy_server_info['image']]) + disks=[self.daisy_server_info['image']], + physical_bridge=self.pxe_bridge) def reboot_nodes(self, boot_dev=None): for node in self.deploy_struct['hosts']: @@ -203,7 +203,6 @@ class VirtualEnvironment(DaisyEnvironmentBase): def create_daisy_server_vm(self): # TODO: refactor the structure of deploy.yml, add VM template param of Daisy Server - # add self.pxe_bridge into the vm template if 'template' in self.deploy_struct: # get VM name of Daisy Server from the template template = self.deploy_struct['template'] diff --git a/deploy/libvirt_utils.py b/deploy/libvirt_utils.py index 8e4523de..3b9eae1c 100644 --- a/deploy/libvirt_utils.py +++ b/deploy/libvirt_utils.py @@ -69,6 +69,24 @@ def modify_vm_disk_file(root, disks): devices.append(disk) +def modify_vm_bridge(root, bridge): + devices = root.find('./devices') + for interface in devices.findall('interface'): + source = interface.find('source') + if interface.attrib.get('type', None) == 'bridge' \ + and source is not None \ + and source.attrib.get('bridge', None) == bridge: + # pxebr is already in the VM template + return + + for interface in devices.findall('interface'): + devices.remove(interface) + + interface = ET.Element('interface', attrib={'type': 'bridge'}) + interface.append(ET.Element('source', attrib={'bridge': bridge})) + devices.append(interface) + + def create_virtual_disk(disk_file, size): LI('Create virtual disk file %s size %d GB' % (disk_file, size)) cmd = 'qemu-img create -f qcow2 {disk_file} {size}G'.format( @@ -79,16 +97,18 @@ def create_virtual_disk(disk_file, size): err_exit('Fail to create qemu image !') -def create_vm(template, name=None, disks=None): +def create_vm(template, name=None, disks=None, physical_bridge=None): LI('Begin to create VM %s' % template) - if name or disks: + if name or disks or physical_bridge: tree = ET.ElementTree(file=template) root = tree.getroot() if name: modify_vm_name(root, name) if disks: modify_vm_disk_file(root, disks) + if physical_bridge: + modify_vm_bridge(root, physical_bridge) temp_file = path_join(WORKSPACE, 'tmp.xml') tree.write(temp_file) |