def _query_iscsi_lunid(self, username, password, portal, port, target): iscsi_getdevices_vars = { 'he_fqdn': self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'he_host_name': self.environment[ohostedcons.EngineEnv.APP_HOST_NAME], 'he_admin_password': self.environment[ohostedcons.EngineEnv.ADMIN_PASSWORD], 'he_iscsi_username': username, 'he_iscsi_password': password, 'he_iscsi_portal_addr': portal, 'he_iscsi_portal_port': port, 'he_iscsi_target': target, } ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_ISCSI_GETDEVICES, extra_vars=iscsi_getdevices_vars, ) self.logger.info(_('Getting iSCSI LUNs list')) r = ah.run() self.logger.debug(r) available_luns = [] if ('otopi_iscsi_devices' in r and 'ansible_facts' in r['otopi_iscsi_devices'] and 'ovirt_host_storages' in r['otopi_iscsi_devices']['ansible_facts']): available_luns = r['otopi_iscsi_devices']['ansible_facts'][ 'ovirt_host_storages'] return self._select_lun(available_luns)
def _query_fc_lunid(self): fc_getdevices_vars = { 'he_fqdn': self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'he_host_name': self.environment[ohostedcons.EngineEnv.APP_HOST_NAME], 'he_admin_password': self.environment[ohostedcons.EngineEnv.ADMIN_PASSWORD] } ansible_helper = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_FC_GETDEVICES, extra_vars=fc_getdevices_vars, user_extra_vars=self.environment.get( ohostedcons.CoreEnv.ANSIBLE_USER_EXTRA_VARS), ) self.logger.info(_('Getting Fibre Channel LUNs list')) r = ansible_helper.run() self.logger.debug(r) available_luns = [] if ('otopi_fc_devices' in r): if ('ansible_facts' in r['otopi_fc_devices'] and 'ovirt_host_storages' in r['otopi_fc_devices']['ansible_facts']): available_luns = r['otopi_fc_devices']['ansible_facts'][ 'ovirt_host_storages'] elif ('ovirt_host_storages' in r['otopi_fc_devices']): available_luns = r['otopi_fc_devices']['ovirt_host_storages'] return self._select_lun(available_luns)
def _customization(self): validValues = [] ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_NETWORK_INTERFACES, extra_vars={'he_just_collect_network_interfaces': True}, ) r = ah.run() self.logger.debug(r) try: validValues = r['otopi_host_net']['ansible_facts'][ 'otopi_host_net'] except KeyError: raise RuntimeError(_('No suitable network interfaces were found')) if not validValues: raise RuntimeError(_('A Network interface is required')) interactive = self.environment[ ohostedcons.NetworkEnv.BRIDGE_IF] is None if interactive: default = self._get_active_interface(validValues) self.environment[ ohostedcons.NetworkEnv.BRIDGE_IF] = self.dialog.queryString( name='ovehosted_bridge_if', note=_( 'Please indicate a nic to set ' '{bridge} bridge on: (@VALUES@) [@DEFAULT@]: ').format( bridge=self.environment[ ohostedcons.NetworkEnv.BRIDGE_NAME]), prompt=True, caseSensitive=True, default=default, validValues=validValues, )
def _query_fc_lunid(self): fc_getdevices_vars = { 'FQDN': self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN ], 'HOST_NAME': self.environment[ ohostedcons.EngineEnv.APP_HOST_NAME ], 'ADMIN_PASSWORD': self.environment[ ohostedcons.EngineEnv.ADMIN_PASSWORD ] } ansible_helper = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_FC_GETDEVICES, extra_vars=fc_getdevices_vars, ) self.logger.info(_('Getting Fibre Channel LUNs list')) r = ansible_helper.run() self.logger.debug(r) available_luns = [] if ( 'otopi_fc_devices' in r and 'ansible_facts' in r['otopi_fc_devices'] and 'ovirt_host_storages' in r['otopi_fc_devices']['ansible_facts'] ): available_luns = r[ 'otopi_fc_devices' ][ 'ansible_facts' ]['ovirt_host_storages'] return self._select_lun(available_luns)
def initial_clean_up(self, bootstrap_vars, inventory_source): ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_INITIAL_CLEAN, extra_vars=bootstrap_vars, inventory_source=inventory_source, ) self.logger.info(_('Cleaning previous attempts')) r = ah.run() self.logger.debug(r)
def initial_clean_up(self, bootstrap_vars, inventory_source): ah = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_INITIAL_CLEAN, extra_vars=bootstrap_vars, inventory_source=inventory_source, ) self.logger.info(_('Cleaning previous attempts')) r = ah.run() self.logger.debug(r)
def initial_clean_up(self, bootstrap_vars, inventory_source): ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_INITIAL_CLEAN, extra_vars=bootstrap_vars, user_extra_vars=self.environment.get( ohostedcons.CoreEnv.ANSIBLE_USER_EXTRA_VARS), inventory_source=inventory_source, ) self.logger.info(_('Cleaning previous attempts')) r = ah.run() self.logger.debug(r)
def _cleanup(self): ah = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_FINAL_CLEAN, extra_vars={ 'LOCAL_VM_DIR': self.environment[ohostedcons.CoreEnv.LOCAL_VM_DIR], }, inventory_source='localhost,', ) self.logger.info(_('Cleaning temporary resources')) r = ah.run() self.logger.debug(r)
def _cleanup(self): ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_FINAL_CLEAN, extra_vars={ 'he_local_vm_dir': self.environment[ohostedcons.CoreEnv.LOCAL_VM_DIR], }, inventory_source='localhost,', ) self.logger.info(_('Cleaning temporary resources')) r = ah.run() self.logger.debug(r)
def _cleanup(self): ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_FINAL_CLEAN, extra_vars={ 'he_appliance_password': self.environment[ohostedcons.CloudInit.ROOTPWD], 'he_fqdn': self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'he_local_vm_dir': self.environment[ohostedcons.CoreEnv.LOCAL_VM_DIR], }, user_extra_vars=self.environment.get( ohostedcons.CoreEnv.ANSIBLE_USER_EXTRA_VARS), inventory_source='localhost,', ) self.logger.info(_('Cleaning temporary resources')) r = ah.run() self.logger.debug(r)
def _query_iscsi_lunid(self, username, password, portal, port, target): iscsi_getdevices_vars = { 'FQDN': self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN ], 'HOST_NAME': self.environment[ ohostedcons.EngineEnv.APP_HOST_NAME ], 'ADMIN_PASSWORD': self.environment[ ohostedcons.EngineEnv.ADMIN_PASSWORD ], 'ISCSI_USERNAME': username, 'ISCSI_PASSWORD': password, 'ISCSI_PORTAL_ADDR': portal, 'ISCSI_PORTAL_PORT': port, 'ISCSI_TARGET': target, } ah = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_ISCSI_GETDEVICES, extra_vars=iscsi_getdevices_vars, ) self.logger.info(_('Getting iSCSI LUNs list')) r = ah.run() self.logger.debug(r) available_luns = [] if ( 'otopi_iscsi_devices' in r and 'ansible_facts' in r['otopi_iscsi_devices'] and 'ovirt_host_storages' in r['otopi_iscsi_devices']['ansible_facts'] ): available_luns = r[ 'otopi_iscsi_devices' ][ 'ansible_facts' ]['ovirt_host_storages'] return self._select_lun(available_luns)
def _closeup(self): # TODO: use just env values bootstrap_vars = { 'he_appliance_ova': self.environment[ohostedcons.VMEnv.OVF], 'he_fqdn': self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'he_vm_mac_addr': self.environment[ohostedcons.VMEnv.MAC_ADDR], 'he_cloud_init_domain_name': self.environment[ohostedcons.CloudInit.INSTANCE_DOMAINNAME], 'he_cloud_init_host_name': self.environment[ohostedcons.CloudInit.INSTANCE_HOSTNAME], 'he_host_name': self.environment[ohostedcons.EngineEnv.APP_HOST_NAME], 'he_host_address': self.environment[ohostedcons.NetworkEnv.HOST_NAME], 'he_local_vm_dir_path': (ohostedcons.FileLocations.LOCAL_VM_DIR_PATH), 'he_local_vm_dir_prefix': (ohostedcons.FileLocations.LOCAL_VM_DIR_PREFIX), 'he_admin_password': self.environment[ohostedcons.EngineEnv.ADMIN_PASSWORD], 'he_appliance_password': self.environment[ohostedcons.CloudInit.ROOTPWD], 'he_time_zone': self.environment[ohostedcons.CloudInit.VM_TZ], 'he_cdrom_uuid': self.environment[ohostedcons.VMEnv.CDROM_UUID], 'he_nic_uuid': self.environment[ohostedcons.VMEnv.NIC_UUID], 'he_maxvcpus': self.environment[ohostedcons.VMEnv.MAXVCPUS], 'he_vm_name': ohostedcons.Const.HOSTED_ENGINE_VM_NAME, 'he_mem_size_MB': self.environment[ohostedcons.VMEnv.MEM_SIZE_MB], 'he_vcpus': self.environment[ohostedcons.VMEnv.VCPUS], 'he_emulated_machine': self.environment[ohostedcons.VMEnv.EMULATED_MACHINE], 'he_vm_uuid': self.environment[ohostedcons.VMEnv.LOCAL_VM_UUID], 'he_vm_etc_hosts': self.environment[ohostedcons.CloudInit.VM_ETC_HOSTS], 'he_root_ssh_pubkey': self.environment[ohostedcons.CloudInit.ROOT_SSH_PUBKEY], 'he_root_ssh_access': self.environment[ohostedcons.CloudInit.ROOT_SSH_ACCESS].lower(), 'he_apply_openscap_profile': self.environment[ohostedcons.CloudInit.APPLY_OPENSCAP_PROFILE], 'he_enable_libgfapi': self.environment[ohostedcons.StorageEnv.ENABLE_LIBGFAPI], 'he_enable_hc_gluster_service': self.environment[ohostedcons.StorageEnv.ENABLE_HC_GLUSTER_SERVICE], 'he_bridge_if': self.environment[ohostedcons.NetworkEnv.BRIDGE_IF], 'he_restore_from_file': self.environment[ohostedcons.CoreEnv.RESTORE_FROM_FILE], 'he_storage_domain_name': self.environment[ohostedcons.StorageEnv.STORAGE_DOMAIN_NAME], 'he_data_center': self.environment[ohostedcons.EngineEnv.HOST_DATACENTER_NAME], 'he_cluster': self.environment[ohostedcons.EngineEnv.HOST_CLUSTER_NAME], 'he_requirements_check_enabled': self.environment[ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED], 'he_memory_requirements_check_enabled': self.environment[ ohostedcons.CoreEnv.MEM_REQUIREMENTS_CHECK_ENABLED], 'he_force_ip4': self.environment[ohostedcons.NetworkEnv.FORCE_IPV4], 'he_force_ip6': self.environment[ohostedcons.NetworkEnv.FORCE_IPV6], 'he_network_test': self.environment[ohostedcons.NetworkEnv.NETWORK_TEST], 'he_tcp_t_address': self.environment[ohostedcons.NetworkEnv.NETWORK_TEST_TCP_ADDRESS], 'he_tcp_t_port': self.environment[ohostedcons.NetworkEnv.NETWORK_TEST_TCP_PORT] } if self.environment[ ohostedcons.CoreEnv.RENEW_PKI_ON_RESTORE] is not None: bootstrap_vars['he_pki_renew_on_restore'] = self.environment[ ohostedcons.CoreEnv.RENEW_PKI_ON_RESTORE] if self.environment[ohostedcons.CoreEnv.PAUSE_ON_RESTORE] is not None: bootstrap_vars['he_pause_host'] = self.environment[ ohostedcons.CoreEnv.PAUSE_ON_RESTORE] inventory_source = 'localhost,{fqdn}'.format(fqdn=self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN]) self.initial_clean_up(bootstrap_vars, inventory_source) ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_BOOTSTRAP_LOCAL_VM, extra_vars=bootstrap_vars, user_extra_vars=self.environment.get( ohostedcons.CoreEnv.ANSIBLE_USER_EXTRA_VARS), inventory_source=inventory_source, raise_on_error=False, ) self.logger.info(_('Starting local VM')) r = ah.run() self.logger.debug(r) if ('otopi_localvm_dir' in r and 'path' in r['otopi_localvm_dir']): self.environment[ohostedcons.CoreEnv. LOCAL_VM_DIR] = r['otopi_localvm_dir']['path'] else: raise RuntimeError(_('Failed getting local_vm_dir')) try: vsize = r['otopi_appliance_disk_size']['ansible_facts'][ 'virtual_size'] self.environment[ ohostedcons.StorageEnv. OVF_SIZE_GB] = int(vsize) // 1024 // 1024 // 1024 + 1 except KeyError: raise RuntimeError(_('Unable to get appliance disk size')) # TODO: get the CPU models list from /ovirt-engine/api/clusterlevels # once wrapped by ansible facts and filter it by host CPU architecture # in order to let the user choose the cluster CPU type in advance if r['ansible-playbook_rc'] != 0: raise RuntimeError(_('Failed executing ansible-playbook'))
def _query_iscsi_target( self, discover_username, discover_password, portal, port ): iscsi_discover_vars = { 'FQDN': self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN ], 'HOST_NAME': self.environment[ ohostedcons.EngineEnv.APP_HOST_NAME ], 'ADMIN_PASSWORD': self.environment[ ohostedcons.EngineEnv.ADMIN_PASSWORD ], 'ISCSI_DISCOVER_USERNAME': discover_username, 'ISCSI_DISCOVER_PASSWORD': discover_password, 'ISCSI_PORTAL_ADDR': portal, 'ISCSI_PORTAL_PORT': port, } ah = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_ISCSI_DISCOVER, extra_vars=iscsi_discover_vars, ) self.logger.info(_('Discovering iSCSI targets')) r = ah.run() self.logger.debug(r) try: values = r[ 'otopi_iscsi_targets' ]['json']['discovered_targets']['iscsi_details'] except KeyError: raise RuntimeError(_('Unable to find any target')) self.logger.debug(values) f_targets = [] found = {} for v in values: self.logger.debug(v) target = v['target'] tpgt = v['portal'].split(',')[1] if target not in found: found[target] = {} if tpgt not in found[target]: found[target][tpgt] = [] found[target][tpgt].append( { 'address': v['address'], 'port': v['port'] } ) self.logger.debug(found) for target in found: for tpgt in found[target]: f_targets.append( { 'index': str(len(f_targets)+1), 'target': target, 'tpgt': tpgt, 'address_port_l': found[target][tpgt] } ) target_list = '' for entry in f_targets: target_list += _( '\t[{index}]\t{target}\n\t\tTPGT: {tpgt}, portals:\n' ).format( index=entry['index'], target=entry['target'], tpgt=entry['tpgt'], ) for pp in entry['address_port_l']: target_list += _( '\t\t\t{portal}:{port}\n' ).format( portal=pp['address'], port=pp['port'], ) target_list += '\n' self.dialog.note( _( 'The following targets have been found:\n' '{target_list}' ).format( target_list=target_list, ) ) s_target = self.dialog.queryString( name='OVEHOSTED_STORAGE_ISCSI_TARGET', note=_( 'Please select a target ' '(@VALUES@) [@DEFAULT@]: ' ), prompt=True, caseSensitive=True, default='1', validValues=[i['index'] for i in f_targets], ) apl = f_targets[int(s_target)-1]['address_port_l'] return ( f_targets[int(s_target)-1]['target'], f_targets[int(s_target)-1]['tpgt'], ','.join([x['address'] for x in apl]), ','.join([x['port'] for x in apl]), )
def _closeup(self): created = False interactive = True if (self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] is not None or self.environment[ohostedcons.StorageEnv. STORAGE_DOMAIN_CONNECTION] is not None or self.environment[ohostedcons.StorageEnv.MNT_OPTIONS] is not None or self.environment[ohostedcons.StorageEnv.NFS_VERSION] is not None or self.environment[ohostedcons.StorageEnv.ISCSI_IP_ADDR] is not None or self.environment[ohostedcons.StorageEnv.ISCSI_PORT] is not None or self.environment[ohostedcons.StorageEnv.ISCSI_USER] is not None or self.environment[ohostedcons.StorageEnv.ISCSI_PASSWORD] is not None or self.environment[ohostedcons.StorageEnv.ISCSI_TARGET] is not None or self.environment[ohostedcons.StorageEnv.ISCSI_TARGET] is not None): interactive = False while not created: domain_type = self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] storage_domain_connection = self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION] storage_domain_address = None storage_domain_path = None mnt_options = self.environment[ohostedcons.StorageEnv.MNT_OPTIONS] nfs_version = self.environment[ohostedcons.StorageEnv.NFS_VERSION] iscsi_portal = self.environment[ ohostedcons.StorageEnv.ISCSI_IP_ADDR] iscsi_port = self.environment[ohostedcons.StorageEnv.ISCSI_PORT] iscsi_username = self.environment[ ohostedcons.StorageEnv.ISCSI_USER] iscsi_password = self.environment[ ohostedcons.StorageEnv.ISCSI_PASSWORD] iscsi_discover_username = self.environment[ ohostedcons.StorageEnv.ISCSI_DISCOVER_USER] iscsi_discover_password = self.environment[ ohostedcons.StorageEnv.ISCSI_DISCOVER_PASSWORD] iscsi_target = self.environment[ ohostedcons.StorageEnv.ISCSI_TARGET] lunid = self.environment[ohostedcons.StorageEnv.LUN_ID] discard = self.environment[ohostedcons.StorageEnv.DISCARD_SUPPORT] if domain_type is None: domain_type = self.dialog.queryString( name='OVEHOSTED_STORAGE_DOMAIN_TYPE', note=_('Please specify the storage ' 'you would like to use (@VALUES@)[@DEFAULT@]: '), prompt=True, caseSensitive=True, validValues=( ohostedcons.DomainTypes.GLUSTERFS, ohostedcons.DomainTypes.ISCSI, ohostedcons.DomainTypes.FC, ohostedcons.DomainTypes.NFS, ), default=ohostedcons.DomainTypes.NFS, ) else: if domain_type == ohostedcons.DomainTypes.NFS3: domain_type = ohostedcons.DomainTypes.NFS self.environment[ohostedcons.StorageEnv. NFS_VERSION] = ohostedcons.NfsVersions.V3 elif domain_type == ohostedcons.DomainTypes.NFS4: domain_type = ohostedcons.DomainTypes.NFS self.environment[ohostedcons.StorageEnv. NFS_VERSION] = ohostedcons.NfsVersions.V4 if domain_type == ohostedcons.DomainTypes.NFS: if nfs_version is None: nfs_version = self._query_nfs_version() if (domain_type == ohostedcons.DomainTypes.NFS or domain_type == ohostedcons.DomainTypes.GLUSTERFS): path_test = '^(.+):/(.+)$' if storage_domain_connection is None: storage_domain_connection = self._query_connection_path() pmatch = re.match(path_test, storage_domain_connection.strip()) valid = False if pmatch and len(pmatch.groups()) == 2: t_storage_domain_address = pmatch.group(1) t_storage_domain_path = pmatch.group(2) valid = True if (':' in t_storage_domain_address and (t_storage_domain_address[0] != '[' or t_storage_domain_address[-1] != ']')): valid = False if not valid: msg = _('Invalid connection path: {p}').format( p=storage_domain_connection, ) self.logger.error(msg) if not interactive: raise RuntimeError(msg) continue storage_domain_address = t_storage_domain_address storage_domain_path = '/{p}'.format(p=t_storage_domain_path) if mnt_options is None: mnt_options = self._query_mnt_options(mnt_options) elif domain_type == ohostedcons.DomainTypes.ISCSI: if iscsi_portal is None: iscsi_portal = self._query_iscsi_portal() if iscsi_port is None: iscsi_port = self._query_iscsi_port() if iscsi_discover_username is None: iscsi_discover_username = self._query_iscsi_username( discover=True) if iscsi_discover_password is None: iscsi_discover_password = self._query_iscsi_password( discover=True) if iscsi_username is None: iscsi_username = self._query_iscsi_username(discover=False) if iscsi_password is None: iscsi_password = self._query_iscsi_password(discover=False) if iscsi_target is None: try: iscsi_target, iscsi_tpgt, iscsi_portal, iscsi_port = \ self._query_iscsi_target( discover_username=iscsi_discover_username, discover_password=iscsi_discover_password, portal=iscsi_portal, port=iscsi_port, ) except RuntimeError as e: self.logger.error(_('Unable to get target list')) if not interactive: raise e continue if lunid is None: try: lun = self._query_iscsi_lunid(username=iscsi_username, password=iscsi_password, portal=iscsi_portal, port=iscsi_port, target=iscsi_target) lunid = lun['id'] discard = lun['discard_max_size'] > 0 self.logger.info( _("iSCSI discard after delete is {v}").format( v=_("enabled") if discard else _("disabled"))) except RuntimeError as e: self.logger.error(_('Unable to get target list')) if not interactive: raise e continue storage_domain_address = iscsi_portal.split(',')[0] elif domain_type == ohostedcons.DomainTypes.FC: if lunid is None: try: lun = self._query_fc_lunid() lunid = lun['id'] discard = lun['discard_max_size'] > 0 self.logger.info( _("FC discard after delete is {v}").format( v=_("enabled") if discard else _("disabled"))) except RuntimeError as e: self.logger.error(_('Unable to get target list')) if not interactive: raise e continue else: self.logger.error(_('Currently not implemented')) if not interactive: raise RuntimeError('Currently not implemented') continue storage_domain_vars = { 'he_fqdn': self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'he_host_name': self.environment[ohostedcons.EngineEnv.APP_HOST_NAME], 'he_admin_password': self.environment[ohostedcons.EngineEnv.ADMIN_PASSWORD], 'he_local_vm_dir': self.environment[ohostedcons.CoreEnv.LOCAL_VM_DIR], 'he_storage_domain_name': self.environment[ohostedcons.StorageEnv.STORAGE_DOMAIN_NAME], 'he_storage_domain_addr': storage_domain_address, 'he_storage_domain_path': storage_domain_path, 'he_mount_options': mnt_options, 'he_nfs_version': nfs_version, 'he_domain_type': domain_type, 'he_iscsi_portal_port': iscsi_port, 'he_iscsi_target': iscsi_target, 'he_lun_id': lunid, 'he_iscsi_username': iscsi_username, 'he_iscsi_password': iscsi_password, 'he_discard': discard, } ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_CREATE_SD, extra_vars=storage_domain_vars, user_extra_vars=self.environment.get( ohostedcons.CoreEnv.ANSIBLE_USER_EXTRA_VARS), ) self.logger.info(_('Creating Storage Domain')) try: r = ah.run() except RuntimeError as e: if not interactive: raise e continue self.logger.debug('Create storage domain results {r}'.format(r=r)) if ('otopi_storage_domain_details' in r and 'storagedomain' in r['otopi_storage_domain_details']): storage_domain = r['otopi_storage_domain_details'][ 'storagedomain'] self.environment[ohostedcons.StorageEnv.BDEVICE_SIZE_GB] = int( storage_domain['available']) / 1024 / 1024 / 1024 if storage_domain['status'] == 'active': created = True # and set all the env values from the response storage = storage_domain['storage'] storage_type = storage['type'] if storage_type == "fcp": storage_type = "fc" # Normalize type for HE broker. self.environment[ ohostedcons.StorageEnv.DOMAIN_TYPE] = storage_type if self.environment[ ohostedcons.StorageEnv. DOMAIN_TYPE] == ohostedcons.DomainTypes.NFS: # workaround for https://bugzilla.redhat.com/1688982 address = storage['address'] if ":" in address and address[0] != "[": address = "[{a}]".format(a=address) self.environment[ ohostedcons.StorageEnv. STORAGE_DOMAIN_CONNECTION] = '{address}:{path}'.format( address=address, path=storage['path'], ) # TODO: any way to get it from the engine self.environment[ ohostedcons.StorageEnv.MNT_OPTIONS] = mnt_options self.environment[ohostedcons.StorageEnv. NFS_VERSION] = storage['nfs_version'] if self.environment[ ohostedcons.StorageEnv. DOMAIN_TYPE] == ohostedcons.DomainTypes.GLUSTERFS: self.environment[ ohostedcons.StorageEnv. STORAGE_DOMAIN_CONNECTION] = '{address}:{path}'.format( address=storage['address'], path=storage['path'], ) self.environment[ ohostedcons.StorageEnv.MNT_OPTIONS] = mnt_options if self.environment[ ohostedcons.StorageEnv. DOMAIN_TYPE] == ohostedcons.DomainTypes.ISCSI: self.logger.info( _('iSCSI connected paths: {n}').format(n=len( storage['volume_group']['logical_units']))) self.environment[ ohostedcons.StorageEnv. ISCSI_PORTAL] = storage['volume_group'][ 'logical_units'][0]['portal'].split(',')[1] lun0 = storage['volume_group']['logical_units'][0] self.environment[ ohostedcons.StorageEnv.ISCSI_IP_ADDR] = ','.join([ x['address'] for x in storage['volume_group'] ['logical_units'] ]) self.environment[ ohostedcons.StorageEnv. STORAGE_DOMAIN_CONNECTION] = self.environment[ ohostedcons.StorageEnv.ISCSI_IP_ADDR] self.environment[ ohostedcons.StorageEnv.ISCSI_PORT] = ','.join([ str(x['port']) for x in storage['volume_group'] ['logical_units'] ]) self.environment[ohostedcons.StorageEnv. ISCSI_TARGET] = lun0['target'] self.environment[ ohostedcons.StorageEnv.LUN_ID] = lun0['id'] self.environment[ ohostedcons.StorageEnv.ISCSI_USER] = iscsi_username self.environment[ohostedcons.StorageEnv. ISCSI_PASSWORD] = iscsi_password else: if not interactive: raise RuntimeError('Failed creating storage domain') else: if not interactive: raise RuntimeError('Failed creating storage domain')
def _closeup(self): # TODO: use just env values bootstrap_vars = { 'APPLIANCE_OVA': self.environment[ohostedcons.VMEnv.OVF], 'FQDN': self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'VM_MAC_ADDR': self.environment[ohostedcons.VMEnv.MAC_ADDR], 'CLOUD_INIT_DOMAIN_NAME': self.environment[ohostedcons.CloudInit.INSTANCE_DOMAINNAME], 'CLOUD_INIT_HOST_NAME': self.environment[ohostedcons.CloudInit.INSTANCE_HOSTNAME], 'HOST_NAME': self.environment[ohostedcons.EngineEnv.APP_HOST_NAME], 'HOST_ADDRESS': self.environment[ohostedcons.NetworkEnv.HOST_NAME], 'LOCAL_VM_DIR_PATH': ohostedcons.FileLocations.LOCAL_VM_DIR_PATH, 'LOCAL_VM_DIR_PREFIX': (ohostedcons.FileLocations.LOCAL_VM_DIR_PREFIX), 'ADMIN_PASSWORD': self.environment[ohostedcons.EngineEnv.ADMIN_PASSWORD], 'APPLIANCE_PASSWORD': self.environment[ohostedcons.CloudInit.ROOTPWD], 'TIME_ZONE': self.environment[ohostedcons.CloudInit.VM_TZ], 'VM_NAME': ohostedcons.Const.HOSTED_ENGINE_VM_NAME, 'MEM_SIZE': self.environment[ohostedcons.VMEnv.MEM_SIZE_MB], 'CDROM_UUID': self.environment[ohostedcons.VMEnv.CDROM_UUID], 'CDROM': '', 'NIC_UUID': self.environment[ohostedcons.VMEnv.NIC_UUID], 'CONSOLE_UUID': '', 'CONSOLE_TYPE': 'vnc', 'VIDEO_DEVICE': 'vga', 'GRAPHICS_DEVICE': 'vnc', 'VCPUS': self.environment[ohostedcons.VMEnv.VCPUS], 'MAXVCPUS': self.environment[ohostedcons.VMEnv.MAXVCPUS], 'CPU_SOCKETS': '1', 'EMULATED_MACHINE': self.environment[ohostedcons.VMEnv.EMULATED_MACHINE], 'VM_UUID': self.environment[ohostedcons.VMEnv.LOCAL_VM_UUID], 'VM_ETC_HOSTS': self.environment[ohostedcons.CloudInit.VM_ETC_HOSTS], 'ROOT_SSH_PUBKEY': self.environment[ohostedcons.CloudInit.ROOT_SSH_PUBKEY], 'HOST_IP': self.environment[ohostedcons.CloudInit.HOST_IP], 'ROOT_SSH_ACCESS': self.environment[ohostedcons.CloudInit.ROOT_SSH_ACCESS].lower(), 'ENABLE_LIBGFAPI': self.environment[ohostedcons.StorageEnv.ENABLE_LIBGFAPI], 'ENABLE_HC_GLUSTER_SERVICE': self.environment[ohostedcons.StorageEnv.ENABLE_HC_GLUSTER_SERVICE], 'BRIDGE_IF': self.environment[ohostedcons.NetworkEnv.BRIDGE_IF] } inventory_source = 'localhost, {fqdn}'.format(fqdn=self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN]) self.initial_clean_up(bootstrap_vars, inventory_source) ah = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_BOOTSTRAP_LOCAL_VM, extra_vars=bootstrap_vars, inventory_source=inventory_source, ) self.logger.info(_('Starting local VM')) r = ah.run() self.logger.debug(r) if ('otopi_localvm_dir' in r and 'path' in r['otopi_localvm_dir']): self.environment[ohostedcons.CoreEnv. LOCAL_VM_DIR] = r['otopi_localvm_dir']['path'] else: raise RuntimeError(_('Failed getting local_vm_dir')) try: vsize = r['otopi_appliance_disk_size']['ansible_facts'][ 'virtual_size'] self.environment[ohostedcons.StorageEnv. OVF_SIZE_GB] = int(vsize) / 1024 / 1024 / 1024 except KeyError: raise RuntimeError(_('Unable to get appliance disk size'))
def _closeup(self): created = False interactive = True if ( self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] is not None or self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION ] is not None or self.environment[ohostedcons.StorageEnv.MNT_OPTIONS] is not None or self.environment[ohostedcons.StorageEnv.NFS_VERSION] is not None or self.environment[ ohostedcons.StorageEnv.ISCSI_IP_ADDR ] is not None or self.environment[ ohostedcons.StorageEnv.ISCSI_PORT ] is not None or self.environment[ ohostedcons.StorageEnv.ISCSI_USER ] is not None or self.environment[ ohostedcons.StorageEnv.ISCSI_PASSWORD ] is not None or self.environment[ ohostedcons.StorageEnv.ISCSI_TARGET ] is not None or self.environment[ ohostedcons.StorageEnv.ISCSI_TARGET ] is not None ): interactive = False while not created: domain_type = self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] storage_domain_connection = self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION ] storage_domain_address = None storage_domain_path = None mnt_options = self.environment[ ohostedcons.StorageEnv.MNT_OPTIONS ] nfs_version = self.environment[ ohostedcons.StorageEnv.NFS_VERSION ] iscsi_portal = self.environment[ ohostedcons.StorageEnv.ISCSI_IP_ADDR ] iscsi_port = self.environment[ ohostedcons.StorageEnv.ISCSI_PORT ] iscsi_username = self.environment[ ohostedcons.StorageEnv.ISCSI_USER ] iscsi_password = self.environment[ ohostedcons.StorageEnv.ISCSI_PASSWORD ] iscsi_discover_username = self.environment[ ohostedcons.StorageEnv.ISCSI_DISCOVER_USER ] iscsi_discover_password = self.environment[ ohostedcons.StorageEnv.ISCSI_DISCOVER_PASSWORD ] iscsi_target = self.environment[ ohostedcons.StorageEnv.ISCSI_TARGET ] lunid = self.environment[ ohostedcons.StorageEnv.LUN_ID ] discard = True if domain_type is None: domain_type = self.dialog.queryString( name='OVEHOSTED_STORAGE_DOMAIN_TYPE', note=_( 'Please specify the storage ' 'you would like to use (@VALUES@)[@DEFAULT@]: ' ), prompt=True, caseSensitive=True, validValues=( ohostedcons.DomainTypes.GLUSTERFS, ohostedcons.DomainTypes.ISCSI, ohostedcons.DomainTypes.FC, ohostedcons.DomainTypes.NFS, ), default=ohostedcons.DomainTypes.NFS, ) else: if domain_type == ohostedcons.DomainTypes.NFS3: domain_type = ohostedcons.DomainTypes.NFS self.environment[ ohostedcons.StorageEnv.NFS_VERSION ] = ohostedcons.NfsVersions.V3 elif domain_type == ohostedcons.DomainTypes.NFS4: domain_type = ohostedcons.DomainTypes.NFS self.environment[ ohostedcons.StorageEnv.NFS_VERSION ] = ohostedcons.NfsVersions.V4 if domain_type == ohostedcons.DomainTypes.NFS: if nfs_version is None: nfs_version = self._query_nfs_version() if ( domain_type == ohostedcons.DomainTypes.NFS or domain_type == ohostedcons.DomainTypes.GLUSTERFS ): if storage_domain_connection is None: storage_domain_connection = self._query_connection_path() storage_domain_det = storage_domain_connection.split(':') if len(storage_domain_det) != 2: msg = _('Invalid connection path') self.logger.error(msg) if not interactive: raise RuntimeError(msg) continue storage_domain_address = storage_domain_det[0] storage_domain_path = storage_domain_det[1] if mnt_options is None: mnt_options = self._query_mnt_options(mnt_options) elif domain_type == ohostedcons.DomainTypes.ISCSI: if iscsi_portal is None: iscsi_portal = self._query_iscsi_portal() if iscsi_port is None: iscsi_port = self._query_iscsi_port() if iscsi_discover_username is None: iscsi_discover_username = self._query_iscsi_username( discover=True ) if iscsi_discover_password is None: iscsi_discover_password = self._query_iscsi_password( discover=True ) if iscsi_username is None: iscsi_username = self._query_iscsi_username( discover=False ) if iscsi_password is None: iscsi_password = self._query_iscsi_password( discover=False ) if iscsi_target is None: try: iscsi_target, iscsi_tpgt, iscsi_portal, iscsi_port = \ self._query_iscsi_target( discover_username=iscsi_discover_username, discover_password=iscsi_discover_password, portal=iscsi_portal, port=iscsi_port, ) storage_domain_address = iscsi_portal.split(',')[0] except RuntimeError as e: self.logger.error(_('Unable to get target list')) if not interactive: raise e continue if lunid is None: try: lun = self._query_iscsi_lunid( username=iscsi_username, password=iscsi_password, portal=iscsi_portal, port=iscsi_port, target=iscsi_target ) lunid = lun['id'] discard = lun['discard_max_size'] > 0 self.logger.info( _("iSCSI discard after delete is {v}").format( v=_("enabled") if discard else _("disabled") ) ) except RuntimeError as e: self.logger.error(_('Unable to get target list')) if not interactive: raise e continue elif domain_type == ohostedcons.DomainTypes.FC: if lunid is None: try: lun = self._query_fc_lunid() lunid = lun['id'] discard = lun['discard_max_size'] > 0 self.logger.info( _("FC discard after delete is {v}").format( v=_("enabled") if discard else _("disabled") ) ) except RuntimeError as e: self.logger.error(_('Unable to get target list')) if not interactive: raise e continue else: self.logger.error(_('Currently not implemented')) if not interactive: raise RuntimeError('Currently not implemented') continue storage_domain_vars = { 'FQDN': self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN ], 'HOST_NAME': self.environment[ ohostedcons.EngineEnv.APP_HOST_NAME ], 'ADMIN_PASSWORD': self.environment[ ohostedcons.EngineEnv.ADMIN_PASSWORD ], 'STORAGE_DOMAIN_NAME': self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_NAME ], 'STORAGE_DOMAIN_ADDR': storage_domain_address, 'STORAGE_DOMAIN_PATH': storage_domain_path, 'MOUNT_OPTIONS': mnt_options, 'NFS_VERSION': nfs_version, 'DOMAIN_TYPE': domain_type, 'ISCSI_PORTAL_PORT': iscsi_port, 'ISCSI_TARGET': iscsi_target, 'LUN_ID': lunid, 'ISCSI_USERNAME': iscsi_username, 'ISCSI_PASSWORD': iscsi_password, 'LOCAL_VM_DIR': self.environment[ ohostedcons.CoreEnv.LOCAL_VM_DIR ], 'DISCARD': discard, } ah = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_CREATE_SD, extra_vars=storage_domain_vars, ) self.logger.info(_('Creating Storage Domain')) try: r = ah.run() except RuntimeError as e: if not interactive: raise e continue self.logger.debug( 'Create storage domain results {r}'.format(r=r) ) if ( 'otopi_storage_domain_details' in r and 'storagedomain' in r['otopi_storage_domain_details'] ): storage_domain = r[ 'otopi_storage_domain_details' ]['storagedomain'] self.environment[ ohostedcons.StorageEnv.BDEVICE_SIZE_GB ] = int(storage_domain['available'])/1024/1024/1024 if storage_domain['status'] == 'active': created = True # and set all the env values from the response storage = storage_domain['storage'] storage_type = storage['type'] if storage_type == "fcp": storage_type = "fc" # Normalize type for HE broker. self.environment[ ohostedcons.StorageEnv.DOMAIN_TYPE ] = storage_type if self.environment[ ohostedcons.StorageEnv.DOMAIN_TYPE ] == ohostedcons.DomainTypes.NFS: self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION ] = '{address}:{path}'.format( address=storage['address'], path=storage['path'], ) # TODO: any way to get it from the engine self.environment[ ohostedcons.StorageEnv.MNT_OPTIONS ] = mnt_options self.environment[ ohostedcons.StorageEnv.NFS_VERSION ] = storage['nfs_version'] if self.environment[ ohostedcons.StorageEnv.DOMAIN_TYPE ] == ohostedcons.DomainTypes.GLUSTERFS: self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION ] = '{address}:{path}'.format( address=storage['address'], path=storage['path'], ) self.environment[ ohostedcons.StorageEnv.MNT_OPTIONS ] = mnt_options if self.environment[ ohostedcons.StorageEnv.DOMAIN_TYPE ] == ohostedcons.DomainTypes.ISCSI: self.logger.info( _('iSCSI connected paths: {n}').format( n=len(storage['volume_group']['logical_units']) ) ) self.environment[ ohostedcons.StorageEnv.ISCSI_PORTAL ] = storage['volume_group']['logical_units'][ 0 ]['portal'].split(',')[1] lun0 = storage['volume_group']['logical_units'][0] self.environment[ ohostedcons.StorageEnv.ISCSI_IP_ADDR ] = ','.join([x['address'] for x in storage[ 'volume_group' ]['logical_units']]) self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION ] = self.environment[ ohostedcons.StorageEnv.ISCSI_IP_ADDR ] self.environment[ ohostedcons.StorageEnv.ISCSI_PORT ] = ','.join([str(x['port']) for x in storage[ 'volume_group' ]['logical_units']]) self.environment[ ohostedcons.StorageEnv.ISCSI_TARGET ] = lun0['target'] self.environment[ ohostedcons.StorageEnv.LUN_ID ] = lun0['id'] self.environment[ ohostedcons.StorageEnv.ISCSI_USER ] = iscsi_username self.environment[ ohostedcons.StorageEnv.ISCSI_PASSWORD ] = iscsi_password else: if not interactive: raise RuntimeError('Failed creating storage domain') else: if not interactive: raise RuntimeError('Failed creating storage domain')
def _customization(self): validValues = [] if self.environment[ohostedcons.CoreEnv.ANSIBLE_DEPLOYMENT]: playbook = ohostedcons.FileLocations.HE_AP_NETWORK_INTERFACES ah = ansible_utils.AnsibleHelper(playbook_name=playbook, extra_vars={}) r = ah.run() self.logger.debug(r) if 'otopi_host_net' in r: for network_interface in r['otopi_host_net']['results']: if 'ansible_facts' in network_interface: validValues.append(network_interface['item']['item']) else: raise RuntimeError( _('No suitable network interfaces were found')) else: INVALID_BOND_MODES = ('0', '5', '6') ALLOW_INVALID_BOND_MODES = \ ohostedcons.NetworkEnv.ALLOW_INVALID_BOND_MODES caps = vds_info.capabilities( self.environment[ohostedcons.VDSMEnv.VDS_CLI]) interfaces = set(caps['nics'].keys() + caps['bondings'].keys() + caps['vlans'].keys()) validValues = [] enslaved = set() inv_bond = set() for bridge in caps['bridges'].keys(): enslaved.update(set(caps['bridges'][bridge]['ports'])) for bond in caps['bondings'].keys(): bondMode = caps['bondings'][bond]['opts']['mode'] if (bondMode in INVALID_BOND_MODES): self.logger.warning( _("Bond {bondname} is on mode {bondmode}, " "modes {invalid} are not supported").format( bondname=bond, bondmode=bondMode, invalid=INVALID_BOND_MODES)) if not self.environment[ALLOW_INVALID_BOND_MODES]: inv_bond.update(set([bond])) else: self.logger.warning( _("Allowing anyway, as enforced by {key}={val}"). format(key=ALLOW_INVALID_BOND_MODES, val=self. environment[ALLOW_INVALID_BOND_MODES])) slaves = set(caps['bondings'][bond]['slaves']) if slaves: enslaved.update(slaves) else: self.logger.debug( 'Detected bond device %s without slaves' % bond) inv_bond.update(set([bond])) validValues = list(interfaces - enslaved - inv_bond) self.logger.debug('Nics detected: %s' % ','.join(interfaces)) self.logger.debug('Nics enslaved: %s' % ','.join(enslaved)) self.logger.debug('Nics valid: %s' % ','.join(validValues)) if not validValues: if enslaved: raise RuntimeError( _('The following existing interfaces are not suitable ' 'for vdsm: {enslaved}. You might want to pull out an ' 'interface out of a bridge to be able to use it').format( enslaved=','.join(enslaved))) else: raise RuntimeError(_('A Network interface is required')) interactive = self.environment[ ohostedcons.NetworkEnv.BRIDGE_IF] is None if interactive: default = self._get_active_interface(validValues) self.environment[ ohostedcons.NetworkEnv.BRIDGE_IF] = self.dialog.queryString( name='ovehosted_bridge_if', note=_( 'Please indicate a nic to set ' '{bridge} bridge on: (@VALUES@) [@DEFAULT@]: ').format( bridge=self.environment[ ohostedcons.NetworkEnv.BRIDGE_NAME]), prompt=True, caseSensitive=True, default=default, validValues=validValues, )
def _closeup(self): ip_addr = '' prefix = '' dnslist = '' if self.environment[ohostedcons.CloudInit.VM_STATIC_CIDR]: ip = netaddr.IPNetwork( self.environment[ohostedcons.CloudInit.VM_STATIC_CIDR]) ip_addr = str(ip.ip) prefix = str(ip.prefixlen) if self.environment[ohostedcons.CloudInit.VM_DNS]: dnslist = [ d.strip() for d in self.environment[ ohostedcons.CloudInit.VM_DNS].split(',') ] target_vm_vars = { 'FQDN': self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'HOST_ADDRESS': self.environment[ohostedcons.NetworkEnv.HOST_NAME], 'HOST_NAME': self.environment[ohostedcons.EngineEnv.APP_HOST_NAME], 'ADMIN_PASSWORD': self.environment[ohostedcons.EngineEnv.ADMIN_PASSWORD], 'APPLIANCE_PASSWORD': self.environment[ohostedcons.CloudInit.ROOTPWD], 'STORAGE_DOMAIN_NAME': self.environment[ohostedcons.StorageEnv.STORAGE_DOMAIN_NAME], 'VM_MAC_ADDR': self.environment[ohostedcons.VMEnv.MAC_ADDR], 'VM_NAME': ohostedcons.Const.HOSTED_ENGINE_VM_NAME, 'MEM_SIZE': self.environment[ohostedcons.VMEnv.MEM_SIZE_MB], 'VCPUS': self.environment[ohostedcons.VMEnv.VCPUS], 'CPU_SOCKETS': '1', 'TIME_ZONE': self.environment[ohostedcons.CloudInit.VM_TZ], 'BRIDGE': self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME], 'LOCAL_VM_DIR': self.environment[ohostedcons.CoreEnv.LOCAL_VM_DIR], 'STORAGE': self.environment[ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION], 'MOUNT_OPTIONS': self.environment[ohostedcons.StorageEnv.MNT_OPTIONS], 'DOMAIN_TYPE': self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE], 'GATEWAY': self.environment[ohostedcons.NetworkEnv.GATEWAY], 'ISCSI_TARGET': self.environment[ohostedcons.StorageEnv.ISCSI_TARGET], 'ISCSI_USERNAME': self.environment[ohostedcons.StorageEnv.ISCSI_USER], 'ISCSI_PASSWORD': self.environment[ohostedcons.StorageEnv.ISCSI_PASSWORD], 'ISCSI_PORT': self.environment[ohostedcons.StorageEnv.ISCSI_PORT], 'ISCSI_IP_ADDR': self.environment[ohostedcons.StorageEnv.ISCSI_IP_ADDR], 'ISCSI_TPGT': self.environment[ohostedcons.StorageEnv.ISCSI_PORTAL], 'LUN_ID': self.environment[ohostedcons.StorageEnv.LUN_ID], 'CONSOLE_TYPE': 'vnc', 'CDROM_UUID': self.environment[ohostedcons.VMEnv.CDROM_UUID], 'CDROM': '', 'NIC_UUID': self.environment[ohostedcons.VMEnv.NIC_UUID], 'VIDEO_DEVICE': 'vga', 'GRAPHICS_DEVICE': 'vnc', 'MAXVCPUS': self.environment[ohostedcons.VMEnv.MAXVCPUS], 'EMULATED_MACHINE': self.environment[ohostedcons.VMEnv.EMULATED_MACHINE], 'NFS_VERSION': self.environment[ohostedcons.StorageEnv.NFS_VERSION], 'VM_IP_ADDR': ip_addr, 'VM_IP_PREFIX': prefix, 'DNS_ADDR': dnslist, 'VM_ETC_HOSTS': self.environment[ohostedcons.CloudInit.VM_ETC_HOSTS], 'HOST_IP': self.environment[ohostedcons.CloudInit.HOST_IP], 'DISK_SIZE': self.environment[ohostedcons.StorageEnv.IMAGE_SIZE_GB], 'SMTP_SERVER': self.environment[ohostedcons.NotificationsEnv.SMTP_SERVER], 'SMTP_PORT': self.environment[ohostedcons.NotificationsEnv.SMTP_PORT], 'SOURCE_EMAIL': self.environment[ohostedcons.NotificationsEnv.SOURCE_EMAIL], 'DEST_EMAIL': self.environment[ohostedcons.NotificationsEnv.DEST_EMAIL], 'APPLIANCE_OVA': self.environment[ohostedcons.VMEnv.OVF], 'CLOUD_INIT_DOMAIN_NAME': self.environment[ohostedcons.CloudInit.INSTANCE_DOMAINNAME], 'CLOUD_INIT_HOST_NAME': self.environment[ohostedcons.CloudInit.INSTANCE_HOSTNAME], 'ROOT_SSH_PUBKEY': self.environment[ohostedcons.CloudInit.ROOT_SSH_PUBKEY], } inventory_source = 'localhost, {fqdn}'.format(fqdn=self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN]) ah = ansible_utils.AnsibleHelper( playbook_name=ohostedcons.FileLocations.HE_AP_CREATE_VM, extra_vars=target_vm_vars, inventory_source=inventory_source, ) self.logger.info(_('Creating Target VM')) r = ah.run() self.logger.debug(r)
def _closeup(self): ip_addr = None prefix = None dnslist = None if self.environment[ohostedcons.CloudInit.VM_STATIC_CIDR]: ip = netaddr.IPNetwork( self.environment[ohostedcons.CloudInit.VM_STATIC_CIDR]) ip_addr = str(ip.ip) prefix = str(ip.prefixlen) if self.environment[ohostedcons.CloudInit.VM_DNS]: dnslist = [ d.strip() for d in self.environment[ ohostedcons.CloudInit.VM_DNS].split(',') ] domain_type = self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] if (domain_type == ohostedcons.DomainTypes.NFS or domain_type == ohostedcons.DomainTypes.GLUSTERFS): storage_domain_det = self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION].split(':') if len(storage_domain_det) != 2: msg = _('Invalid connection path') self.logger.error(msg) raise RuntimeError(msg) storage_domain_address = storage_domain_det[0] storage_domain_path = storage_domain_det[1] else: storage_domain_address = self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION] storage_domain_path = None target_vm_vars = { 'he_fqdn': self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN], 'he_host_name': self.environment[ohostedcons.EngineEnv.APP_HOST_NAME], 'he_host_address': self.environment[ohostedcons.NetworkEnv.HOST_NAME], 'he_admin_password': self.environment[ohostedcons.EngineEnv.ADMIN_PASSWORD], 'he_appliance_password': self.environment[ohostedcons.CloudInit.ROOTPWD], 'he_local_vm_dir': self.environment[ohostedcons.CoreEnv.LOCAL_VM_DIR], 'he_storage_domain_name': self.environment[ohostedcons.StorageEnv.STORAGE_DOMAIN_NAME], 'he_vm_mac_addr': self.environment[ohostedcons.VMEnv.MAC_ADDR], 'he_vm_name': ohostedcons.Const.HOSTED_ENGINE_VM_NAME, 'he_mem_size_MB': self.environment[ohostedcons.VMEnv.MEM_SIZE_MB], 'he_vcpus': self.environment[ohostedcons.VMEnv.VCPUS], 'he_time_zone': self.environment[ohostedcons.CloudInit.VM_TZ], 'he_bridge_if': self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME], 'he_local_vm_dir_path': self.environment[ohostedcons.CoreEnv.LOCAL_VM_DIR], 'he_storage_domain_addr': storage_domain_address, 'he_storage_domain_path': storage_domain_path, 'he_mount_options': self.environment[ohostedcons.StorageEnv.MNT_OPTIONS], 'he_domain_type': self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE], 'he_gateway': self.environment[ohostedcons.NetworkEnv.GATEWAY], 'he_iscsi_target': self.environment[ohostedcons.StorageEnv.ISCSI_TARGET], 'he_iscsi_username': self.environment[ohostedcons.StorageEnv.ISCSI_USER], 'he_iscsi_password': self.environment[ohostedcons.StorageEnv.ISCSI_PASSWORD], 'he_iscsi_portal_port': self.environment[ohostedcons.StorageEnv.ISCSI_PORT], 'he_iscsi_portal_addr': self.environment[ohostedcons.StorageEnv.ISCSI_IP_ADDR], 'he_iscsi_tpgt': self.environment[ohostedcons.StorageEnv.ISCSI_PORTAL], 'he_lun_id': self.environment[ohostedcons.StorageEnv.LUN_ID], 'he_cdrom_uuid': self.environment[ohostedcons.VMEnv.CDROM_UUID], 'he_nic_uuid': self.environment[ohostedcons.VMEnv.NIC_UUID], 'he_maxvcpus': self.environment[ohostedcons.VMEnv.MAXVCPUS], 'he_emulated_machine': self.environment[ohostedcons.VMEnv.EMULATED_MACHINE], 'he_nfs_version': self.environment[ohostedcons.StorageEnv.NFS_VERSION], 'he_vm_ip_addr': ip_addr, 'he_vm_ip_prefix': prefix, 'he_dns_addr': dnslist, 'he_vm_etc_hosts': self.environment[ohostedcons.CloudInit.VM_ETC_HOSTS], 'he_disk_size_GB': self.environment[ohostedcons.StorageEnv.IMAGE_SIZE_GB], 'he_smtp_server': self.environment[ohostedcons.NotificationsEnv.SMTP_SERVER], 'he_smtp_port': self.environment[ohostedcons.NotificationsEnv.SMTP_PORT], 'he_source_email': self.environment[ohostedcons.NotificationsEnv.SOURCE_EMAIL], 'he_dest_email': self.environment[ohostedcons.NotificationsEnv.DEST_EMAIL], 'he_appliance_ova': self.environment[ohostedcons.VMEnv.OVF], 'he_cloud_init_domain_name': self.environment[ohostedcons.CloudInit.INSTANCE_DOMAINNAME], 'he_cloud_init_host_name': self.environment[ohostedcons.CloudInit.INSTANCE_HOSTNAME], 'he_root_ssh_pubkey': self.environment[ohostedcons.CloudInit.ROOT_SSH_PUBKEY], 'he_restore_from_file': self.environment[ohostedcons.CoreEnv.RESTORE_FROM_FILE], 'he_cluster': self.environment[ohostedcons.EngineEnv.HOST_CLUSTER_NAME], 'he_force_ip4': self.environment[ohostedcons.NetworkEnv.FORCE_IPV4], 'he_force_ip6': self.environment[ohostedcons.NetworkEnv.FORCE_IPV6] } inventory_source = 'localhost, {fqdn}'.format(fqdn=self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN]) ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_CREATE_VM, extra_vars=target_vm_vars, inventory_source=inventory_source, ) self.logger.info(_('Creating Target VM')) r = ah.run() self.logger.debug(r)
def _closeup(self): # TODO: use just env values bootstrap_vars = { 'he_appliance_ova': self.environment[ohostedcons.VMEnv.OVF], 'he_fqdn': self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN ], 'he_vm_mac_addr': self.environment[ ohostedcons.VMEnv.MAC_ADDR ], 'he_cloud_init_domain_name': self.environment[ ohostedcons.CloudInit.INSTANCE_DOMAINNAME ], 'he_cloud_init_host_name': self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ], 'he_host_name': self.environment[ ohostedcons.EngineEnv.APP_HOST_NAME ], 'he_host_address': self.environment[ ohostedcons.NetworkEnv.HOST_NAME ], 'he_local_vm_dir_path': ( ohostedcons.FileLocations.LOCAL_VM_DIR_PATH ), 'he_local_vm_dir_prefix': ( ohostedcons.FileLocations.LOCAL_VM_DIR_PREFIX ), 'he_admin_password': self.environment[ ohostedcons.EngineEnv.ADMIN_PASSWORD ], 'he_appliance_password': self.environment[ ohostedcons.CloudInit.ROOTPWD ], 'he_time_zone': self.environment[ohostedcons.CloudInit.VM_TZ], 'he_cdrom_uuid': self.environment[ohostedcons.VMEnv.CDROM_UUID], 'he_nic_uuid': self.environment[ohostedcons.VMEnv.NIC_UUID], 'he_maxvcpus': self.environment[ohostedcons.VMEnv.MAXVCPUS], 'he_vm_name': ohostedcons.Const.HOSTED_ENGINE_VM_NAME, 'he_mem_size_MB': self.environment[ohostedcons.VMEnv.MEM_SIZE_MB], 'he_vcpus': self.environment[ohostedcons.VMEnv.VCPUS], 'he_emulated_machine': self.environment[ ohostedcons.VMEnv.EMULATED_MACHINE ], 'he_vm_uuid': self.environment[ohostedcons.VMEnv.LOCAL_VM_UUID], 'he_vm_etc_hosts': self.environment[ ohostedcons.CloudInit.VM_ETC_HOSTS ], 'he_root_ssh_pubkey': self.environment[ ohostedcons.CloudInit.ROOT_SSH_PUBKEY ], 'he_root_ssh_access': self.environment[ ohostedcons.CloudInit.ROOT_SSH_ACCESS ].lower(), 'he_enable_libgfapi': self.environment[ ohostedcons.StorageEnv.ENABLE_LIBGFAPI ], 'he_enable_hc_gluster_service': self.environment[ ohostedcons.StorageEnv.ENABLE_HC_GLUSTER_SERVICE ], 'he_bridge_if': self.environment[ ohostedcons.NetworkEnv.BRIDGE_IF ], 'he_restore_from_file': self.environment[ ohostedcons.CoreEnv.RESTORE_FROM_FILE ], 'he_storage_domain_name': self.environment[ ohostedcons.StorageEnv.STORAGE_DOMAIN_NAME ], 'he_data_center': self.environment[ ohostedcons.EngineEnv.HOST_DATACENTER_NAME ], 'he_cluster': self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME ], 'he_requirements_check_enabled': self.environment[ ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED ], 'he_memory_requirements_check_enabled': self.environment[ ohostedcons.CoreEnv.MEM_REQUIREMENTS_CHECK_ENABLED ], 'he_force_ip4': self.environment[ ohostedcons.NetworkEnv.FORCE_IPV4 ], 'he_force_ip6': self.environment[ ohostedcons.NetworkEnv.FORCE_IPV6 ] } inventory_source = 'localhost,{fqdn}'.format( fqdn=self.environment[ ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN ] ) self.initial_clean_up(bootstrap_vars, inventory_source) ah = ansible_utils.AnsibleHelper( tags=ohostedcons.Const.HE_TAG_BOOTSTRAP_LOCAL_VM, extra_vars=bootstrap_vars, inventory_source=inventory_source, ) self.logger.info(_('Starting local VM')) r = ah.run() self.logger.debug(r) if ( 'otopi_localvm_dir' in r and 'path' in r['otopi_localvm_dir'] ): self.environment[ ohostedcons.CoreEnv.LOCAL_VM_DIR ] = r['otopi_localvm_dir']['path'] else: raise RuntimeError(_('Failed getting local_vm_dir')) try: vsize = r[ 'otopi_appliance_disk_size' ]['ansible_facts']['virtual_size'] self.environment[ ohostedcons.StorageEnv.OVF_SIZE_GB ] = int(vsize)/1024/1024/1024 except KeyError: raise RuntimeError(_('Unable to get appliance disk size'))