示例#1
0
    def delete_tap_service(self, context, id):
        LOG.debug("delete_tap_service() called")

        # Get all the tap Flows that are associated with the Tap service
        # and delete them as well
        t_f_collection = self.get_tap_flows(context,
                                            filters={'tap_service_id': [id]},
                                            fields=['id'])

        for t_f in t_f_collection:
            self.delete_tap_flow(context, t_f['id'])

        with context.session.begin(subtransactions=True):
            ts = self.get_tap_service(context, id)
            driver_context = sd_context.TapServiceContext(self, context, ts)
            super(TaasPlugin, self).delete_tap_service(context, id)
            self.driver.delete_tap_service_precommit(driver_context)

        try:
            self.driver.delete_tap_service_postcommit(driver_context)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    "Failed to delete tap service on driver. "
                    "tap_sevice: %s", id)
示例#2
0
    def create_tap_service(self, context, tap_service):
        LOG.debug("create_tap_service() called")

        t_s = tap_service['tap_service']
        tenant_id = t_s['tenant_id']
        port_id = t_s['port_id']
        erspan_dst_ip = t_s['erspan_dst_ip']

        LOG.error("port_id:%s" % port_id)
        LOG.error("#####t_s=%s" % t_s)
        if port_id is '' and erspan_dst_ip is '':
            LOG.error("Either port_id or erspan_dst_ip needs to be specified!")
            raise taas_ex.TapServiceInvalidParameters()

        if port_id is not '':
            # Get port details
            port = self._get_port_details(context, port_id)

            # Check if the port is owned by the tenant.
            if port['tenant_id'] != tenant_id:
                raise taas_ex.PortDoesNotBelongToTenant()

            # Extract the host where the port is located
            host = port['binding:host_id']

            if host is not None:
                LOG.debug("Host on which the port is created = %s" % host)
            else:
                LOG.debug("Host could not be found, Port Binding disbaled!")

        # Create tap service in the db model
        with context.session.begin(subtransactions=True):
            ts = super(TaasPlugin,
                       self).create_tap_service(context, tap_service)
            driver_context = sd_context.TapServiceContext(self, context, ts)
            self.driver.create_tap_service_precommit(driver_context)

        try:
            self.driver.create_tap_service_postcommit(driver_context)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    "Failed to create tap service on driver,"
                    "deleting tap_service %s", ts['id'])
                super(TaasPlugin, self).delete_tap_service(context, ts['id'])

        return ts
示例#3
0
    def sync_tap_resources(self, context, sync_tap_res, host):
        """Handle Rpc from Agent to sync up Tap resources."""
        LOG.debug("In RPC Call for Sync Tap Resources: MSG=%s" % sync_tap_res)

        # Get list of configured tap-services
        active_tss = self.plugin.get_tap_services(
            context,
            filters={'status': [constants.ACTIVE]})

        for ts in active_tss:
            # If tap-service port is bound to a different host than the one
            # which sent this RPC, then continue.
            ts_port = self.plugin._get_port_details(
                context, ts['port_id'])
            if ts_port['binding:host_id'] != host:
                continue

            driver_context = sd_context.TapServiceContext(self.plugin,
                                                          context, ts)
            try:
                self.rpc_driver.create_tap_service_postcommit(driver_context)
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error("Failed to create tap service on driver,"
                              "deleting tap_service %s", ts['id'])
                    super(TaasPlugin, self.plugin).delete_tap_service(
                        context, ts['id'])

            # Get all the active tap flows for current tap-service
            active_tfs = self.plugin.get_tap_flows(
                context,
                filters={'tap_service_id': [ts['id']],
                         'status': [constants.ACTIVE]})

            # Filter out the tap flows associated with distinct tap services
            for tf in active_tfs:
                driver_context = sd_context.TapFlowContext(self.plugin,
                                                           context, tf)
                try:
                    self.rpc_driver.create_tap_flow_postcommit(driver_context)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        LOG.error("Failed to create tap flow on driver,"
                                  "deleting tap_flow %s", tf['id'])
                        super(TaasPlugin, self.plugin).delete_tap_flow(
                            context, tf['id'])
示例#4
0
    def handle_update_port(self, resource, event, trigger, **kwargs):
        updated_port = kwargs['port']
        if not updated_port['device_owner'].startswith(
                nl_constants.DEVICE_OWNER_COMPUTE_PREFIX):
            return

        if (kwargs.get('original_port')[pb_def.VIF_TYPE] !=
                pb_def.VIF_TYPE_UNBOUND):
            # Checking newly vm port binding allows us to avoid call to DB
            # when a port update_event like restart, setting name, etc...
            # Moreover, that will help us in case of tenant admin wants to
            # only attach security group to vm port.
            return

        context = kwargs['context']
        port_id = updated_port['id']

        LOG.debug("create_tap_service() called")

        t_s = tap_service['tap_service']
        tenant_id = t_s['tenant_id']
        port_id = t_s['port_id']

        # Get port details
        port = self._get_port_details(context, port_id)

        # Check if the port is owned by the tenant.
        if port['tenant_id'] != tenant_id:
            raise taas_ex.PortDoesNotBelongToTenant()

        # Extract the host where the port is located
        host = port['binding:host_id']

        if host is not None:
            LOG.debug("Host on which the port is created = %s" % host)
        else:
            LOG.debug("Host could not be found, Port Binding disbaled!")

        t_f = tap_flow['tap_flow']
        tenant_id = t_f['tenant_id']

        # Check if the tenant id of the source port is the same as the
        # tenant_id of the tap service we are attaching it to.

        ts = self.get_tap_service(context, t_f['tap_service_id'])
        ts_tenant_id = ts['tenant_id']

        if tenant_id != ts_tenant_id:
            raise taas_ex.TapServiceNotBelongToTenant()

        # Create tap service in the db model
        with context.session.begin(subtransactions=True):
            ts = super(TaasPlugin, self).create_tap_service(context, tap_service)
            driver_context = sd_context.TapServiceContext(self, context, ts)
            self.driver.create_tap_service_precommit(driver_context)

        try:
            self.driver.create_tap_service_postcommit(driver_context)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error("Failed to create tap service on driver,"
                          "deleting tap_service %s", ts['id'])
                super(TaasPlugin, self).delete_tap_service(context, ts['id'])

        return ts