Use unified vm template files in python deploy script 15/35015/6
authorAlex Yang <yangyang1@zte.com.cn>
Fri, 19 May 2017 01:19:17 +0000 (09:19 +0800)
committerAlex Yang <yangyang1@zte.com.cn>
Thu, 25 May 2017 05:34:38 +0000 (13:34 +0800)
Change-Id: I386011a35a9be3e4f1d468744a6945360bb2adb3
Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
deploy/config/schemas.py
deploy/config/vm_environment/zte-virtual1/deploy.yml
deploy/config/vm_environment/zte-virtual2/deploy.yml
deploy/environment.py
templates/virtual_environment/vms/computer.xml [new file with mode: 0644]
templates/virtual_environment/vms/controller.xml [new file with mode: 0644]

index 7cc2c80..d2fd7ef 100644 (file)
@@ -27,7 +27,8 @@ hosts_schema = {
                     'type': 'string',
                     'enum': ['COMPUTER', 'CONTROLLER_LB', 'CONTROLLER_HA']
                 }
-            }
+            },
+            'template': {'type': 'string', 'minLength': 1}
         }
     }
 }
index 0b3a2c5..a85f429 100644 (file)
@@ -4,6 +4,7 @@ hosts:
   roles:\r
     - 'CONTROLLER_LB'\r
     - 'COMPUTER'\r
+  template: 'templates/virtual_environment/vms/all_in_one.xml'\r
 disks:\r
   daisy: 50\r
   controller: 110\r
index 646fa13..43b2ed0 100644 (file)
@@ -3,18 +3,23 @@ hosts:
 - name: 'controller01'\r
   roles:\r
     - 'CONTROLLER_LB'\r
+  template: 'templates/virtual_environment/vms/controller.xml'\r
 - name: 'controller02'\r
   roles:\r
     - 'CONTROLLER_LB'\r
+  template: 'templates/virtual_environment/vms/controller.xml'\r
 - name: 'controller03'\r
   roles:\r
     - 'CONTROLLER_LB'\r
+  template: 'templates/virtual_environment/vms/controller.xml'\r
 - name: 'computer01'\r
   roles:\r
     - 'COMPUTER'\r
+  template: 'templates/virtual_environment/vms/computer.xml'\r
 - name: 'computer02'\r
   roles:\r
     - 'COMPUTER'\r
+  template: 'templates/virtual_environment/vms/computer.xml'\r
 disks:\r
   daisy: 50\r
   controller: 110\r
