Example #1
0
    def read(self):
        """

        :return:
        :rtype shellfoundry.models.install_config.Installconfig
        """
        config_path = os.path.join(os.getcwd(), 'cloudshell_config.yml')

        if not os.path.isfile(config_path):
            return InstallConfig.get_default()

        with open(config_path) as stream:
            config = yaml.load(stream.read())

        if not config or INSTALL not in config:
            return InstallConfig.get_default()

        install_config = config[INSTALL]

        host = self._get_with_default(install_config, HOST, DEFAULT_HOST)
        port = self._get_with_default(install_config, PORT, DEFAULT_PORT)
        username = self._get_with_default(install_config, USERNAME, DEFAULT_USERNAME)
        password = self._get_with_default(install_config, PASSWORD, DEFAULT_PASSWORD)
        domain = self._get_with_default(install_config, DOMAIN, DEFAULT_DOMAIN)

        return InstallConfig(host, port, username, password, domain)
Example #2
0
    def readall(config_path, mark_defaults=None):
        """
        reads configuration from given file and adds missing keys with their defaults
        """
        config_data = None
        if os.path.exists(config_path):
            with open(config_path, mode="r") as conf_file:
                config_data = yaml.safe_load(conf_file)

        if not config_data or INSTALL not in config_data:
            config_data = {INSTALL: dict()}

        mark_defaults_f = Configuration._mark_defaults
        install_cfg_def = dict(
            (k, mark_defaults_f(v, mark_defaults)) for k, v in InstallConfig.get_default().__dict__.items())
        sf_cfg_def = dict(
            (k, mark_defaults_f(v, mark_defaults)) for k, v in ShellFoundrySettings.get_default().__dict__.items())
        all_cfg = dict(install_cfg_def)
        all_cfg.update(sf_cfg_def)
        all_cfg.update(config_data[INSTALL])
        return {INSTALL: all_cfg}
Example #3
0
 def get_defaults(self):
     return InstallConfig.get_default()