Example #1
0
    def create_vnfd(self, context, vnfd):
        vnfd_data = vnfd['vnfd']
        template = vnfd_data['attributes'].get('vnfd')
        if isinstance(template, dict):
            # TODO(sripriya) remove this yaml dump once db supports storing
            # json format of yaml files in a separate column instead of
            # key value string pairs in vnf attributes table
            vnfd_data['attributes']['vnfd'] = yaml.safe_dump(
                template)
        elif isinstance(template, str):
            self._report_deprecated_yaml_str()
        if "tosca_definitions_version" not in template:
            raise exceptions.Invalid('Not a valid template: '
                                     'tosca_definitions_version is missing.')

        LOG.debug('vnfd %s', vnfd_data)

        service_types = vnfd_data.get('service_types')
        if not attributes.is_attr_set(service_types):
            LOG.debug('service type must be specified')
            raise vnfm.ServiceTypesNotSpecified()
        for service_type in service_types:
            # TODO(yamahata):
            # framework doesn't know what services are valid for now.
            # so doesn't check it here yet.
            pass
        if 'template_source' in vnfd_data:
            template_source = vnfd_data.get('template_source')
        else:
            template_source = 'onboarded'
        vnfd['vnfd']['template_source'] = template_source

        self._parse_template_input(vnfd)
        return super(VNFMPlugin, self).create_vnfd(
            context, vnfd)
Example #2
0
def get_metadata_for_reservation(template, metadata):
    """Method used to add lease_id in metadata

     So that it can be used further while creating query_metadata

    :param template: ToscaTemplate object
    :param metadata: metadata dict
    :return: dictionary contains lease_id
    """

    metadata.setdefault('reservation', {})
    input_param_list = template.parsed_params.keys()
    # if lease_id is passed in the parameter file,
    # get it from template parsed_params.
    if 'lease_id' in input_param_list:
        metadata['reservation']['lease_id'] = template.parsed_params[
            'lease_id']
    else:
        for policy in template.policies:
            if policy.entity_tpl['type'] == constants.POLICY_RESERVATION:
                metadata['reservation']['lease_id'] = policy.entity_tpl[
                    'reservation']['properties']['lease_id']
                break
    if not uuidutils.is_uuid_like(metadata['reservation']['lease_id']):
        raise exceptions.Invalid('Invalid UUID for lease_id')
    return metadata
Example #3
0
    def __init__(self,
                 plugin,
                 collection,
                 resource,
                 attr_info,
                 allow_bulk=False,
                 member_actions=None,
                 parent=None,
                 allow_pagination=False,
                 allow_sorting=False):
        member_actions = member_actions or []
        #受那个插件管理
        self._plugin = plugin
        self._collection = collection.replace('-', '_')
        #资源名称
        self._resource = resource.replace('-', '_')
        self._attr_info = attr_info
        self._allow_bulk = allow_bulk
        self._allow_pagination = allow_pagination
        self._allow_sorting = allow_sorting
        self._native_bulk = self._is_native_bulk_supported()
        self._native_pagination = self._is_native_pagination_supported()
        self._native_sorting = self._is_native_sorting_supported()
        self._policy_attrs = [
            name for (name, info) in self._attr_info.items()
            if info.get('required_by_policy')
        ]
        self._notifier = n_rpc.get_notifier('nfv')
        self._member_actions = member_actions
        self._primary_key = self._get_primary_key()
        if self._allow_pagination and self._native_pagination:
            # Native pagination need native sorting support
            if not self._native_sorting:
                raise exceptions.Invalid(
                    _("Native pagination depend on native sorting"))
            if not self._allow_sorting:
                LOG.info("Allow sorting is enabled because native "
                         "pagination requires native sorting")
                self._allow_sorting = True

        if parent:
            #如果存在父节点,则生成的action名称将包含父节点部分
            self._parent_id_name = '%s_id' % parent['member_name']
            parent_part = '_%s' % parent['member_name']
        else:
            self._parent_id_name = None
            parent_part = ''

        #生成list,show action对应的名称
        self._plugin_handlers = {
            self.LIST: 'get%s_%s' % (parent_part, self._collection),
            self.SHOW: 'get%s_%s' % (parent_part, self._resource)
        }
        #生成create,update,delete对应的action名称
        for action in [self.CREATE, self.UPDATE, self.DELETE]:
            self._plugin_handlers[action] = '%s%s_%s' % (action, parent_part,
                                                         self._resource)