index d18bf55..2adec49 100644 (file)
@@ -28,6 +28,7 @@ from libvirt_utils import (
 )
 from utils import (
     WORKSPACE,
+    LD,
     LI,
     LW,
     err_exit,
@@ -45,8 +46,8 @@ VMDEPLOY_DAISY_SERVER_VM = path_join(WORKSPACE, 'templates/virtual_environment/v
 BMDEPLOY_DAISY_SERVER_VM = path_join(WORKSPACE, 'templates/physical_environment/vms/daisy.xml')
 
 ALL_IN_ONE_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/all_in_one.xml')
-CONTROLLER_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/controller01.xml')
-COMPUTE_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/computer01.xml')
+CONTROLLER_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/controller.xml')
+COMPUTE_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/computer.xml')
 VIRT_NET_TEMPLATE_PATH = path_join(WORKSPACE, 'templates/virtual_environment/networks')
 
 
@@ -160,6 +161,27 @@ class BareMetalEnvironment(DaisyEnvironmentBase):
 
 
 class VirtualEnvironment(DaisyEnvironmentBase):
+    def __init__(self, deploy_struct, net_struct, adapter, pxe_bridge,
+                 daisy_server_info, work_dir, storage_dir):
+        super(VirtualEnvironment, self).__init__(deploy_struct, net_struct, adapter, pxe_bridge,
+                                                 daisy_server_info, work_dir, storage_dir)
+        self.check_configuration()
+
+    def check_configuration(self):
+        self.check_nodes_template()
+
+    def check_nodes_template(self):
+        for node in self.deploy_struct['hosts']:
+            template = node.get('template', None)
+            if not template or os.access(template, os.R_OK):
+                continue
+            elif os.access(path_join(WORKSPACE, template), os.R_OK):
+                template_new = path_join(WORKSPACE, template)
+                LD('Template of VM node %s is %s' % (node.get('name', ''), template_new))
+                node['template'] = template_new
+            else:
+                err_exit('The template of vm node %s does not exist.' % node.get('name'))
+
     def create_daisy_server_network(self):
         net_name = create_virtual_network(VMDEPLOY_DAISY_SERVER_NET)
         if net_name != self.pxe_bridge:
diff --git a/templates/virtual_environment/vms/computer.xml b/templates/virtual_environment/vms/computer.xml
new file mode 100644 (file)
index 0000000..ee03810
--- /dev/null
@@ -0,0 +1,124 @@
+<domain type='kvm' id='4'>
+  <name>computer</name>
+  <memory unit='KiB'>8388608</memory>
+  <currentMemory unit='KiB'>8388608</currentMemory>
+  <vcpu placement='static'>4</vcpu>
+  <resource>
+    <partition>/machine</partition>
+  </resource>
+  <os>
+    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
+    <boot dev='network'/>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+  </features>
+  <cpu mode="host-model"/>
+  <clock offset='utc'>
+    <timer name='rtc' tickpolicy='catchup'/>
+    <timer name='pit' tickpolicy='delay'/>
+    <timer name='hpet' present='no'/>
+  </clock>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <pm>
+    <suspend-to-mem enabled='no'/>
+    <suspend-to-disk enabled='no'/>
+  </pm>
+  <devices>
+    <emulator>/usr/libexec/qemu-kvm</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='qcow2'/>
+      <source file='/home/qemu/vms/computer.qcow2'/>
+      <backingStore/>
+      <target dev='hda' bus='ide'/>
+      <alias name='ide0-0-0'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0' model='ich9-ehci1'>
+      <alias name='usb'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x7'/>
+    </controller>
+    <controller type='usb' index='0' model='ich9-uhci1'>
+      <alias name='usb'/>
+      <master startport='0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0' multifunction='on'/>
+    </controller>
+    <controller type='usb' index='0' model='ich9-uhci2'>
+      <alias name='usb'/>
+      <master startport='2'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x1'/>
+    </controller>
+    <controller type='usb' index='0' model='ich9-uhci3'>
+      <alias name='usb'/>
+      <master startport='4'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x2'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'>
+      <alias name='pci.0'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <alias name='ide'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='virtio-serial' index='0'>
+      <alias name='virtio-serial0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+    </controller>
+    <interface type='network'>
+      <source network='daisy1' bridge='daisy1'/>
+      <model type='rtl8139'/>
+    </interface>
+    <interface type='network'>
+      <source network='daisy2' bridge='daisy2'/>
+      <model type='rtl8139'/>
+    </interface>
+    <serial type='pty'>
+      <source path='/dev/pts/4'/>
+      <target port='0'/>
+      <alias name='serial0'/>
+    </serial>
+    <console type='pty' tty='/dev/pts/4'>
+      <source path='/dev/pts/4'/>
+      <target type='serial' port='0'/>
+      <alias name='serial0'/>
+    </console>
+    <channel type='spicevmc'>
+      <target type='virtio' name='com.redhat.spice.0' state='connected'/>
+      <alias name='channel0'/>
+      <address type='virtio-serial' controller='0' bus='0' port='1'/>
+    </channel>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <graphics type='spice' port='5903' autoport='yes' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+      <image compression='off'/>
+    </graphics>
+    <sound model='ich6'>
+      <alias name='sound0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </sound>
+    <video>
+      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1'/>
+      <alias name='video0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </video>
+    <redirdev bus='usb' type='spicevmc'>
+      <alias name='redir0'/>
+    </redirdev>
+    <redirdev bus='usb' type='spicevmc'>
+      <alias name='redir1'/>
+    </redirdev>
+    <memballoon model='virtio'>
+      <alias name='balloon0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+    </memballoon>
+  </devices>
+  <seclabel type='dynamic' model='selinux' relabel='yes'>
+    <label>system_u:system_r:svirt_t:s0:c182,c195</label>
+    <imagelabel>system_u:object_r:svirt_image_t:s0:c182,c195</imagelabel>
+  </seclabel>
+</domain>
diff --git a/templates/virtual_environment/vms/controller.xml b/templates/virtual_environment/vms/controller.xml
new file mode 100644 (file)
index 0000000..5943e65
--- /dev/null
@@ -0,0 +1,124 @@
+<domain type='kvm' id='4'>
+  <name>controller</name>
+  <memory unit='KiB'>4194304</memory>
+  <currentMemory unit='KiB'>4194304</currentMemory>
+  <vcpu placement='static'>4</vcpu>
+  <resource>
+    <partition>/machine</partition>
+  </resource>
+  <os>
+    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
+    <boot dev='network'/>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+  </features>
+  <cpu mode="host-model"/>
+  <clock offset='utc'>
+    <timer name='rtc' tickpolicy='catchup'/>
+    <timer name='pit' tickpolicy='delay'/>
+    <timer name='hpet' present='no'/>
+  </clock>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <pm>
+    <suspend-to-mem enabled='no'/>
+    <suspend-to-disk enabled='no'/>
+  </pm>
+  <devices>
+    <emulator>/usr/libexec/qemu-kvm</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='qcow2'/>
+      <source file='/home/qemu/vms/controller.qcow2'/>
+      <backingStore/>
+      <target dev='hda' bus='ide'/>
+      <alias name='ide0-0-0'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0' model='ich9-ehci1'>
+      <alias name='usb'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x7'/>
+    </controller>
+    <controller type='usb' index='0' model='ich9-uhci1'>
+      <alias name='usb'/>
+      <master startport='0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0' multifunction='on'/>
+    </controller>
+    <controller type='usb' index='0' model='ich9-uhci2'>
+      <alias name='usb'/>
+      <master startport='2'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x1'/>
+    </controller>
+    <controller type='usb' index='0' model='ich9-uhci3'>
+      <alias name='usb'/>
+      <master startport='4'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x2'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'>
+      <alias name='pci.0'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <alias name='ide'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='virtio-serial' index='0'>
+      <alias name='virtio-serial0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+    </controller>
+    <interface type='network'>
+      <source network='daisy1' bridge='daisy1'/>
+      <model type='rtl8139'/>
+    </interface>
+    <interface type='network'>
+      <source network='daisy2' bridge='daisy2'/>
+      <model type='rtl8139'/>
+    </interface>
+    <serial type='pty'>
+      <source path='/dev/pts/4'/>
+      <target port='0'/>
+      <alias name='serial0'/>
+    </serial>
+    <console type='pty' tty='/dev/pts/4'>
+      <source path='/dev/pts/4'/>
+      <target type='serial' port='0'/>
+      <alias name='serial0'/>
+    </console>
+    <channel type='spicevmc'>
+      <target type='virtio' name='com.redhat.spice.0' state='connected'/>
+      <alias name='channel0'/>
+      <address type='virtio-serial' controller='0' bus='0' port='1'/>
+    </channel>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <graphics type='spice' port='5903' autoport='yes' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+      <image compression='off'/>
+    </graphics>
+    <sound model='ich6'>
+      <alias name='sound0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </sound>
+    <video>
+      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1'/>
+      <alias name='video0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </video>
+    <redirdev bus='usb' type='spicevmc'>
+      <alias name='redir0'/>
+    </redirdev>
+    <redirdev bus='usb' type='spicevmc'>
+      <alias name='redir1'/>
+    </redirdev>
+    <memballoon model='virtio'>
+      <alias name='balloon0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+    </memballoon>
+  </devices>
+  <seclabel type='dynamic' model='selinux' relabel='yes'>
+    <label>system_u:system_r:svirt_t:s0:c182,c195</label>
+    <imagelabel>system_u:object_r:svirt_image_t:s0:c182,c195</imagelabel>
+  </seclabel>
+</domain>