def _copy_manager_blueprint(self):
     inputs_path, mb_path = util.generate_unique_configurations(
         workdir=self.workdir,
         original_inputs_path=self.env.cloudify_config_path,
         original_manager_blueprint_path=self.env._manager_blueprint_path)
     self.test_manager_blueprint_path = path(mb_path)
     self.test_inputs_path = path(inputs_path)
Пример #2
0
def _generate_configuration(cmd_inputs_override,
                            cmd_blueprint_override,
                            conf_obj,
                            conf_key,
                            conf_name,
                            conf_additional,
                            conf_blueprint_key,
                            blueprint_dir_name,
                            blueprint_override_key,
                            blueprint_override_template_key,
                            blueprint_path,
                            reset,
                            properties,
                            user_yaml):
    if conf_name not in user_yaml[conf_key]:
        raise NO_SUCH_CONFIGURATION
    conf = user_yaml[conf_key][conf_name]
    cmd_inputs_override = [user_yaml['inputs_override_templates'][key]
                           for key in (cmd_inputs_override or [])]
    cmd_blueprint_override = [user_yaml[blueprint_override_template_key][key]
                              for key in (cmd_blueprint_override or [])]
    original_inputs_path = os.path.expanduser(conf.get('inputs', ''))
    original_blueprint_path = os.path.expanduser(conf[conf_blueprint_key])
    if conf_obj.exists():
        if reset:
            if conf_obj.dir == os.getcwd():
                os.chdir(conf_obj.dir.dirname())
            shutil.rmtree(conf_obj.dir)
        else:
            raise ALREADY_INITIALIZED
    conf_obj.dir.makedirs()
    if not original_inputs_path:
        fd, original_inputs_path = tempfile.mkstemp()
        os.close(fd)
        with open(original_inputs_path, 'w') as f:
            f.write('{}')
    _, tmp_blueprint_path = util.generate_unique_configurations(
        workdir=conf_obj.dir,
        original_inputs_path=original_inputs_path,
        original_manager_blueprint_path=original_blueprint_path,
        manager_blueprint_dir_name=blueprint_dir_name)
    shutil.move(tmp_blueprint_path, blueprint_path)
    conf['inputs'] = str(conf_obj.inputs_path)
    conf[conf_blueprint_key] = str(blueprint_path)
    conf.update(conf_additional or {})
    user_yaml['variables'] = user_yaml.get('variables', {})
    user_yaml['variables']['properties'] = properties or {}
    overrides = [
        (conf_obj.inputs_path, 'inputs_override', cmd_inputs_override),
        (blueprint_path, blueprint_override_key, cmd_blueprint_override)
    ]
    for yaml_path, prop, additional_overrides in overrides:
        unprocessed = conf.pop(prop, {})
        for additional in additional_overrides:
            unprocessed.update(additional)
        override = util.process_variables(user_yaml, unprocessed)
        with patcher.YamlPatcher(yaml_path, default_flow_style=False) as patch:
            for k, v in override.items():
                patch.set_value(k, v)
    return conf
 def _generate_unique_configurations(self):
     inputs_path, manager_blueprint_path = generate_unique_configurations(
         workdir=self._workdir,
         original_inputs_path=self.cloudify_config_path,
         original_manager_blueprint_path=self._manager_blueprint_path)
     self.cloudify_config_path = inputs_path
     self._manager_blueprint_path = manager_blueprint_path
Пример #4
0
 def _generate_unique_configurations(self):
     inputs_path, manager_blueprint_path = generate_unique_configurations(
         workdir=self._workdir,
         original_inputs_path=self.cloudify_config_path,
         original_manager_blueprint_path=self._manager_blueprint_path)
     self.cloudify_config_path = inputs_path
     self._manager_blueprint_path = manager_blueprint_path
Пример #5
0
def _generate_configuration(cmd_inputs_override,
                            cmd_blueprint_override,
                            conf_obj,
                            conf_key,
                            conf_name,
                            conf_additional,
                            conf_blueprint_key,
                            blueprint_dir_name,
                            blueprint_override_key,
                            blueprint_override_template_key,
                            blueprint_path,
                            reset,
                            properties,
                            user_yaml):
    if conf_name not in user_yaml[conf_key]:
        raise NO_SUCH_CONFIGURATION
    conf = user_yaml[conf_key][conf_name]
    cmd_inputs_override = [user_yaml['inputs_override_templates'][key]
                           for key in (cmd_inputs_override or [])]
    cmd_blueprint_override = [user_yaml[blueprint_override_template_key][key]
                              for key in (cmd_blueprint_override or [])]
    original_inputs_path = os.path.expanduser(conf.get('inputs', ''))
    original_blueprint_path = os.path.expanduser(conf[conf_blueprint_key])
    if conf_obj.dir.exists():
        if reset:
            if conf_obj.dir == os.getcwd():
                os.chdir(conf_obj.dir.dirname())
            shutil.rmtree(conf_obj.dir)
        else:
            raise ALREADY_INITIALIZED
    conf_obj.dir.makedirs()
    if not original_inputs_path:
        fd, original_inputs_path = tempfile.mkstemp()
        os.close(fd)
        with open(original_inputs_path, 'w') as f:
            f.write('{}')
    _, tmp_blueprint_path = util.generate_unique_configurations(
        workdir=conf_obj.dir,
        original_inputs_path=original_inputs_path,
        original_manager_blueprint_path=original_blueprint_path,
        manager_blueprint_dir_name=blueprint_dir_name)
    shutil.move(tmp_blueprint_path, blueprint_path)
    conf['inputs'] = str(conf_obj.inputs_path)
    conf[conf_blueprint_key] = str(blueprint_path)
    conf.update(conf_additional or {})
    user_yaml['variables'] = user_yaml.get('variables', {})
    user_yaml['variables']['properties'] = properties or {}
    overrides = [
        (conf_obj.inputs_path, 'inputs_override', cmd_inputs_override),
        (blueprint_path, blueprint_override_key, cmd_blueprint_override)
    ]
    for yaml_path, prop, additional_overrides in overrides:
        unprocessed = conf.pop(prop, {})
        for additional in additional_overrides:
            unprocessed.update(additional)
        override = util.process_variables(user_yaml, unprocessed)
        with patcher.YamlPatcher(yaml_path, default_flow_style=False) as patch:
            for k, v in override.items():
                patch.set_value(k, v)
    return conf
 def _copy_manager_blueprint(self):
     inputs_path, mb_path = util.generate_unique_configurations(
         workdir=self.workdir,
         original_inputs_path=self.env.cloudify_config_path,
         original_manager_blueprint_path=self.env._manager_blueprint_path)
     self.test_manager_blueprint_path = path(mb_path)
     self.test_inputs_path = path(inputs_path)
     self.test_manager_types_path = os.path.join(
         self.workdir, 'manager-blueprint/types/manager-types.yaml')
Пример #7
0
 def _copy_manager_blueprint(self):
     inputs_path, mb_path = util.generate_unique_configurations(
         workdir=self.workdir,
         original_inputs_path=self.env.cloudify_config_path,
         original_manager_blueprint_path=self.env._manager_blueprint_path)
     self.test_manager_blueprint_path = path(mb_path)
     self.test_inputs_path = path(inputs_path)
     self.test_manager_types_path = os.path.join(
         self.workdir, 'manager-blueprint/types/manager-types.yaml')