コード例 #1
0
 def test_process_stack_spec(self, mock_get_temp, mock_process):
     spec = {
         'template': 'temp.yaml',
         'disable_rollback': True,
         'context': {
             'region_name': 'RegionOne'
         },
     }
     tpl_files = {'fake_key1': 'fake_value1'}
     template = mock.Mock()
     mock_get_temp.return_value = tpl_files, template
     env_files = {'fake_key2': 'fake_value2'}
     env = mock.Mock()
     mock_process.return_value = env_files, env
     new_spec = utils.process_stack_spec(spec)
     stack_spec = {
         'disable_rollback': True,
         'context': {
             'region_name': 'RegionOne',
         },
         'parameters': {},
         'timeout': 60,
         'template': template,
         'files': {
             'fake_key1': 'fake_value1',
             'fake_key2': 'fake_value2',
         },
         'environment': env
     }
     self.assertEqual(stack_spec, new_spec)
     mock_get_temp.assert_called_once_with(template_file='temp.yaml')
     mock_process.assert_called_once_with(env_paths=None)
コード例 #2
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        senlin_client = self.app.client_manager.clustering

        spec = senlin_utils.get_spec_content(parsed_args.spec_file)
        type_name = spec.get('type', None)
        type_version = spec.get('version', None)
        properties = spec.get('properties', None)
        if type_name is None:
            raise exc.CommandError(_("Missing 'type' key in spec file."))
        if type_version is None:
            raise exc.CommandError(_("Missing 'version' key in spec file."))
        if properties is None:
            raise exc.CommandError(_("Missing 'properties' key in spec file."))

        if type_name == 'os.heat.stack':
            stack_properties = senlin_utils.process_stack_spec(properties)
            spec['properties'] = stack_properties

        params = {
            'name': parsed_args.name,
            'spec': spec,
            'metadata': senlin_utils.format_parameters(parsed_args.metadata),
        }

        profile = senlin_client.create_profile(**params)
        return _show_profile(senlin_client, profile_id=profile.id)
コード例 #3
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        senlin_client = self.app.client_manager.clustering

        spec = senlin_utils.get_spec_content(parsed_args.spec_file)
        type_name = spec.get('type', None)
        type_version = spec.get('version', None)
        properties = spec.get('properties', None)
        if type_name is None:
            raise exc.CommandError(_("Missing 'type' key in spec file."))
        if type_version is None:
            raise exc.CommandError(_("Missing 'version' key in spec file."))
        if properties is None:
            raise exc.CommandError(_("Missing 'properties' key in spec file."))

        if type_name == 'os.heat.stack':
            stack_properties = senlin_utils.process_stack_spec(properties)
            spec['properties'] = stack_properties

        params = {
            'name': parsed_args.name,
            'spec': spec,
            'metadata': senlin_utils.format_parameters(parsed_args.metadata),
        }

        profile = senlin_client.create_profile(**params)
        return _show_profile(senlin_client, profile_id=profile.id)
コード例 #4
0
 def test_process_stack_spec(self, mock_get_temp, mock_process):
     spec = {
         'template': 'temp.yaml',
         'disable_rollback': True,
         'context': {
             'region_name': 'RegionOne'
         },
     }
     tpl_files = {'fake_key1': 'fake_value1'}
     template = mock.Mock()
     mock_get_temp.return_value = tpl_files, template
     env_files = {'fake_key2': 'fake_value2'}
     env = mock.Mock()
     mock_process.return_value = env_files, env
     new_spec = utils.process_stack_spec(spec)
     stack_spec = {
         'disable_rollback': True,
         'context': {
             'region_name': 'RegionOne',
         },
         'parameters': {},
         'timeout': 60,
         'template': template,
         'files': {
             'fake_key1': 'fake_value1',
             'fake_key2': 'fake_value2',
         },
         'environment': env
     }
     self.assertEqual(stack_spec, new_spec)
     mock_get_temp.assert_called_once_with(template_file='temp.yaml')
     mock_process.assert_called_once_with(env_paths=None)
