def set_yaml_config(config_name, data_dict, hostname=None): """Given a yaml name, dictionary and hostname, set the configuration yaml on the server The configuration yamls must be inserted into the DB using the ruby console, so this function uses SSH, not the database. It makes sense to be included here as a counterpart to :py:func:`get_yaml_config` Args: config_name: Name of the yaml configuration file data_dict: Dictionary with data to set/change hostname: Hostname/address of the server that we want to set up (default ``None``) Note: If hostname is set to ``None``, the default server set up for this session will be used. See :py:class:``utils.ssh.SSHClient`` for details of the default setup. Warning: Manually editing the config yamls is potentially dangerous. Furthermore, the rails runner doesn't return useful information on the outcome of the set request, so errors that arise from the newly loading config file will go unreported. Usage: # Update the appliance name, for example vmbd_yaml = get_yaml_config('vmdb') vmdb_yaml['server']['name'] = 'EVM IS AWESOME' set_yaml_config('vmdb', vmdb_yaml, '1.2.3.4') """ # CFME does a lot of things when loading a configfile, so # let their native conf loader handle the job # If hostname is defined, connect to the specified server if hostname is not None: _ssh_client = SSHClient(hostname=hostname) # Else, connect to the default one set up for this session else: _ssh_client = store.current_appliance.ssh_client # Build & send new config temp_yaml = NamedTemporaryFile() dest_yaml = '/tmp/conf.yaml' yaml.dump(data_dict, temp_yaml, default_flow_style=False) _ssh_client.put_file(temp_yaml.name, dest_yaml) # Build and send ruby script dest_ruby = '/tmp/load_conf.rb' ruby_template = data_path.join('utils', 'cfmedb_load_config.rbt') ruby_replacements = { 'config_name': config_name, 'config_file': dest_yaml } temp_ruby = load_data_file(ruby_template.strpath, ruby_replacements) _ssh_client.put_file(temp_ruby.name, dest_ruby) # Run it _ssh_client.run_rails_command(dest_ruby) fire('server_details_changed') fire('server_config_changed')
def delete(self, cancel=True): """ Deletes a provider from CFME Args: cancel: Whether to cancel the deletion, defaults to True """ sel.force_navigate('clouds_provider', context={'provider': self}) cfg_btn('Remove this Cloud Provider from the VMDB', invokes_alert=True) sel.handle_alert(cancel=cancel) fire("providers_changed") if not cancel: flash.assert_message_match( 'Delete initiated for 1 Cloud Provider from the CFME Database')
def delete(self, cancel=True): """ Deletes a provider from CFME Args: cancel: Whether to cancel the deletion, defaults to True """ self.load_details() cfg_btn('Remove this {} Provider from the VMDB'.format(self.string_name), invokes_alert=True) sel.handle_alert(cancel=cancel) fire("providers_changed") if not cancel: flash.assert_message_match( 'Delete initiated for 1 {} Provider from the CFME Database'.format( self.string_name))
def delete(self, cancel=True): """ Deletes a provider from CFME Args: cancel: Whether to cancel the deletion, defaults to True """ self.load_details() cfg_btn('Remove this {} Provider from the VMDB'.format( self.string_name), invokes_alert=True) sel.handle_alert(cancel=cancel) fire("providers_changed") if not cancel: flash.assert_message_match( 'Delete initiated for 1 {} Provider from the CFME Database'. format(self.string_name))
def create(self, cancel=False, validate_credentials=False): """ Creates a provider in the UI Args: cancel (boolean): Whether to cancel out of the creation. The cancel is done after all the information present in the Provider has been filled in the UI. validate_credentials (boolean): Whether to validate credentials - if True and the credentials are invalid, an error will be raised. """ sel.force_navigate('clouds_provider_new') fill(properties_form, self._form_mapping(True, **self.__dict__)) fill(credential_form, self.credentials, validate=validate_credentials) self._submit(cancel, add_provider_button) fire("providers_changed") if not cancel: flash.assert_message_match('Cloud Providers "%s" was saved' % self.name)
def create(self, cancel=False, validate_credentials=False): """ Creates a provider in the UI Args: cancel (boolean): Whether to cancel out of the creation. The cancel is done after all the information present in the Provider has been filled in the UI. validate_credentials (boolean): Whether to validate credentials - if True and the credentials are invalid, an error will be raised. """ sel.force_navigate('{}_provider_new'.format(self.page_name)) fill(self.properties_form, self._form_mapping(True, **self.__dict__)) for cred in self.credentials: fill(credential_form, self.credentials[cred], validate=validate_credentials) self._submit(cancel, self.add_provider_button) fire("providers_changed") if not cancel: flash.assert_message_match('{} Providers "{}" was saved'.format( self.string_name, self.name))