diff options
author | Alex Yang <yangyang1@zte.com.cn> | 2017-05-19 09:19:17 +0800 |
---|---|---|
committer | Alex Yang <yangyang1@zte.com.cn> | 2017-05-25 13:34:38 +0800 |
commit | 24e32399eba20d6b613b654b60b1dcc48a857adc (patch) | |
tree | 544247100b7428d3e91f693863e52939089779b9 /deploy | |
parent | bfacd100e576a50be19447f7c1b6cea2ac55ebd0 (diff) |
Use unified vm template files in python deploy script
Change-Id: I386011a35a9be3e4f1d468744a6945360bb2adb3
Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
Diffstat (limited to 'deploy')
-rw-r--r-- | deploy/config/schemas.py | 3 | ||||
-rw-r--r-- | deploy/config/vm_environment/zte-virtual1/deploy.yml | 1 | ||||
-rw-r--r-- | deploy/config/vm_environment/zte-virtual2/deploy.yml | 5 | ||||
-rw-r--r-- | deploy/environment.py | 26 |
4 files changed, 32 insertions, 3 deletions
diff --git a/deploy/config/schemas.py b/deploy/config/schemas.py index 7cc2c80e..d2fd7ef6 100644 --- a/deploy/config/schemas.py +++ b/deploy/config/schemas.py @@ -27,7 +27,8 @@ hosts_schema = { 'type': 'string', 'enum': ['COMPUTER', 'CONTROLLER_LB', 'CONTROLLER_HA'] } - } + }, + 'template': {'type': 'string', 'minLength': 1} } } } diff --git a/deploy/config/vm_environment/zte-virtual1/deploy.yml b/deploy/config/vm_environment/zte-virtual1/deploy.yml index 0b3a2c52..a85f429f 100644 --- a/deploy/config/vm_environment/zte-virtual1/deploy.yml +++ b/deploy/config/vm_environment/zte-virtual1/deploy.yml @@ -4,6 +4,7 @@ hosts: roles:
- 'CONTROLLER_LB'
- 'COMPUTER'
+ template: 'templates/virtual_environment/vms/all_in_one.xml'
disks:
daisy: 50
controller: 110
diff --git a/deploy/config/vm_environment/zte-virtual2/deploy.yml b/deploy/config/vm_environment/zte-virtual2/deploy.yml index 646fa130..43b2ed03 100644 --- a/deploy/config/vm_environment/zte-virtual2/deploy.yml +++ b/deploy/config/vm_environment/zte-virtual2/deploy.yml @@ -3,18 +3,23 @@ hosts: - name: 'controller01'
roles:
- 'CONTROLLER_LB'
+ template: 'templates/virtual_environment/vms/controller.xml'
- name: 'controller02'
roles:
- 'CONTROLLER_LB'
+ template: 'templates/virtual_environment/vms/controller.xml'
- name: 'controller03'
roles:
- 'CONTROLLER_LB'
+ template: 'templates/virtual_environment/vms/controller.xml'
- name: 'computer01'
roles:
- 'COMPUTER'
+ template: 'templates/virtual_environment/vms/computer.xml'
- name: 'computer02'
roles:
- 'COMPUTER'
+ template: 'templates/virtual_environment/vms/computer.xml'
disks:
daisy: 50
controller: 110
diff --git a/deploy/environment.py b/deploy/environment.py index d18bf550..2adec494 100644 --- a/deploy/environment.py +++ b/deploy/environment.py @@ -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: |