Exemplo n.º 1
0
def read_global_environment(env, env_dir=None):
    if env_dir is None:
        cfg.CONF.import_opt('environment_dir', 'heat.common.config')
        env_dir = cfg.CONF.environment_dir

    try:
        env_files = glob.glob(os.path.join(env_dir, '*'))
    except OSError as osex:
        LOG.error(_LE('Failed to read %s'), env_dir)
        LOG.exception(osex)
        return

    for file_path in env_files:
        try:
            with open(file_path) as env_fd:
                LOG.info(_LI('Loading %s'), file_path)
                env_body = env_fmt.parse(env_fd.read())
                env_fmt.default_for_missing(env_body)
                env.load(env_body)
        except ValueError as vex:
            LOG.error(_LE('Failed to parse %(file_path)s'), {
                      'file_path': file_path})
            LOG.exception(vex)
        except IOError as ioex:
            LOG.error(_LE('Failed to read %(file_path)s'), {
                      'file_path': file_path})
            LOG.exception(ioex)
Exemplo n.º 2
0
def _load_global_environment(env, env_dir=None):
    if env_dir is None:
        cfg.CONF.import_opt('environment_dir', 'heat.common.config')
        env_dir = cfg.CONF.environment_dir

    for env_name in _list_environment_files(env_dir):
        try:
            file_path = os.path.join(env_dir, env_name)
            with open(file_path) as env_fd:
                LOG.info(_('Loading %s') % file_path)
                env_body = environment_format.parse(env_fd.read())
                environment_format.default_for_missing(env_body)
                env.load(env_body)
        except ValueError as vex:
            LOG.error(
                _('Failed to parse %(dir)s/%(name)s') % {
                    'dir': env_dir,
                    'name': env_name
                })
            LOG.exception(vex)
        except IOError as ioex:
            LOG.error(
                _('Failed to read %(dir)s/%(name)s') % {
                    'dir': env_dir,
                    'name': env_name
                })
            LOG.exception(ioex)
Exemplo n.º 3
0
    def test_minimal_yaml(self):
        yaml1 = ''
        yaml2 = '''
parameters: {}
resource_registry: {}
'''
        tpl1 = environment_format.parse(yaml1)
        environment_format.default_for_missing(tpl1)
        tpl2 = environment_format.parse(yaml2)
        self.assertEqual(tpl1, tpl2)
    def test_minimal_yaml(self):
        yaml1 = ''
        yaml2 = '''
parameters: {}
resource_registry: {}
'''
        tpl1 = environment_format.parse(yaml1)
        environment_format.default_for_missing(tpl1)
        tpl2 = environment_format.parse(yaml2)
        self.assertEqual(tpl1, tpl2)
    def test_minimal_yaml(self):
        yaml1 = ''
        yaml2 = '''
parameters: {}
encrypted_param_names: []
parameter_defaults: {}
event_sinks: []
resource_registry: {}
'''
        tpl1 = environment_format.parse(yaml1)
        environment_format.default_for_missing(tpl1)
        tpl2 = environment_format.parse(yaml2)
        self.assertEqual(tpl1, tpl2)
Exemplo n.º 6
0
    def test_minimal_yaml(self):
        yaml1 = ''
        yaml2 = '''
parameters: {}
encrypted_param_names: []
parameter_defaults: {}
event_sinks: []
resource_registry: {}
'''
        tpl1 = environment_format.parse(yaml1)
        environment_format.default_for_missing(tpl1)
        tpl2 = environment_format.parse(yaml2)
        self.assertEqual(tpl1, tpl2)
    def test_param_valid_strategy_section(self):
        yaml1 = ''
        yaml2 = '''
parameters: {}
encrypted_param_names: []
parameter_defaults: {}
parameter_merge_strategies: {}
event_sinks: []
resource_registry: {}
'''
        tpl1 = environment_format.parse(yaml1)
        environment_format.default_for_missing(tpl1)
        tpl2 = environment_format.parse(yaml2)
        self.assertNotEqual(tpl1, tpl2)
Exemplo n.º 8
0
    def test_param_valid_strategy_section(self):
        yaml1 = ''
        yaml2 = '''
parameters: {}
encrypted_param_names: []
parameter_defaults: {}
parameter_merge_strategies: {}
event_sinks: []
resource_registry: {}
'''
        tpl1 = environment_format.parse(yaml1)
        environment_format.default_for_missing(tpl1)
        tpl2 = environment_format.parse(yaml2)
        self.assertNotEqual(tpl1, tpl2)
Exemplo n.º 9
0
def _load_global_environment(env_dir):
    for env_name in _list_environment_files(env_dir):
        try:
            file_path = os.path.join(env_dir, env_name)
            with open(file_path) as env_fd:
                LOG.info('Loading %s' % file_path)
                env_body = environment_format.parse(env_fd.read())
                environment_format.default_for_missing(env_body)
                _environment.load(env_body)
        except ValueError as vex:
            LOG.error('Failed to parse %s/%s' % (env_dir, env_name))
            LOG.exception(vex)
        except IOError as ioex:
            LOG.error('Failed to read %s/%s' % (env_dir, env_name))
            LOG.exception(ioex)