Example #4
0
    def __init__(self,
                 plugin,
                 collection,
                 resource,
                 attr_info,
                 allow_bulk=False,
                 member_actions=None,
                 parent=None,
                 allow_pagination=False,
                 allow_sorting=False):
        if member_actions is None:
            member_actions = []
        self._plugin = plugin
        self._collection = collection.replace('-', '_')
        self._resource = resource.replace('-', '_')
        self._attr_info = attr_info
        self._allow_bulk = allow_bulk
        self._allow_pagination = allow_pagination
        self._allow_sorting = allow_sorting
        self._native_bulk = self._is_native_bulk_supported()
        self._native_pagination = self._is_native_pagination_supported()
        self._native_sorting = self._is_native_sorting_supported()
        self._policy_attrs = [
            name for (name, info) in self._attr_info.items()
            if info.get('required_by_policy')
        ]
        self._notifier = n_rpc.get_notifier('network')
        # if cfg.CONF.notify_nova_on_port_data_changes:
        #     from tacker.notifiers import nova
        #     self._nova_notifier = nova.Notifier()
        self._member_actions = member_actions
        self._primary_key = self._get_primary_key()
        if self._allow_pagination and self._native_pagination:
            # Native pagination need native sorting support
            if not self._native_sorting:
                raise exceptions.Invalid(
                    _("Native pagination depend on native sorting"))
            if not self._allow_sorting:
                LOG.info(
                    _("Allow sorting is enabled because native "
                      "pagination requires native sorting"))
                self._allow_sorting = True

        if parent:
            self._parent_id_name = '%s_id' % parent['member_name']
            parent_part = '_%s' % parent['member_name']
        else:
            self._parent_id_name = None
            parent_part = ''
        self._plugin_handlers = {
            self.LIST: 'get%s_%s' % (parent_part, self._collection),
            self.SHOW: 'get%s_%s' % (parent_part, self._resource)
        }
        for action in [self.CREATE, self.UPDATE, self.DELETE]:
            self._plugin_handlers[action] = '%s%s_%s' % (action, parent_part,
                                                         self._resource)
Example #5
0
def post_process_template(template):
    def _add_scheduler_hints_property(nt):
        hints = nt.get_property_value('scheduler_hints')
        if hints is None:
            hints = OrderedDict()
            hints_schema = {'type': 'map', 'required': False,
                            'entry_schema': {'type': 'string'}}
            hints_prop = properties.Property('scheduler_hints',
                                             hints,
                                             hints_schema)
            nt.get_properties_objects().append(hints_prop)
        return hints

    for nt in template.nodetemplates:
        if (nt.type_definition.is_derived_from(MONITORING) or
            nt.type_definition.is_derived_from(FAILURE) or
                nt.type_definition.is_derived_from(PLACEMENT)):
            template.nodetemplates.remove(nt)
            continue

        if nt.type in delpropmap.keys():
            for prop in delpropmap[nt.type]:
                for p in nt.get_properties_objects():
                    if prop == p.name:
                        nt.get_properties_objects().remove(p)

        # change the property value first before the property key
        if nt.type in convert_prop_values:
            for prop in convert_prop_values[nt.type].keys():
                for p in nt.get_properties_objects():
                    if (prop == p.name and
                            p.value in
                            convert_prop_values[nt.type][prop].keys()):
                        v = convert_prop_values[nt.type][prop][p.value]
                        p.value = v

        if nt.type in convert_prop:
            for prop in convert_prop[nt.type].keys():
                for p in nt.get_properties_objects():
                    if prop == p.name:
                        schema_dict = {'type': p.type}
                        v = nt.get_property_value(p.name)
                        newprop = properties.Property(
                            convert_prop[nt.type][prop], v, schema_dict)
                        nt.get_properties_objects().append(newprop)
                        nt.get_properties_objects().remove(p)

        if nt.type_definition.is_derived_from(TACKERVDU):
            reservation_metadata = nt.get_property_value(
                'reservation_metadata')
            if reservation_metadata is not None:
                hints = _add_scheduler_hints_property(nt)

                input_resource_type = reservation_metadata.get(
                    'resource_type')
                input_id = reservation_metadata.get('id')

                # Checking if 'resource_type' and 'id' is passed through a
                # input parameter file or not. If it's then get the value
                # from input parameter file.
                if (isinstance(input_resource_type, OrderedDict) and
                        input_resource_type.get('get_input')):
                    input_resource_type = template.parsed_params.get(
                        input_resource_type.get('get_input'))
                # TODO(niraj-singh): Remove this validation once bug
                # 1815755 is fixed.
                if input_resource_type not in (
                        'physical_host', 'virtual_instance'):
                    raise exceptions.Invalid(
                        'resoure_type must be physical_host'
                        ' or virtual_instance')

                if (isinstance(input_id, OrderedDict) and
                        input_id.get('get_input')):
                    input_id = template.parsed_params.get(
                        input_id.get('get_input'))

                if input_resource_type == 'physical_host':
                    hints['reservation'] = input_id
                elif input_resource_type == 'virtual_instance':
                    hints['group'] = input_id
                nt.get_properties_objects().remove(nt.get_properties().get(
                    'reservation_metadata'))
