def _read_console(self): base_dir = utils.get_base_dir() console_log_file = os.path.join( base_dir, "%s-console.log" % constants.PRODUCT_NAME) buf = "" menu_done = False with open(console_log_file, 'ab') as console_log_file: with open(self._console_named_pipe, 'rb') as vm_console_pipe: while True: data = vm_console_pipe.readline() # Exit loop when the VM reboots if not data: LOG.debug("Console: no more data") break # NOTE: Workaround due to formatting issues with menu.c32 # TODO: Needs to be fixed in term.js if not menu_done: buf += data if b'\x1b' not in buf: self._stdout_callback(data) idx = buf.find(b"\x1b[0m") if idx >= 0: self._stdout_callback(buf[idx + len(b"\x1b[0m"):]) menu_done = True buf = b"" LOG.debug("Console: pxelinux menu done") else: self._stdout_callback(data) console_log_file.write(data) # TODO(alexpilotti): Fix why the heck CentOS gets stuck # instead of rebooting and remove this awful workaround :) if data.find("Reached target Shutdown.") != -1: LOG.debug("Console: reached target Shutdown") break if data.find("Warning: Could not boot.") != -1: raise exceptions.CouldNotBootException()
def _deploy_openstack_vm(self, ext_vswitch_name, openstack_vm_vcpu_count, openstack_vm_mem_mb, openstack_base_dir, admin_password, repo_url, mgmt_ext_ip, mgmt_ext_netmask, mgmt_ext_gateway, mgmt_ext_name_servers, proxy_url, proxy_username, proxy_password): vm_name = OPENSTACK_CONTROLLER_VM_NAME vm_admin_user = "******" vm_dir = os.path.join(openstack_base_dir, vm_name) # TODO(alexpilotti): Add support for more OSs pxe_os_id = "centos7" console_named_pipe = r"\\.\pipe\%s" % vm_name iso_path = os.path.join(vm_dir, "ks.iso") self._update_status('Generating SSH key...') (ssh_key_path, ssh_pub_key_path) = self._dep_actions.generate_controller_ssh_key() self._update_status('Generating MD5 password...') encrypted_password = security.get_password_md5(admin_password) if not os.path.isdir(vm_dir): os.makedirs(vm_dir) self._update_status('Check if OpenStack controller VM exists...') self._dep_actions.check_remove_vm(vm_name) self._update_status('Creating virtual switches...') internal_net_config = self._dep_actions.get_internal_network_config() self._dep_actions.create_vswitches(ext_vswitch_name, internal_net_config) vm_network_config = self._dep_actions.get_openstack_vm_network_config( vm_name, ext_vswitch_name) LOG.info("VNIC Network config: %s " % vm_network_config) mgmt_ext_mac_address = self._get_mac_address(vm_network_config, "%s-mgmt-ext" % vm_name) mgmt_int_mac_address = self._get_mac_address(vm_network_config, "%s-mgmt-int" % vm_name) data_mac_address = self._get_mac_address(vm_network_config, "%s-data" % vm_name) ext_mac_address = self._get_mac_address(vm_network_config, "%s-ext" % vm_name) pxe_mac_address = self._get_mac_address(vm_network_config, "%s-pxe" % vm_name) self._dep_actions.create_kickstart_image( iso_path, encrypted_password, mgmt_ext_mac_address, mgmt_int_mac_address, data_mac_address, ext_mac_address, repo_url, ssh_pub_key_path, mgmt_ext_ip, mgmt_ext_netmask, mgmt_ext_gateway, mgmt_ext_name_servers, proxy_url, proxy_username, proxy_password) self._update_status('Creating the OpenStack controller VM...') self._dep_actions.create_openstack_vm(vm_name, vm_dir, openstack_vm_vcpu_count, openstack_vm_mem_mb, None, iso_path, vm_network_config, console_named_pipe) vnic_ip_info = self._dep_actions.get_openstack_vm_ip_info( vm_network_config, internal_net_config["subnet"]) LOG.debug("VNIC PXE IP info: %s " % vnic_ip_info) self._update_status('Starting PXE daemons...') self._dep_actions.start_pxe_service( internal_net_config["host_ip"], [vnic_ip[1:] for vnic_ip in vnic_ip_info], pxe_os_id) self._dep_actions.generate_mac_pxelinux_cfg( pxe_mac_address, mgmt_ext_mac_address.replace('-', ':'), repo_url, mgmt_ext_ip, mgmt_ext_netmask, mgmt_ext_gateway, mgmt_ext_name_servers, proxy_url, proxy_username, proxy_password) self._update_status('PXE booting OpenStack controller VM...') self._dep_actions.start_openstack_vm() LOG.debug("Reading from console") console_thread = _VMConsoleThread(console_named_pipe, self._stdout_callback) console_thread.start() console_thread.join() ex = console_thread.get_exception() if ex: if isinstance(ex, exceptions.CouldNotBootException): raise exceptions.CouldNotBootException( 'Unable to deploy the controller VM. Make sure that DHCP ' 'is enabled on the "{0}" network and that the repository ' '"{1}" is accessible'.format(ext_vswitch_name, repo_url)) else: raise ex self._update_status('Rebooting OpenStack controller VM...') self._dep_actions.reboot_openstack_vm() LOG.info("PXE booting done") vm_int_mgmt_ip = [ vnic_ip[2] for vnic_ip in vnic_ip_info if vnic_ip[0] == "%s-mgmt-int" % vm_name ][0] return (vm_int_mgmt_ip, vm_admin_user, ssh_key_path)