Ejemplo n.º 1
0
    def create_tap_flow(self, context, tap_flow):
        LOG.debug("create_tap_flow() called")

        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 flow in the db model
        with context.session.begin(subtransactions=True):
            tf = super(TaasPlugin, self).create_tap_flow(context, tap_flow)
            driver_context = sd_context.TapFlowContext(self, context, tf)
            self.driver.create_tap_flow_precommit(driver_context)

        try:
            self.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).delete_tap_flow(context, tf['id'])

        return tf
Ejemplo n.º 2
0
    def delete_tap_flow(self, context, id):
        LOG.debug("delete_tap_flow() called")

        with context.session.begin(subtransactions=True):
            tf = self.get_tap_flow(context, id)
            driver_context = sd_context.TapFlowContext(self, context, tf)
            super(TaasPlugin, self).delete_tap_flow(context, id)
            self.driver.delete_tap_flow_precommit(driver_context)

        try:
            self.driver.delete_tap_flow_postcommit(driver_context)
        except Exception:
            with excutils.save_and_reraise_exception():
                with excutils.save_and_reraise_exception():
                    LOG.error("Failed to delete tap flow on driver. "
                              "tap_flow: %s", id)
Ejemplo n.º 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'])