def get_base_dictionary(): base_dict = {} current_user_name = get_user() base_dict["edi_current_user_name"] = current_user_name base_dict["edi_current_user_group_name"] = get_user_group() base_dict["edi_current_user_ssh_pub_keys"] = get_user_ssh_pub_keys() base_dict["edi_current_user_uid"] = get_user_uid() base_dict["edi_current_user_gid"] = get_user_gid() base_dict[ "edi_current_user_host_home_directory"] = get_user_home_directory( current_user_name) base_dict["edi_current_user_target_home_directory"] = "/home/{}".format( current_user_name) base_dict["edi_host_hostname"] = get_hostname() base_dict["edi_edi_plugin_directory"] = get_edi_plugin_directory() proxy_setup = ProxySetup() base_dict["edi_host_http_proxy"] = proxy_setup.get('http_proxy', default='') base_dict["edi_host_https_proxy"] = proxy_setup.get('https_proxy', default='') base_dict["edi_host_ftp_proxy"] = proxy_setup.get('ftp_proxy', default='') base_dict["edi_host_socks_proxy"] = proxy_setup.get('all_proxy', default='') base_dict["edi_host_no_proxy"] = proxy_setup.get('no_proxy', default='') base_dict["edi_edi_version"] = get_edi_version() base_dict["edi_lxd_version"] = get_lxd_version() base_dict["edi_current_display"] = get_current_display() return base_dict
def __init__(self, base_config_file): self.base_config_file = base_config_file self.project_directory = dirname(abspath(base_config_file.name)) self.config_id = splitext(basename(base_config_file.name))[0] if not ConfigurationParser._configurations.get(self.config_id): logging.info(("Load time dictionary:\n{}").format( yaml.dump(remove_passwords(self._get_load_time_dictionary()), default_flow_style=False))) logging.info(("Using base configuration file '{0}'").format( base_config_file.name)) base_config = self._get_base_config(base_config_file) global_config = self._get_overlay_config(base_config_file, "global") hostname = get_hostname() system_config = self._get_overlay_config(base_config_file, hostname) user = get_user() if user == hostname: user = '******'.format(user) logging.warning(( "User name and host name are equal! Going to search user overlay file " "with '.user' postfix.")) user_config = self._get_overlay_config(base_config_file, user) merge_1 = self._merge_configurations(base_config, global_config) merge_2 = self._merge_configurations(merge_1, system_config) merged_config = self._merge_configurations(merge_2, user_config) ConfigurationParser._configurations[self.config_id] = merged_config logging.info("Merged configuration:\n{0}".format(self.dump())) self._verify_version_compatibility()
def __init__(self, base_config_file): self.config_directory = dirname(abspath(base_config_file.name)) self.config_id = splitext(basename(base_config_file.name))[0] if not ConfigurationParser._configurations.get(self.config_id): logging.info(("Load time dictionary:\n{}").format( yaml.dump(self._get_load_time_dictionary(), default_flow_style=False))) logging.info(("Using base configuration file '{0}'").format( base_config_file.name)) base_config = self._get_base_config(base_config_file) global_config = self._get_overlay_config(base_config_file, "global") system_config = self._get_overlay_config(base_config_file, get_hostname()) user_config = self._get_overlay_config(base_config_file, get_user()) merge_1 = self._merge_configurations(base_config, global_config) merge_2 = self._merge_configurations(merge_1, system_config) merged_config = self._merge_configurations(merge_2, user_config) ConfigurationParser._configurations[self.config_id] = merged_config logging.info("Merged configuration:\n{0}".format(self.dump())) self._verify_version_compatibility()
def config_files(tmpdir_factory): dir_name = tmpdir_factory.mktemp('configuration') main_file = "{0}.yml".format(_config_name) with open(str(dir_name.join(main_file)), "w") as file: file.write(sample_file) overlay_dir = dir_name.join("configuration", "overlay") os.makedirs(str(overlay_dir)) overlays = [("global", sample_global_file), (get_user(), sample_user_file), (get_hostname(), sample_system_file)] for overlay in overlays: o_type, o_content = overlay o_file_name = "{0}.{1}.yml".format(_config_name, o_type) with open(str(overlay_dir.join(o_file_name)), "w") as o_file: o_file.write(o_content) for subdir in ['playbooks', 'templates', 'profiles']: directory = dir_name.join("plugins", subdir) os.makedirs(str(directory)) with open(str(directory.join("foo.yml")), "w") as file: file.write("baz") commands_dir = dir_name.join("plugins", "commands") os.makedirs(str(commands_dir)) commands = [ ('first', first_command), ('second', second_command), ('last', last_command), ] for name, content in commands: with open(str(commands_dir.join(name)), "w") as file: file.write(content) return str(dir_name.join(main_file))
def get_base_dictionary(): base_dict = {} current_user_name = get_user() base_dict["edi_current_user_name"] = current_user_name base_dict["edi_current_user_uid"] = get_user_uid() base_dict["edi_current_user_gid"] = get_user_gid() base_dict[ "edi_current_user_host_home_directory"] = get_user_environment_variable( "HOME") base_dict["edi_current_user_target_home_directory"] = "/home/{}".format( current_user_name) base_dict["edi_host_hostname"] = get_hostname() base_dict["edi_edi_plugin_directory"] = get_edi_plugin_directory() base_dict["edi_host_http_proxy"] = get_user_environment_variable( 'http_proxy', '') base_dict["edi_host_https_proxy"] = get_user_environment_variable( 'https_proxy', '') base_dict["edi_host_ftp_proxy"] = get_user_environment_variable( 'ftp_proxy', '') base_dict["edi_host_socks_proxy"] = get_user_environment_variable( 'all_proxy', '') base_dict["edi_host_no_proxy"] = get_user_environment_variable( 'no_proxy', '') base_dict["edi_lxd_version"] = get_lxd_version() return base_dict
def config_files(tmpdir_factory): dir_name = tmpdir_factory.mktemp('configuration') main_file = "{0}.yml".format(config_name) with open(str(dir_name.join(main_file)), "w") as file: file.write(sample_file) overlay_dir = dir_name.join("configuration", "overlay") os.makedirs(str(overlay_dir)) overlays = [("global", sample_global_file), (get_user(), sample_user_file), (get_hostname(), sample_system_file)] for overlay in overlays: o_type, o_content = overlay o_file_name = "{0}.{1}.yml".format(config_name, o_type) with open(str(overlay_dir.join(o_file_name)), "w") as o_file: o_file.write(o_content) playbook_dir = dir_name.join("plugins", "playbooks") os.makedirs(str(playbook_dir)) with open(str(playbook_dir.join("foo.yml")), "w") as file: file.write("baz") return str(dir_name.join(main_file))