Example #6
0
    def update_vnf_with_reservation(self, plugin, context, vnf, policy_dict):

        alarm_url = dict()

        def create_alarm_action(action, action_list, scaling_type):
            params = dict()
            params['vnf_id'] = vnf['id']
            params['mon_policy_name'] = action
            driver = 'ceilometer'

            def _refactor_backend_policy(bk_policy_name, bk_action_name):
                policy = '%(policy_name)s%(action_name)s' % {
                    'policy_name': bk_policy_name,
                    'action_name': bk_action_name}
                return policy

            for index, policy_action_name in enumerate(action_list):
                filters = {'name': policy_action_name}
                bkend_policies = \
                    plugin.get_vnf_policies(context, vnf['id'], filters)
                if bkend_policies:
                    if constants.POLICY_SCALING in str(bkend_policies[0]):
                        action_list[index] = _refactor_backend_policy(
                            policy_action_name, scaling_type)

                # Support multiple action. Ex: respawn % notify
                action_name = '%'.join(action_list)
                params['mon_policy_action'] = action_name
                alarm_url[action] = \
                    self.call_alarm_url(driver, vnf, params)
                details = "Alarm URL set successfully: %s" % alarm_url
                vnfm_utils.log_events(t_context.get_admin_context(), vnf,
                                      constants.RES_EVT_MONITOR,
                                      details)

        before_end_action = policy_dict['reservation']['before_end_actions']
        end_action = policy_dict['reservation']['end_actions']
        start_action = policy_dict['reservation']['start_actions']

        scaling_policies = \
            plugin.get_vnf_policies(
                context, vnf['id'], filters={
                    'type': constants.POLICY_SCALING})

        if len(scaling_policies) == 0:
            raise exceptions.VnfPolicyNotFound(
                policy=constants.POLICY_SCALING, vnf_id=vnf['id'])

        for scaling_policy in scaling_policies:
            # validating start_action for scale-out policy action
            if scaling_policy['name'] not in start_action:
                raise exceptions.Invalid(
                    'Not a valid template: start_action must contain'
                    ' %s as scaling-out action' % scaling_policy['name'])

            # validating before_end and end_actions for scale-in policy action
            if scaling_policy['name'] not in before_end_action:
                if scaling_policy['name'] not in end_action:
                    raise exceptions.Invalid(
                        'Not a valid template:'
                        ' before_end_action or end_action'
                        ' should contain scaling policy: %s'
                        % scaling_policy['name'])

        for action in constants.RESERVATION_POLICY_ACTIONS:
            scaling_type = "-out" if action == 'start_actions' else "-in"
            create_alarm_action(action, policy_dict[
                'reservation'][action], scaling_type)

        return alarm_url