From 24e32399eba20d6b613b654b60b1dcc48a857adc Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Fri, 19 May 2017 09:19:17 +0800 Subject: Use unified vm template files in python deploy script Change-Id: I386011a35a9be3e4f1d468744a6945360bb2adb3 Signed-off-by: Alex Yang --- deploy/environment.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'deploy/environment.py') 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: -- cgit 1.2.3-korg