def _customization(self): def readable(f): res = '' try: with open(self.resolveFile(f), 'r'): pass res = '' except IOError: res = _('Cannot read from {f}').format(f=f) return res dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=oreportscons.ToolEnv.FILE, note=_('Filename to import saved reports from: '), prompt=True, tests=( { 'test': lambda(f): ( '' if os.path.exists(self.resolveFile(f)) else _('File {f} not found'.format(f=f)) ), }, { 'test': readable, }, ), )
def _customization(self): dialog.queryEnvKey( name='OVESETUP_DWH_SCALE', dialog=self.dialog, logger=self.logger, env=self.environment, key=odwhcons.ConfigEnv.SCALE, note=_( 'Please choose Data Warehouse sampling scale:\n' '{scales}' '\n(@VALUES@)[@DEFAULT@]: ' ).format( scales='\n'.join( [ _( '({index}) {desc}' ).format( index=scale['index'], desc=scale['desc'], ) for scale in self._DWH_SCALES ] ), ), default=( self._DEFAULT_DWH_SCALE_WITH_ENGINE if self.environment[oenginecons.CoreEnv.ENABLE] else self._DEFAULT_DWH_SCALE_WITHOUT_ENGINE ), validValues=( scale['index'] for scale in self._DWH_SCALES ), prompt=True, )
def query_dbenv(what, note, tests=None, **kwargs): dialog.queryEnvKey(name='{qpref}{what}'.format( qpref=queryprefix, what=string.upper(what), ), dialog=self.dialog, logger=self.logger, env=dbenv, key=self._dbenvkeys[what], note=note.format(name=name, ), prompt=True, default=defaultdbenvkeys[what], tests=tests, **kwargs)
def _customize_user(self): return dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.StorageEnv.ISCSI_USER, note=_( 'Please specify the iSCSI portal user: '******'test': lambda username: ( '' if len( username ) <= ohostedcons.Const.MAX_STORAGE_USERNAME_LENGTH else _( 'Username should not be longer than %i characters.' ) % ohostedcons.Const.MAX_STORAGE_USERNAME_LENGTH ), }, ), name='OVEHOSTED_STORAGE_ISCSI_USER', default = '', store = False, )
def _customize_password(self, user): return '' if not user else dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.StorageEnv.ISCSI_PASSWORD, note=_( 'Please specify the iSCSI portal password: '******'test': lambda password: ( '' if len( password ) <= ohostedcons.Const.MAX_STORAGE_PASSWORD_LENGTH else _( 'Password should not be longer than %i characters.' ) % ohostedcons.Const.MAX_STORAGE_PASSWORD_LENGTH ), }, ), name='OVEHOSTED_STORAGE_ISCSI_PASSWORD', default = '', store = False, )
def _customization(self): dialog.queryEnvKey( name='OVESETUP_DWH_SCALE', dialog=self.dialog, logger=self.logger, env=self.environment, key=odwhcons.ConfigEnv.SCALE, note=_('Please choose Data Warehouse sampling scale:\n' '{scales}' '\n(@VALUES@)[@DEFAULT@]: ').format(scales='\n'.join([ _('({index}) {desc}').format( index=scale['index'], desc=scale['desc'], ) for scale in self._DWH_SCALES ]), ), default=(self._DEFAULT_DWH_SCALE_WITH_ENGINE if self.environment[oenginecons.CoreEnv.ENABLE] else self._DEFAULT_DWH_SCALE_WITHOUT_ENGINE), validValues=(scale['index'] for scale in self._DWH_SCALES), prompt=True, )
def query_dbenv( what, note, tests=None, **kwargs ): dialog.queryEnvKey( name='{qpref}{what}'.format( qpref=queryprefix, what=string.upper(what), ), dialog=self.dialog, logger=self.logger, env=dbenv, key=self._dbenvkeys[what], note=note.format( name=name, ), prompt=True, default=defaultdbenvkeys[what], tests=tests, **kwargs )
def _customization(self): def writable(f): res = '' try: with open(self.resolveFile(f), 'a'): pass res = '' except IOError: res = _('Cannot write to {f}').format(f=f) return res dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=oreportscons.ToolEnv.FILE, note=_( 'Filename to export saved reports to: ' ), prompt=True, tests=( { 'test': lambda(f): _( 'File {f} exists' ).format(f=f) if os.path.exists( self.resolveFile(f) ) else '', 'is_error': False, 'warn_note': 'Overwrite? ', }, { 'test': writable, }, ), )
def getHostname( self, envkey, whichhost, supply_default, prompttext=None, dialog_name=None, **tester_kwarg ): if prompttext is None: prompttext = _( 'Host fully qualified DNS name of {whichhost} server' ).format( whichhost=whichhost, ) if dialog_name is None: dialog_name = 'OVESETUP_NETWORK_FQDN_{whichhost}'.format( whichhost=whichhost.replace(' ', '_'), ) return dialog.queryEnvKey( name=dialog_name, dialog=self.dialog, logger=self.logger, env=self.environment, key=envkey, note=_( '{prompt} [@DEFAULT@]: ' ).format( prompt=prompttext, ), prompt=True, default=socket.getfqdn() if supply_default else '', tests=( { 'test': self.getHostnameTester(**tester_kwarg), }, { 'test': self.fqdnLocalhostValidation, 'is_error': False, 'warn_note': 'Are you sure?', }, ), store=(True if envkey else False), )
def _customize_user(self): return dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.StorageEnv.ISCSI_USER, note=_('Please specify the iSCSI portal user: '******'test': lambda username: ('' if len(username ) <= ohostedcons.Const.MAX_STORAGE_USERNAME_LENGTH else _('Username should not be longer than %i characters.' ) % ohostedcons.Const.MAX_STORAGE_USERNAME_LENGTH), }, ), name='OVEHOSTED_STORAGE_ISCSI_USER', default='', store=False, )
def _customize_password(self, user): return '' if not user else dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.StorageEnv.ISCSI_PASSWORD, note=_('Please specify the iSCSI portal password: '******'test': lambda password: ('' if len(password ) <= ohostedcons.Const.MAX_STORAGE_PASSWORD_LENGTH else _('Password should not be longer than %i characters.' ) % ohostedcons.Const.MAX_STORAGE_PASSWORD_LENGTH), }, ), name='OVEHOSTED_STORAGE_ISCSI_PASSWORD', default='', store=False, )
def getHostname( self, envkey, whichhost, supply_default, prompttext=None, dialog_name=None, **tester_kwarg ): if prompttext is None: prompttext = _( 'Host fully qualified DNS name of {whichhost} server' ).format( whichhost=whichhost, ) if dialog_name is None: dialog_name = 'OVESETUP_NETWORK_FQDN_{whichhost}'.format( whichhost=whichhost.replace(' ', '_'), ) return dialog.queryEnvKey( name=dialog_name, dialog=self.dialog, logger=self.logger, env=self.environment, key=envkey, note=_( '{prompt} [@DEFAULT@]: ' ).format( prompt=prompttext, ), prompt=True, default=socket.getfqdn() if supply_default else '', tests=( { 'test': self.getHostnameTester(**tester_kwarg), }, ), store=(True if envkey else False), )
def _customization(self): if self.environment[ ohostedcons.CloudInit.VM_TZ ] is None: self.environment[ohostedcons.CloudInit.VM_TZ] = self._get_host_tz() self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_GENERATE self.environment[ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN ] = True self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] = True if self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] is None: if self.dialog.queryString( name='CLOUD_INIT_USE', note=_( 'Would you like to use cloud-init to customize the ' 'appliance on the first boot ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes') ) == _('Yes').lower(): if self.dialog.queryString( name='CLOUD_INIT_GENERATE', note=_( 'Would you like to generate on-fly a cloud-init ' 'ISO image (of no-cloud type)\n' 'or do you have an existing one ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Generate'), _('Existing')), caseSensitive=False, default=_('Generate') ) == _('Generate').lower(): self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_GENERATE else: self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_EXISTING else: self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_SKIP if self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] == ohostedcons.Const.CLOUD_INIT_GENERATE: if not self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ]: instancehname = self._hostname_helper.getHostname( envkey=None, whichhost='CI_INSTANCE_HOSTNAME', supply_default=False, prompttext=_( 'Please provide the FQDN you would like to use for ' 'the engine.\n' 'Note: This will be the FQDN of the engine VM ' 'you are now going to launch,\nit should not ' 'point to the base host or to any other ' 'existing machine.\n' 'Engine VM FQDN: ' ), dialog_name='CI_INSTANCE_HOSTNAME', validate_syntax=True, system=True, dns=False, local_non_loopback=False, reverse_dns=False, not_local=True, not_local_text=_( 'Please input the hostname for the engine VM, ' 'not for this host.' ), allow_empty=False, ) if instancehname: self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] = instancehname else: self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] = False if ( self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] and self.environment[ ohostedcons.CloudInit.INSTANCE_DOMAINNAME ] is None ): default_domain = '' if '.' in self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ]: default_domain = self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ].split('.', 1)[1] self.environment[ ohostedcons.CloudInit.INSTANCE_DOMAINNAME ] = self.dialog.queryString( name='CI_INSTANCE_DOMAINNAME', note=_( 'Please provide the domain name you would like to ' 'use for the engine appliance.\n' 'Engine VM domain: [@DEFAULT@]' ), prompt=True, default=default_domain, ) if not self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ]: self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] = self.dialog.queryString( name='CI_EXECUTE_ESETUP', note=_( 'Automatically execute ' 'engine-setup on the engine appliance on first boot ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes') ) == _('Yes').lower() if self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] and self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME ] is None: self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME ] = ohostedcons.Defaults.DEFAULT_CLUSTER_NAME if self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] and self.environment[ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN ] is None: self.environment[ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN ] = self.dialog.queryString( name='AUTOMATE_VM_SHUTDOWN', note=_( 'Automatically restart the engine VM ' 'as a monitored service after engine-setup ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes') ) == _('Yes').lower() if ( self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] or self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] or self.environment[ ohostedcons.CloudInit.VM_STATIC_CIDR ] or self.environment[ ohostedcons.CloudInit.VM_DNS ] ): self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_GENERATE self._enable = True if self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] == ohostedcons.Const.CLOUD_INIT_GENERATE: while self.environment[ ohostedcons.CloudInit.ROOTPWD ] is None: password = self.dialog.queryString( name='CI_ROOT_PASSWORD', note=_( 'Enter root password that ' 'will be used for the engine appliance: ' ), prompt=True, hidden=True, default='', ).strip() if password: password_check = self.dialog.queryString( name='CI_ROOT_PASSWORD', note=_( "Confirm appliance root password: "******"Enter ssh public key for the root user that " 'will be used for the engine appliance ' '(leave it empty to skip): ' ), prompt=True, hidden=False, default='', ).strip() if pubkey: fd, pkfilename = tempfile.mkstemp(suffix='pub') pkfile = os.fdopen(fd, 'w') try: pkfile.write(pubkey) finally: pkfile.close() rc, stdout, stderr = self.execute( ( self.command.get('ssh-keygen'), '-lf', pkfilename, ), raiseOnError=False, ) os.unlink(pkfilename) if rc != 0: self.logger.error(_( 'The ssh key is not valid.' )) else: self.environment[ ohostedcons.CloudInit.ROOT_SSH_PUBKEY ] = pubkey else: self.environment[ ohostedcons.CloudInit.ROOT_SSH_PUBKEY ] = '' self.logger.warning(_( 'Skipping appliance root ssh public key' )) vv_root_a = ( 'yes', 'no', 'without-password', ) dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.CloudInit.ROOT_SSH_ACCESS, name='CI_ROOT_SSH_ACCESS', note=_( 'Do you want to enable ssh access for the root user ' '(@VALUES@) [@DEFAULT@]: ' ), prompt=True, hidden=False, default=vv_root_a[0], store=True, validValues=vv_root_a, caseSensitive=False, ) if self.environment[ ohostedcons.CloudInit.APPLY_OPENSCAP_PROFILE ] is None: self.environment[ ohostedcons.CloudInit.APPLY_OPENSCAP_PROFILE ] = self.dialog.queryString( name='CI_APPLY_OPENSCAP_PROFILE', note=_( 'Do you want to apply a default OpenSCAP security ' 'profile (@VALUES@) [@DEFAULT@]: ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('No') ) == _('Yes').lower() if ( self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] != ohostedcons.Const.CLOUD_INIT_GENERATE or not self.environment[ ohostedcons.CloudInit.ROOTPWD ] or self.environment[ ohostedcons.CloudInit.ROOTPWD ].strip() == '' ): self.logger.warning(_( 'The oVirt engine appliance is not configured with a ' 'default password, please consider configuring it ' 'via cloud-init' ))
def _customization(self): maxmem = int(self._getMaxMemorySize()) - \ ohostedcons.Const.HOST_RESERVED_MEMORY_MB if maxmem < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: self.logger.warning( _( 'Minimum requirements not met by available memory: ' 'Required: {memsize} MB. Available: {maxmem} MB' ).format( memsize=ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB, maxmem=maxmem, ) ) default = ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB default_msg = _('minimum requirement') if self.environment[ ohostedcons.VMEnv.APPLIANCEMEM ] is not None: default = self.environment[ohostedcons.VMEnv.APPLIANCEMEM] default_msg = _('appliance OVF value') if default > maxmem: default = maxmem default_msg = _('maximum available') def _check_min_memory(mem_size_mb): if not self.environment[ ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED ]: return None try: if int( mem_size_mb ) < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: return _( 'Minimum requirements for memory size not met' ) except ValueError: return _( 'Invalid memory size specified: {size}' ).format( size=mem_size_mb, ) def _check_memory_is_int(mem_size_mb): try: int(mem_size_mb) except ValueError: return _( 'Invalid memory size specified: {size}' ).format( size=mem_size_mb, ) def _check_memory_value(mem_size_mb): if not self.environment[ ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED ] or not self.environment[ ohostedcons.CoreEnv.MEM_REQUIREMENTS_CHECK_ENABLED ]: return None if int( mem_size_mb ) < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: return _( 'Minimum requirements for memory size not met' ) if int( mem_size_mb ) > maxmem: return _( 'Invalid memory size specified: {memsize}, ' 'while only {maxmem} are available on ' 'the host' ).format( memsize=mem_size_mb, maxmem=maxmem, ) mem_size_mb_was_set = self.environment[ ohostedcons.VMEnv.MEM_SIZE_MB ] dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.VMEnv.MEM_SIZE_MB, name='ovehosted_vmenv_mem', note=_( 'Please specify the memory size of the VM in MB ' '(Defaults to {default_msg}): [@DEFAULT@]: ' ).format( default_msg=default_msg, ), prompt=True, hidden=False, tests=( { 'test': _check_memory_is_int, 'is_error': True, }, { 'test': _check_memory_value, 'warn_name': ohostedcons.Confirms.MEMORY_PROCEED, 'warn_note': _( 'Continue with specified memory size?' ), 'is_error': False, }, ), default=default, store=True, ) # ensure that value is stored as integer. _check_memory_is_int # already ensured that value is a valid integer before. self.environment[ohostedcons.VMEnv.MEM_SIZE_MB] = int( self.environment[ohostedcons.VMEnv.MEM_SIZE_MB] ) # For the 'interactive-only' flow. # set the memory size check to false if the user chose to continue. if not mem_size_mb_was_set and (( self.environment[ohostedcons.VMEnv.MEM_SIZE_MB] ) < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB or ( self.environment[ohostedcons.VMEnv.MEM_SIZE_MB] ) > maxmem): self.environment[ ohostedcons.CoreEnv.MEM_REQUIREMENTS_CHECK_ENABLED ] = False
def _customization(self): maxmem = int(self._getMaxMemorySize()) if maxmem < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: self.logger.warning( _('Minimum requirements not met by available memory: ' 'Required: {memsize} MB. Available: {maxmem} MB').format( memsize=ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB, maxmem=maxmem, )) default = ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB default_msg = _('minimum requirement') if self.environment[ohostedcons.VMEnv.APPLIANCEMEM] is not None: default = self.environment[ohostedcons.VMEnv.APPLIANCEMEM] default_msg = _('appliance OVF value') if default > maxmem: default = maxmem default_msg = _('maximum available') def _check_min_memory(mem_size_mb): if not self.environment[ ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED]: return None try: if int(mem_size_mb) < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: return _('Minimum requirements for memory size not met') except ValueError: return _('Invalid memory size specified: {size}').format( size=mem_size_mb, ) def _check_memory_is_int(mem_size_mb): try: int(mem_size_mb) except ValueError: return _('Invalid memory size specified: {size}').format( size=mem_size_mb, ) def _check_memory_value(mem_size_mb): if not self.environment[ ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED]: return None if int(mem_size_mb) < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: return _('Minimum requirements for memory size not met') if int(mem_size_mb) > maxmem: return _('Invalid memory size specified: {memsize}, ' 'while only {maxmem} are available on ' 'the host').format( memsize=mem_size_mb, maxmem=maxmem, ) dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.VMEnv.MEM_SIZE_MB, name='ovehosted_vmenv_mem', note=_('Please specify the memory size of the VM in MB ' '(Defaults to {default_msg}): [@DEFAULT@]: ').format( default_msg=default_msg, ), prompt=True, hidden=False, tests=( { 'test': _check_memory_is_int, 'is_error': True, }, { 'test': _check_memory_value, 'warn_name': ohostedcons.Confirms.MEMORY_PROCEED, 'warn_note': _('Continue with specified memory size?'), 'is_error': False, }, ), default=default, store=True, ) # ensure that value is stored as integer. _check_memory_is_int # already ensured that value is a valid integer before. self.environment[ohostedcons.VMEnv.MEM_SIZE_MB] = int( self.environment[ohostedcons.VMEnv.MEM_SIZE_MB])
def _customization(self): maxmem = int(self._getMaxMemorySize()) if maxmem < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: self.logger.warning( _( 'Minimum requirements not met by available memory: ' 'Required: {memsize} MB. Available: {maxmem} MB' ).format( memsize=ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB, maxmem=maxmem, ) ) default = ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB default_msg = _('minimum requirement') if self.environment[ ohostedcons.VMEnv.APPLIANCEMEM ] is not None: default = self.environment[ohostedcons.VMEnv.APPLIANCEMEM] default_msg = _('appliance OVF value') if default > maxmem: default = maxmem default_msg = _('maximum available') def _check_min_memory(mem_size_mb): if not self.environment[ ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED ]: return None try: if int( mem_size_mb ) < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: return _( 'Minimum requirements for memory size not met' ) except ValueError: return _( 'Invalid memory size specified: {size}' ).format( size=mem_size_mb, ) def _check_memory_is_int(mem_size_mb): try: int(mem_size_mb) except ValueError: return _( 'Invalid memory size specified: {size}' ).format( size=mem_size_mb, ) def _check_memory_value(mem_size_mb): if not self.environment[ ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED ]: return None if int( mem_size_mb ) < ohostedcons.Defaults.MINIMAL_MEM_SIZE_MB: return _( 'Minimum requirements for memory size not met' ) if int( mem_size_mb ) > maxmem: return _( 'Invalid memory size specified: {memsize}, ' 'while only {maxmem} are available on ' 'the host' ).format( memsize=mem_size_mb, maxmem=maxmem, ) dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.VMEnv.MEM_SIZE_MB, name='ovehosted_vmenv_mem', note=_( 'Please specify the memory size of the VM in MB ' '[Defaults to {default_msg}: @DEFAULT@]: ' ).format( default_msg=default_msg, ), prompt=True, hidden=False, tests=( { 'test': _check_memory_is_int, 'is_error': True, }, { 'test': _check_memory_value, 'warn_name': ohostedcons.Confirms.MEMORY_PROCEED, 'warn_note': _( 'Continue with specified memory size?' ), 'is_error': False, }, ), default=default, store=True, )
def _customization(self): if self.environment[ohostedcons.CloudInit.VM_TZ] is None: self.environment[ohostedcons.CloudInit.VM_TZ] = self._get_host_tz() if self.environment[ohostedcons.CoreEnv.ANSIBLE_DEPLOYMENT]: self.environment[ ohostedcons.CloudInit. GENERATE_ISO] = ohostedcons.Const.CLOUD_INIT_GENERATE if self.environment[ohostedcons.CloudInit.GENERATE_ISO] is None: if self.dialog.queryString( name='CLOUD_INIT_USE', note=_('Would you like to use cloud-init to customize the ' 'appliance on the first boot ' '(@VALUES@)[@DEFAULT@]? '), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes')) == _('Yes').lower(): if self.dialog.queryString( name='CLOUD_INIT_GENERATE', note=_( 'Would you like to generate on-fly a cloud-init ' 'ISO image (of no-cloud type)\n' 'or do you have an existing one ' '(@VALUES@)[@DEFAULT@]? '), prompt=True, validValues=(_('Generate'), _('Existing')), caseSensitive=False, default=_('Generate')) == _('Generate').lower(): self.environment[ ohostedcons.CloudInit. GENERATE_ISO] = ohostedcons.Const.CLOUD_INIT_GENERATE else: self.environment[ ohostedcons.CloudInit. GENERATE_ISO] = ohostedcons.Const.CLOUD_INIT_EXISTING else: self.environment[ ohostedcons.CloudInit. GENERATE_ISO] = ohostedcons.Const.CLOUD_INIT_SKIP if self.environment[ ohostedcons.CloudInit. GENERATE_ISO] == ohostedcons.Const.CLOUD_INIT_GENERATE: if not self.environment[ohostedcons.CloudInit.INSTANCE_HOSTNAME]: instancehname = self._hostname_helper.getHostname( envkey=None, whichhost='CI_INSTANCE_HOSTNAME', supply_default=False, prompttext=_( 'Please provide the FQDN you would like to use for ' 'the engine appliance.\n' 'Note: This will be the FQDN of the engine VM ' 'you are now going to launch,\nit should not ' 'point to the base host or to any other ' 'existing machine.\n' 'Engine VM FQDN: (leave it empty to skip): '), dialog_name='CI_INSTANCE_HOSTNAME', validate_syntax=True, system=True, dns=False, local_non_loopback=False, reverse_dns=False, not_local=True, not_local_text=_( 'Please input the hostname for the engine VM, ' 'not for this host.'), allow_empty=True, ) if instancehname: self.environment[ohostedcons.CloudInit. INSTANCE_HOSTNAME] = instancehname else: self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME] = False if (self.environment[ohostedcons.CloudInit.INSTANCE_HOSTNAME] and self.environment[ohostedcons.CloudInit.INSTANCE_DOMAINNAME] is None): default_domain = '' if '.' in self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME]: default_domain = self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME].split('.', 1)[1] self.environment[ ohostedcons.CloudInit. INSTANCE_DOMAINNAME] = self.dialog.queryString( name='CI_INSTANCE_DOMAINNAME', note=_( 'Please provide the domain name you would like to ' 'use for the engine appliance.\n' 'Engine VM domain: [@DEFAULT@]'), prompt=True, default=default_domain, ) if not self.environment[ohostedcons.CloudInit.EXECUTE_ESETUP]: self.environment[ ohostedcons.CloudInit. EXECUTE_ESETUP] = self.dialog.queryString( name='CI_EXECUTE_ESETUP', note=_( 'Automatically execute ' 'engine-setup on the engine appliance on first boot ' '(@VALUES@)[@DEFAULT@]? '), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes')) == _('Yes').lower() if self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP] and self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME] is None: self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME] = 'Default' if self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP] and self.environment[ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN] is None: self.environment[ ohostedcons.VMEnv. AUTOMATE_VM_SHUTDOWN] = self.dialog.queryString( name='AUTOMATE_VM_SHUTDOWN', note=_('Automatically restart the engine VM ' 'as a monitored service after engine-setup ' '(@VALUES@)[@DEFAULT@]? '), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes')) == _('Yes').lower() if (self.environment[ohostedcons.CloudInit.INSTANCE_HOSTNAME] or self.environment[ohostedcons.CloudInit.EXECUTE_ESETUP] or self.environment[ohostedcons.CloudInit.VM_STATIC_CIDR] or self.environment[ohostedcons.CloudInit.VM_DNS]): self.environment[ ohostedcons.CloudInit. GENERATE_ISO] = ohostedcons.Const.CLOUD_INIT_GENERATE self._enable = True if self.environment[ ohostedcons.CloudInit. GENERATE_ISO] == ohostedcons.Const.CLOUD_INIT_GENERATE: while self.environment[ohostedcons.CloudInit.ROOTPWD] is None: skip_password = _(': ') if not self.environment[ ohostedcons.CoreEnv.ANSIBLE_DEPLOYMENT]: skip_password = _(' (leave it empty to skip): ') password = self.dialog.queryString( name='CI_ROOT_PASSWORD', note="{prefix}{skip_password}".format( prefix=_("Enter root password that " 'will be used for the engine appliance'), skip_password=skip_password), prompt=True, hidden=True, default='', ).strip() if password: password_check = self.dialog.queryString( name='CI_ROOT_PASSWORD', note=_("Confirm appliance root password: "******"Enter ssh public key for the root user that " 'will be used for the engine appliance ' '(leave it empty to skip): '), prompt=True, hidden=False, default='', ).strip() if pubkey: fd, pkfilename = tempfile.mkstemp(suffix='pub') pkfile = os.fdopen(fd, 'w') try: pkfile.write(pubkey) finally: pkfile.close() rc, stdout, stderr = self.execute( ( self.command.get('ssh-keygen'), '-lf', pkfilename, ), raiseOnError=False, ) os.unlink(pkfilename) if rc != 0: self.logger.error(_('The ssh key is not valid.')) else: self.environment[ ohostedcons.CloudInit.ROOT_SSH_PUBKEY] = pubkey else: self.environment[ ohostedcons.CloudInit.ROOT_SSH_PUBKEY] = '' self.logger.warning( _('Skipping appliance root ssh public key')) vv_root_a = ( 'yes', 'no', 'without-password', ) dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.CloudInit.ROOT_SSH_ACCESS, name='CI_ROOT_SSH_ACCESS', note=_('Do you want to enable ssh access for the root user ' '(@VALUES@) [@DEFAULT@]: '), prompt=True, hidden=False, default=vv_root_a[0], store=True, validValues=vv_root_a, caseSensitive=False, ) if (self.environment[ohostedcons.CloudInit.GENERATE_ISO] != ohostedcons.Const.CLOUD_INIT_GENERATE or not self.environment[ohostedcons.CloudInit.ROOTPWD] or self.environment[ohostedcons.CloudInit.ROOTPWD].strip() == ''): self.logger.warning( _('The oVirt engine appliance is not configured with a ' 'default password, please consider configuring it ' 'via cloud-init'))
def _customization(self): if self.environment[ ohostedcons.CloudInit.VM_TZ ] is None: self.environment[ohostedcons.CloudInit.VM_TZ] = self._get_host_tz() self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_GENERATE self.environment[ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN ] = True self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] = True if self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] is None: if self.dialog.queryString( name='CLOUD_INIT_USE', note=_( 'Would you like to use cloud-init to customize the ' 'appliance on the first boot ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes') ) == _('Yes').lower(): if self.dialog.queryString( name='CLOUD_INIT_GENERATE', note=_( 'Would you like to generate on-fly a cloud-init ' 'ISO image (of no-cloud type)\n' 'or do you have an existing one ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Generate'), _('Existing')), caseSensitive=False, default=_('Generate') ) == _('Generate').lower(): self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_GENERATE else: self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_EXISTING else: self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_SKIP if self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] == ohostedcons.Const.CLOUD_INIT_GENERATE: if not self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ]: if self.environment[ ohostedcons.CoreEnv.RESTORE_FROM_FILE ]is not None: self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] = self._get_fqdn_from_backup_file() self.logger.info(_( 'Using Engine VM FQDN {v} from backup file.').format( v=self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] ) ) self.logger.info(_( 'Using domain name from backup file.' )) else: instancehname = self._hostname_helper.getHostname( envkey=None, whichhost='CI_INSTANCE_HOSTNAME', supply_default=False, prompttext=_( 'Please provide the FQDN you would like to use ' 'for the engine.\n' 'Note: This will be the FQDN of the engine VM ' 'you are now going to launch,\nit should not ' 'point to the base host or to any other ' 'existing machine.\n' 'Engine VM FQDN' ), dialog_name='CI_INSTANCE_HOSTNAME', validate_syntax=True, system=True, dns=False, local_non_loopback=False, reverse_dns=False, not_local=True, not_local_text=_( 'Please input the hostname for the engine VM, ' 'not for this host.' ), allow_empty=False, ) if instancehname: self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] = instancehname else: self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] = False if ( self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] and self.environment[ ohostedcons.CloudInit.INSTANCE_DOMAINNAME ] is None ): default_domain = '' if '.' in self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ]: default_domain = self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ].split('.', 1)[1] self.environment[ ohostedcons.CloudInit.INSTANCE_DOMAINNAME ] = self.dialog.queryString( name='CI_INSTANCE_DOMAINNAME', note=_( 'Please provide the domain name you would like to ' 'use for the engine appliance.\n' 'Engine VM domain [@DEFAULT@]: ' ), prompt=True, default=default_domain, ) if not self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ]: self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] = self.dialog.queryString( name='CI_EXECUTE_ESETUP', note=_( 'Automatically execute ' 'engine-setup on the engine appliance on first boot ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes') ) == _('Yes').lower() if self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] and self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME ] is None: self.environment[ ohostedcons.EngineEnv.HOST_CLUSTER_NAME ] = ohostedcons.Defaults.DEFAULT_CLUSTER_NAME if self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] and self.environment[ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN ] is None: self.environment[ ohostedcons.VMEnv.AUTOMATE_VM_SHUTDOWN ] = self.dialog.queryString( name='AUTOMATE_VM_SHUTDOWN', note=_( 'Automatically restart the engine VM ' 'as a monitored service after engine-setup ' '(@VALUES@)[@DEFAULT@]? ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('Yes') ) == _('Yes').lower() if ( self.environment[ ohostedcons.CloudInit.INSTANCE_HOSTNAME ] or self.environment[ ohostedcons.CloudInit.EXECUTE_ESETUP ] or self.environment[ ohostedcons.CloudInit.VM_STATIC_CIDR ] or self.environment[ ohostedcons.CloudInit.VM_DNS ] ): self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] = ohostedcons.Const.CLOUD_INIT_GENERATE self._enable = True if self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] == ohostedcons.Const.CLOUD_INIT_GENERATE: attemps = 0 while self.environment[ ohostedcons.CloudInit.ROOTPWD ] is None and attemps < ohostedcons.Const.MAX_DIALOG_ATTEMPTS: password = self.dialog.queryString( name='CI_ROOT_PASSWORD', note=_( 'Enter root password that ' 'will be used for the engine appliance: ' ), prompt=True, hidden=True, default='', ).strip() if password: password_check = self.dialog.queryString( name='CI_ROOT_PASSWORD', note=_( "Confirm appliance root password: "******"\nYou may provide an SSH public key, that will be " "added by the deployment script to the " "authorized_keys file of the root user in the engine " "appliance.\n" "This should allow you passwordless login to the " "engine machine after deployment.\n" "If you provide no key, authorized_keys will not be " "touched.\n" "SSH public key []: " ), prompt=True, hidden=False, default='', ).strip() if pubkey: fd, pkfilename = tempfile.mkstemp(suffix='pub') pkfile = os.fdopen(fd, 'w') try: pkfile.write(pubkey) finally: pkfile.close() rc, stdout, stderr = self.execute( ( self.command.get('ssh-keygen'), '-lf', pkfilename, ), raiseOnError=False, ) os.unlink(pkfilename) if rc != 0: self.logger.error(_( 'The ssh key is not valid.' )) else: self.environment[ ohostedcons.CloudInit.ROOT_SSH_PUBKEY ] = pubkey else: self.environment[ ohostedcons.CloudInit.ROOT_SSH_PUBKEY ] = '' self.logger.warning(_( 'Skipping appliance root ssh public key' )) vv_root_a = ( 'yes', 'no', 'without-password', ) dialog.queryEnvKey( dialog=self.dialog, logger=self.logger, env=self.environment, key=ohostedcons.CloudInit.ROOT_SSH_ACCESS, name='CI_ROOT_SSH_ACCESS', note=_( 'Do you want to enable ssh access for the root user? ' '(@VALUES@) [@DEFAULT@]: ' ), prompt=True, hidden=False, default=vv_root_a[0], store=True, validValues=vv_root_a, caseSensitive=False, ) if self.environment[ ohostedcons.CloudInit.APPLY_OPENSCAP_PROFILE ] is None: self.environment[ ohostedcons.CloudInit.APPLY_OPENSCAP_PROFILE ] = self.dialog.queryString( name='CI_APPLY_OPENSCAP_PROFILE', note=_( 'Do you want to apply a default OpenSCAP security ' 'profile? (@VALUES@) [@DEFAULT@]: ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('No') ) == _('Yes').lower() if self.environment[ ohostedcons.CloudInit.ENABLE_FIPS ] is None and self.environment[ ohostedcons.CloudInit.APPLY_OPENSCAP_PROFILE ] is False: self.environment[ ohostedcons.CloudInit.ENABLE_FIPS ] = self.dialog.queryString( name='CI_ENABLE_FIPS', note=_( 'Do you want to enable FIPS? ' '(@VALUES@) [@DEFAULT@]: ' ), prompt=True, validValues=(_('Yes'), _('No')), caseSensitive=False, default=_('No') ) == _('Yes').lower() if ( self.environment[ ohostedcons.CloudInit.GENERATE_ISO ] != ohostedcons.Const.CLOUD_INIT_GENERATE or not self.environment[ ohostedcons.CloudInit.ROOTPWD ] or self.environment[ ohostedcons.CloudInit.ROOTPWD ].strip() == '' ): self.logger.warning(_( 'The oVirt engine appliance is not configured with a ' 'default password, please consider configuring it ' 'via cloud-init' ))