コード例 #5
0
ファイル: shell.py プロジェクト: zzxwill/python-senlinclient
def do_profile_create(service, args):
    """Create a profile."""

    spec = utils.get_spec_content(args.spec_file)
    type_name = spec.get('type', None)
    type_version = spec.get('version', None)
    properties = spec.get('properties', None)
    if type_name is None:
        raise exc.CommandError(_("Missing 'type' key in spec file."))
    if type_version is None:
        raise exc.CommandError(_("Missing 'version' key in spec file."))
    if properties is None:
        raise exc.CommandError(_("Missing 'properties' key in spec file."))

    if type_name == 'os.heat.stack':
        stack_properties = utils.process_stack_spec(properties)
        spec['properties'] = stack_properties

    params = {
        'name': args.name,
        'spec': spec,
        'metadata': utils.format_parameters(args.metadata),
    }

    profile = service.create_profile(**params)
    _show_profile(service, profile.id)
コード例 #6
0
def _populate_profile_params(name, spec, metadata, id=None):

    if spec is None:
        spec_dict = None
    else:
        try:
            spec_dict = yaml.safe_load(spec)
        except Exception as ex:
            raise ValidationError(_('The specified file is not a valid '
                                    'YAML file: %s') % ex)
        type_name = spec_dict['type']
        if type_name == 'os.heat.stack':
            spec_dict['properties'] = utils.process_stack_spec(
                spec['properties'])
    if not metadata:
        metadata_dict = {}
    else:
        try:
            metadata_dict = yaml.safe_load(metadata)
        except Exception as ex:
            raise ValidationError(_('The specified file is not a valid '
                                    'YAML file: %s') % ex)
    params = {"name": name,
              "spec": spec_dict,
              "metadata": metadata_dict}

    return params
コード例 #7
0
ファイル: forms.py プロジェクト: openstack/senlin-dashboard
def _populate_profile_params(name, spec, metadata, id=None):

    if spec is None:
        spec_dict = None
    else:
        try:
            spec_dict = yaml.load(spec)
        except Exception as ex:
            raise ValidationError(_('The specified file is not a valid '
                                    'YAML file: %s') % six.text_type(ex))
        type_name = spec_dict['type']
        if type_name == 'os.heat.stack':
            spec_dict['properties'] = utils.process_stack_spec(
                spec['properties'])
    if not metadata:
        metadata_dict = {}
    else:
        try:
            metadata_dict = yaml.load(metadata)
        except Exception as ex:
            raise ValidationError(_('The specified file is not a valid '
                                    'YAML file: %s') % six.text_type(ex))
    params = {"name": name,
              "spec": spec_dict,
              "metadata": metadata_dict}

    if id is not None:
        params["id"] = id

    return params
コード例 #8
0
ファイル: profile.py プロジェクト: numvc/LuxoftBot
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        senlin_client = self.app.client_manager.clustering

        spec = senlin_utils.get_spec_content(parsed_args.spec_file)
        type_name = spec.get('type', None)
        type_version = spec.get('version', None)
        properties = spec.get('properties', None)
        if type_name is None:
            raise exc.CommandError(_("Missing 'type' key in spec file."))
        if type_version is None:
            raise exc.CommandError(_("Missing 'version' key in spec file."))
        if properties is None:
            raise exc.CommandError(_("Missing 'properties' key in spec file."))

        if type_name == 'os.heat.stack':
            stack_properties = senlin_utils.process_stack_spec(properties)
            spec['properties'] = stack_properties

        params = {
            'spec': spec,
        }

        profile = senlin_client.validate_profile(**params)

        formatters = {}
        formatters['metadata'] = senlin_utils.json_formatter
        formatters['spec'] = senlin_utils.nested_dict_formatter(
            ['type', 'version', 'properties'], ['property', 'value'])

        columns = [
            'created_at', 'domain', 'id', 'metadata', 'name', 'project_id',
            'spec', 'type', 'updated_at', 'user_id'
        ]
        return columns, utils.get_dict_properties(profile.to_dict(),
                                                  columns,
                                                  formatters=formatters)