Exemplo n.º 10
0
    def environment(self):
        """
        Get the user-supplied environment for the stack in YAML format.
        If the user supplied Parameters then merge these into the
        environment global options.
        """
        env = {}
        if self.PARAM_ENVIRONMENT in self.data:
            env_data = self.data[self.PARAM_ENVIRONMENT]
            if isinstance(env_data, dict):
                env = env_data
            else:
                env = self.format_parse(env_data, 'Environment')

        environment_format.default_for_missing(env)
        parameters = self.data.get(self.PARAM_USER_PARAMS, {})
        env[self.PARAM_USER_PARAMS].update(parameters)
        return env
Exemplo n.º 11
0
Arquivo: stacks.py Projeto: ii0/heat
 def no_change(self):
     assert self.patch
     return ((self.template() is None)
             and (self.environment()
                  == environment_format.default_for_missing({}))
             and (not self.files()) and (not self.environment_files())
             and (self.files_container() is None)
             and (not any(k != rpc_api.PARAM_EXISTING
                          for k in self.args().keys())))
Exemplo n.º 12
0
Arquivo: stacks.py Projeto: rmery/heat
    def environment(self):
        """
        Get the user-supplied environment for the stack in YAML format.
        If the user supplied Parameters then merge these into the
        environment global options.
        """
        env = {}
        if self.PARAM_ENVIRONMENT in self.data:
            env_data = self.data[self.PARAM_ENVIRONMENT]
            if isinstance(env_data, dict):
                env = env_data
            else:
                env = self.format_parse(env_data, "Environment")

        environment_format.default_for_missing(env)
        parameters = self.data.get(self.PARAM_USER_PARAMS, {})
        env[self.PARAM_USER_PARAMS].update(parameters)
        return env
Exemplo n.º 13
0
def _load_global_environment(env, env_dir=None):
    if env_dir is None:
        cfg.CONF.import_opt('environment_dir', 'heat.common.config')
        env_dir = cfg.CONF.environment_dir

    for env_name in _list_environment_files(env_dir):
        try:
            file_path = os.path.join(env_dir, env_name)
            with open(file_path) as env_fd:
                LOG.info('Loading %s' % file_path)
                env_body = environment_format.parse(env_fd.read())
                environment_format.default_for_missing(env_body)
                env.load(env_body)
        except ValueError as vex:
            LOG.error('Failed to parse %s/%s' % (env_dir, env_name))
            LOG.exception(vex)
        except IOError as ioex:
            LOG.error('Failed to read %s/%s' % (env_dir, env_name))
            LOG.exception(ioex)
Exemplo n.º 14
0
    def environment(self):
        """Get the user-supplied environment for the stack in YAML format.

        If the user supplied Parameters then merge these into the
        environment global options.
        """
        env = {}
        # Don't use merged environment, if environment_files are supplied.
        if (self.PARAM_ENVIRONMENT in self.data
                and not self.data.get(self.PARAM_ENVIRONMENT_FILES)):
            env_data = self.data[self.PARAM_ENVIRONMENT]
            with self.parse_error_check('Environment'):
                if isinstance(env_data, dict):
                    env = environment_format.validate(env_data)
                else:
                    env = environment_format.parse(env_data)

        environment_format.default_for_missing(env)
        parameters = self.data.get(self.PARAM_USER_PARAMS, {})
        env[self.PARAM_USER_PARAMS].update(parameters)
        return env
Exemplo n.º 15
0
Arquivo: stacks.py Projeto: sdake/heat
    def environment(self):
        """Get the user-supplied environment for the stack in YAML format.

        If the user supplied Parameters then merge these into the
        environment global options.
        """
        env = {}
        # Don't use merged environment, if environment_files are supplied.
        if (self.PARAM_ENVIRONMENT in self.data and
                not self.data.get(self.PARAM_ENVIRONMENT_FILES)):
            env_data = self.data[self.PARAM_ENVIRONMENT]
            with self.parse_error_check('Environment'):
                if isinstance(env_data, dict):
                    env = environment_format.validate(env_data)
                else:
                    env = environment_format.parse(env_data)

        environment_format.default_for_missing(env)
        parameters = self.data.get(self.PARAM_USER_PARAMS, {})
        env[self.PARAM_USER_PARAMS].update(parameters)
        return env
Exemplo n.º 16
0
def read_global_environment(env, env_dir=None):
    if env_dir is None:
        cfg.CONF.import_opt("environment_dir", "heat.common.config")
        env_dir = cfg.CONF.environment_dir

    try:
        env_files = glob.glob(os.path.join(env_dir, "*"))
    except OSError:
        LOG.exception(_LE("Failed to read %s"), env_dir)
        return

    for file_path in env_files:
        try:
            with open(file_path) as env_fd:
                LOG.info(_LI("Loading %s"), file_path)
                env_body = env_fmt.parse(env_fd.read())
                env_fmt.default_for_missing(env_body)
                env.load(env_body)
        except ValueError:
            LOG.exception(_LE("Failed to parse %s"), file_path)
        except IOError:
            LOG.exception(_LE("Failed to read %s"), file_path)