diff --git a/code/daisy/daisy/api/backends/kolla/config.py b/code/daisy/daisy/api/backends/kolla/config.py index f327157e..8bda269e 100755 --- a/code/daisy/daisy/api/backends/kolla/config.py +++ b/code/daisy/daisy/api/backends/kolla/config.py @@ -19,11 +19,21 @@ import yaml import random import string import uuid +from oslo_log import log as logging +from daisy import i18n from Crypto.PublicKey import RSA +LOG = logging.getLogger(__name__) +_ = i18n._ +_LE = i18n._LE +_LI = i18n._LI +_LW = i18n._LW + + # generate kolla's ansible inventory multinode file def clean_inventory_file(file_path, filename): + LOG.info(_("begin to clean inventory file for kolla")) fp = open('%s/kolla/ansible/inventory/%s' % (file_path, filename)) txt = fp.read() fp.close() @@ -43,6 +53,7 @@ def clean_inventory_file(file_path, filename): def update_inventory_file(file_path, filename, node_name, host_name, num_of_host, connection_type): + LOG.info(_("begin to update inventory file for kolla...")) fp = file('%s/kolla/ansible/inventory/%s' % (file_path, filename)) lines = [] for line in fp: @@ -58,6 +69,7 @@ def update_inventory_file(file_path, filename, node_name, host_name, def add_role_to_inventory(file_path, config_data): + LOG.info(_("add role to inventory file...")) clean_inventory_file(file_path, 'multinode') host_sequence = 1 for control_ip in config_data['Controller_ips']: @@ -92,16 +104,32 @@ def add_role_to_inventory(file_path, config_data): # generate kolla's globals.yml file def update_globals_yml(config_data): - Version = config_data['Version'] - Namespace = config_data['Namespace'] - VIP = config_data['VIP'] - IntIfMac = config_data['IntIfMac'] - ExtIfMac = config_data['ExtIfMac'] - TulIfMac = config_data['TulIfMac'] - PubIfMac = config_data['PubIfMac'] - StoIfMac = config_data['StoIfMac'] - local_ip = config_data['LocalIP'] - # kolla_yml = yaml.load(file('/etc/kolla/globals.yml')) + LOG.info(_("begin to update kolla's globals.yml file...")) + Version = config_data['Version'].encode() + Namespace = config_data['Namespace'].encode() + VIP = config_data['VIP'].encode() + local_ip = config_data['LocalIP'].encode() + IntIfMac = config_data['IntIfMac'].encode() + if config_data['vlans_id'].get('MANAGEMENT'): + IntIfMac = IntIfMac + '.' + \ + config_data['vlans_id'].get('MANAGEMENT').encode() + ExtIfMac = config_data['ExtIfMac'].encode() + if config_data['vlans_id'].get('EXTERNAL'): + ExtIfMac = ExtIfMac + '.' + \ + config_data['vlans_id'].get('EXTERNAL').encode() + TulIfMac = config_data['TulIfMac'].encode() + if config_data['vlans_id'].get('DATAPLANE'): + TulIfMac = TulIfMac + '.' + \ + config_data['vlans_id'].get('DATAPLANE').encode() + PubIfMac = config_data['PubIfMac'].encode() + if config_data['vlans_id'].get('PUBLICAPI'): + PubIfMac = PubIfMac + '.' + \ + config_data['vlans_id'].get('PUBLICAPI').encode() + StoIfMac = config_data['StoIfMac'].encode() + if config_data['vlans_id'].get('STORAGE'): + StoIfMac = StoIfMac + '.' + \ + config_data['vlans_id'].get('STORAGE').encode() + kolla_yml = {'openstack_release': '3.0.0', 'docker_registry': '127.0.0.1:4000', 'docker_namespace': 'kollaglue', @@ -112,15 +140,15 @@ def update_globals_yml(config_data): 'kolla_external_vip_interface': 'eth0', 'neutron_external_interface': 'eth1' } - kolla_yml['openstack_release'] = Version.encode() - kolla_yml['docker_registry'] = local_ip.encode() - kolla_yml['docker_namespace'] = Namespace.encode() - kolla_yml['kolla_internal_vip_address'] = VIP.encode() - kolla_yml['network_interface'] = IntIfMac.encode() - kolla_yml['tunnel_interface'] = TulIfMac.encode() - kolla_yml['neutron_external_interface'] = ExtIfMac.encode() - kolla_yml['kolla_external_vip_interface'] = PubIfMac.encode() - kolla_yml['storage_interface'] = StoIfMac.encode() + kolla_yml['openstack_release'] = Version + kolla_yml['docker_registry'] = local_ip + kolla_yml['docker_namespace'] = Namespace + kolla_yml['kolla_internal_vip_address'] = VIP + kolla_yml['network_interface'] = IntIfMac + kolla_yml['tunnel_interface'] = TulIfMac + kolla_yml['neutron_external_interface'] = ExtIfMac + kolla_yml['kolla_external_vip_interface'] = PubIfMac + kolla_yml['storage_interface'] = StoIfMac yaml.dump(kolla_yml, file('/etc/kolla/globals.yml', 'w'), default_flow_style=False) @@ -134,6 +162,7 @@ def generate_RSA(bits=2048): def update_password_yml(): + LOG.info(_("begin to update kolla's passwd.yml file...")) # These keys should be random uuids uuid_keys = ['ceph_cluster_fsid', 'rbd_secret_uuid'] diff --git a/code/daisy/daisy/api/backends/kolla/install.py b/code/daisy/daisy/api/backends/kolla/install.py index 1b11501b..568a568e 100644 --- a/code/daisy/daisy/api/backends/kolla/install.py +++ b/code/daisy/daisy/api/backends/kolla/install.py @@ -169,6 +169,7 @@ def get_cluster_kolla_config(req, cluster_id): dat_macname_list = [] ext_macname_list = [] sto_macname_list = [] + vlans_id = {} openstack_version = '3.0.0' docker_namespace = 'kolla' host_name_ip = {} @@ -197,9 +198,13 @@ def get_cluster_kolla_config(req, cluster_id): kolla_openstack_version = line.strip() openstack_version = kolla_openstack_version.split( ": ")[1] + LOG.info(_("openstack version is %s" % openstack_version)) docker_registry_ip = _get_local_ip() docker_registry = docker_registry_ip + ':4000' + LOG.info(_("get cluster network detail...")) cluster_networks = daisy_cmn.get_cluster_networks_detail(req, cluster_id) + for network in cluster_networks: + vlans_id.update({network.get('network_type'): network.get('vlan_id')}) all_roles = kolla_cmn.get_roles_detail(req) roles = [role for role in all_roles if (role['cluster_id'] == cluster_id and @@ -242,6 +247,7 @@ def get_cluster_kolla_config(req, cluster_id): kolla_config.update({'Controller_ips': controller_ip_list}) kolla_config.update({'Network_ips': controller_ip_list}) kolla_config.update({'Storage_ips': controller_ip_list}) + kolla_config.update({'vlans_id': vlans_id}) if role['name'] == 'COMPUTER': role_hosts = kolla_cmn.get_hosts_of_role(req, role['id']) for role_host in role_hosts: @@ -340,6 +346,60 @@ def _get_hosts_id_by_mgnt_ips(req, cluster_id, ips): return hosts_id_needed +def _thread_bin(req, host, root_passwd, fp, host_name_ip_list, + host_prepare_file, docker_registry_ip, role_id_list): + host_ip = host['mgtip'] + cmd = '/var/lib/daisy/trustme.sh %s %s' % \ + (host_ip, root_passwd) + daisy_cmn.subprocess_call(cmd, fp) + config_nodes_hosts(host_name_ip_list, host_ip) + cmd = 'ssh -o StrictHostKeyChecking=no %s \ + "if [ ! -d %s ];then mkdir %s;fi" ' % \ + (host_ip, host_prepare_file, host_prepare_file) + daisy_cmn.subprocess_call(cmd, fp) + cmd = "scp -o ConnectTimeout=10 \ + /var/lib/daisy/kolla/prepare.sh \ + root@%s:%s" % (host_ip, host_prepare_file) + daisy_cmn.subprocess_call(cmd, fp) + cmd = 'ssh -o StrictHostKeyChecking=no %s \ + chmod u+x %s/prepare.sh' % \ + (host_ip, host_prepare_file) + daisy_cmn.subprocess_call(cmd, fp) + try: + exc_result = subprocess.check_output( + 'ssh -o StrictHostKeyChecking=' + 'no %s %s/prepare.sh %s' % + (host_ip, host_prepare_file, docker_registry_ip), + shell=True, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + message = "Prepare install failed!" + update_host_progress_to_db(req, role_id_list, host, + kolla_state['INSTALL_FAILED'], + message) + LOG.info(_("prepare for %s failed!" % host_ip)) + fp.write(e.output.strip()) + exit() + else: + LOG.info(_("prepare for %s successfully!" % host_ip)) + fp.write(exc_result) + message = "Preparing for installation successful!" + update_host_progress_to_db(self.req, role_id_list, host, + kolla_state['INSTALLING'], + message, 10) + + +def thread_bin(req, host, root_passwd, fp, host_name_ip_list, + host_prepare_file, docker_registry_ip, role_id_list): + try: + _thread_bin(req, host, root_passwd, fp, host_name_ip_list, + host_prepare_file, docker_registry_ip, role_id_list) + except Exception as e: + message = "Prepare for installation failed!" + update_host_progress_to_db(req, role_id_list, host, + kolla_state['INSTALL_FAILED'], + message) + + class KOLLAInstallTask(Thread): """ Class for kolla install openstack. @@ -409,7 +469,9 @@ class KOLLAInstallTask(Thread): ssh_host_info = {'ip': mgnt_ip, 'root_pwd': root_passwd} api_cmn.config_network_new(ssh_host_info, 'kolla') time.sleep(20) + LOG.info(_("begin to generate kolla config file ...")) generate_kolla_config_file(self.cluster_id, kolla_config) + LOG.info(_("generate kolla config file in /etc/kolla/ dir...")) (role_id_list, host_id_list, hosts_list) = \ kolla_cmn.get_roles_and_hosts_list(self.req, self.cluster_id) self.message = "Begin install" @@ -418,52 +480,35 @@ class KOLLAInstallTask(Thread): self.message, 0) docker_registry_ip = _get_local_ip() with open(self.log_file, "w+") as fp: + threads = [] for host in hosts_list: - host_ip = host['mgtip'] - cmd = '/var/lib/daisy/trustme.sh %s %s' % \ - (host_ip, root_passwd) - daisy_cmn.subprocess_call(cmd, fp) - config_nodes_hosts(host_name_ip_list, host_ip) - cmd = 'ssh -o StrictHostKeyChecking=no %s \ - "if [ ! -d %s ];then mkdir %s;fi" ' % \ - (host_ip, self.host_prepare_file, self.host_prepare_file) - daisy_cmn.subprocess_call(cmd, fp) - cmd = "scp -o ConnectTimeout=10 \ - /var/lib/daisy/kolla/prepare.sh \ - root@%s:%s" % (host_ip, self.host_prepare_file) - daisy_cmn.subprocess_call(cmd, fp) - cmd = 'ssh -o StrictHostKeyChecking=no %s \ - chmod u+x %s/prepare.sh' % \ - (host_ip, self.host_prepare_file) - daisy_cmn.subprocess_call(cmd, fp) - try: - exc_result = subprocess.check_output( - 'ssh -o StrictHostKeyChecking=' - 'no %s %s/prepare.sh %s' % - (host_ip, self.host_prepare_file, docker_registry_ip), - shell=True, stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as e: - self.message = "Prepare install failed!" - update_host_progress_to_db(self.req, role_id_list, host, - kolla_state['INSTALL_FAILED'], - self.message) - LOG.info(_("prepare for %s failed!" % host_ip)) - fp.write(e.output.strip()) - exit() - else: - LOG.info(_("prepare for %s successfully!" % host_ip)) - fp.write(exc_result) - self.message = "Preparing for installation successful!" - update_host_progress_to_db(self.req, role_id_list, host, - kolla_state['INSTALLING'], - self.message, 10) + t = threading.Thread(target=thread_bin, + args=(self.req, host, root_passwd, fp, + host_name_ip_list, + self.host_prepare_file, + docker_registry_ip, role_id_list)) + t.setDaemon(True) + t.start() + threads.append(t) try: + LOG.info(_("prepare kolla installation threads have started, " + "please waiting....")) + for t in threads: + t.join() + except: + LOG.error("join kolla prepare installation " + "thread %s failed!" % t) + + try: + LOG.info(_("begin to kolla-ansible " + "prechecks for all nodes...")) exc_result = subprocess.check_output( 'cd %s/kolla && ./tools/kolla-ansible prechecks -i ' '%s/kolla/ansible/inventory/multinode' % (self.kolla_file, self.kolla_file), shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: + LOG.error("kolla-ansible preckecks failed!") self.message = "kolla-ansible preckecks failed!" update_all_host_progress_to_db(self.req, role_id_list, host_id_list, @@ -480,6 +525,7 @@ class KOLLAInstallTask(Thread): host_id_list, kolla_state['INSTALLING'], self.message, 20) + LOG.info(_("kolla-ansible begin to deploy openstack ...")) cmd = subprocess.Popen( 'cd %s/kolla && ./tools/kolla-ansible deploy -i ' '%s/kolla/ansible/inventory/multinode' % @@ -502,7 +548,7 @@ class KOLLAInstallTask(Thread): host_id_list, kolla_state['INSTALL_FAILED'], self.message) - LOG.info(_("kolla-ansible deploy failed!")) + LOG.error("kolla-ansible deploy failed!") exit() else: self.progress = _calc_progress(self.log_file) @@ -517,6 +563,7 @@ class KOLLAInstallTask(Thread): self.message, self.progress) execute_times += 1 try: + LOG.info(_("kolla-ansible post-deploy for each node...")) exc_result = subprocess.check_output( 'cd %s/kolla && ./tools/kolla-ansible post-deploy -i ' '%s/kolla/ansible/inventory/multinode' % @@ -528,7 +575,7 @@ class KOLLAInstallTask(Thread): host_id_list, kolla_state['INSTALL_FAILED'], self.message) - LOG.info(_("kolla-ansible post-deploy failed!")) + LOG.error("kolla-ansible post-deploy failed!") fp.write(e.output.strip()) exit() else: