Ejemplo n.º 1
0
    def poll_event(self, event, spacing=2, max_times=sys.maxint):
        """To poll for an event.

            As a base class, it only does the polling
            descriptor preparation.
            NfpController class implements the required functionality.
        """
        ev_spacing = self._event_handlers.get_poll_spacing(event.id)
        assert spacing or ev_spacing, "No spacing specified for polling"
        if ev_spacing:
            spacing = ev_spacing
        logging_context = nfp_logging.get_logging_context()
        module = logging_context['namespace']
        handler = (
            self._event_handlers.get_poll_handler(event.id, module=module))
        assert handler, "No poll handler found for event %s" % (event.id)

        refuuid = event.desc.uuid
        event = self._make_new_event(event)
        event.lifetime = 0
        event.desc.type = nfp_event.POLL_EVENT
        event.desc.target = module

        kwargs = {'spacing': spacing,
                  'max_times': max_times,
                  'ref': refuuid}
        poll_desc = nfp_event.PollDesc(**kwargs)

        setattr(event.desc, 'poll_desc', poll_desc)
        return event
Ejemplo n.º 2
0
    def _data_wrapper(self, context, tenant_id, nf, **kwargs):
        nfp_context = {}
        str_description = nf['description'].split('\n')[1]
        description = self._get_dict_desc_from_string(str_description)
        resource = kwargs['rsrc_type']
        resource_data = kwargs['resource']
        resource_data['description'] = str_description
        if resource.lower() == 'ipsec_site_connection':
            nfp_context = {
                'network_function_id': nf['id'],
                'ipsec_site_connection_id': kwargs['rsrc_id']
            }

        ctx_dict, rsrc_ctx_dict = self.\
            _prepare_resource_context_dicts(context, tenant_id,
                                            resource, resource_data)
        nfp_context.update({
            'neutron_context': ctx_dict,
            'requester': 'nas_service',
            'logging_context': nfp_logging.get_logging_context()
        })
        resource_type = 'vpn'
        kwargs.update({'neutron_context': rsrc_ctx_dict})
        body = common.prepare_request_data(nfp_context, resource,
                                           resource_type, kwargs,
                                           description['service_vendor'])
        return body
Ejemplo n.º 3
0
    def _data_wrapper(self, context, firewall, host, nf, reason):
        # Hardcoding the position for fetching data since we are owning
        # its positional change
        description = ast.literal_eval((nf['description'].split('\n'))[1])
        fw_mac = description['provider_ptg_info'][0]
        firewall.update({'description': str(description)})
        kwargs = {
            'context': context,
            'firewall_policy_id': firewall['firewall_policy_id'],
            'description': str(description),
            'tenant_id': firewall['tenant_id']
        }

        ctx_dict, rsrc_ctx_dict = self._prepare_resource_context_dicts(
            **kwargs)
        nfp_context = {
            'network_function_id': nf['id'],
            'neutron_context': ctx_dict,
            'fw_mac': fw_mac,
            'requester': 'nas_service',
            'logging_context': nfp_logging.get_logging_context()
        }
        resource = resource_type = 'firewall'
        resource_data = {
            resource: firewall,
            'host': host,
            'neutron_context': rsrc_ctx_dict
        }
        body = common.prepare_request_data(nfp_context, resource,
                                           resource_type, resource_data,
                                           description['service_vendor'])
        return body
Ejemplo n.º 4
0
 def register_events(self, event_descs, priority=0):
     """Register event handlers with core. """
     logging_context = nfp_logging.get_logging_context()
     module = logging_context['namespace']
     # REVISIT (mak): change name to register_event_handlers() ?
     for event_desc in event_descs:
         self._event_handlers.register(
             event_desc.id, event_desc.handler,
             module, priority=priority)
Ejemplo n.º 5
0
    def _data_wrapper(self, context, tenant_id, name, reason, nf, **kwargs):
        nfp_context = {}
        description = ast.literal_eval((nf['description'].split('\n'))[1])
        if name.lower() == 'loadbalancer':
            lb_id = kwargs['loadbalancer']['id']
            kwargs['loadbalancer'].update({'description': str(description)})
            nfp_context = {
                'network_function_id': nf['id'],
                'loadbalancer_id': kwargs['loadbalancer']['id']
            }
        elif name.lower() == 'listener':
            lb_id = kwargs['listener'].get('loadbalancer_id')
            kwargs['listener']['description'] = str(description)
        elif name.lower() == 'pool':
            lb_id = kwargs['pool'].get('loadbalancer_id')
            kwargs['pool']['description'] = str(description)
        elif name.lower() == 'member':
            pool = kwargs['member'].get('pool')
            if pool:
                lb_id = pool.get('loadbalancer_id')
            kwargs['member']['description'] = str(description)
        elif name.lower() == 'healthmonitor':
            pool = kwargs['healthmonitor'].get('pool')
            if pool:
                lb_id = pool.get('loadbalancer_id')
            kwargs['healthmonitor']['description'] = str(description)
        else:
            kwargs[name.lower()].update({'description': str(description)})
            lb_id = kwargs[name.lower()].get('loadbalancer_id')

        args = {
            'tenant_id': tenant_id,
            'lb_id': lb_id,
            'context': context,
            'description': str(description)
        }

        ctx_dict, rsrc_ctx_dict = self._prepare_resource_context_dicts(**args)

        nfp_context.update({
            'neutron_context': ctx_dict,
            'requester': 'nas_service',
            'logging_context': nfp_logging.get_logging_context()
        })
        resource_type = 'loadbalancerv2'
        resource = name
        resource_data = {'neutron_context': rsrc_ctx_dict}
        resource_data.update(**kwargs)
        body = common.prepare_request_data(nfp_context, resource,
                                           resource_type, resource_data,
                                           description['service_vendor'])
        return body
Ejemplo n.º 6
0
 def create_event(self, **kwargs):
     """To create a new event. """
     event = None
     try:
         event = nfp_event.Event(**kwargs)
         # Get the logging context stored in thread
         logging_context = nfp_logging.get_logging_context()
         # Log metadata for event handling code
         event.context = logging_context
     except AssertionError as aerr:
         message = "%s" % (aerr)
         LOG.exception(message)
     return event
 def create_event(self, **kwargs):
     """To create a new event. """
     event = None
     try:
         event = nfp_event.Event(**kwargs)
         # Get the logging context stored in thread
         logging_context = nfp_logging.get_logging_context()
         # Log metadata for event handling code
         event.context = logging_context
     except AssertionError as aerr:
         message = "%s" % (aerr)
         LOG.exception(message)
     return event