예제 #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
    def create_tap_flow(self, context, tap_flow):
        LOG.debug("create_tap_flow() called")

        tenant_id = self._get_tenant_id_for_create(context,
                                                   tap_flow['tap_flow'])

        t_f = tap_flow['tap_flow']

        # 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']

        taas_id = (self.get_tap_id_association(
            context, tap_service_id=ts['id'])['taas_id'] +
                   cfg.CONF.taas.vlan_range_start)

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

        # Extract the host where the source port is located
        port = self._get_port_details(context, t_f['source_port'])
        host = port['binding:host_id']
        port_mac = port['mac_address']

        # create tap flow in the db model
        tf = super(TaasPlugin, self).create_tap_flow(context, tap_flow)

        # Send RPC message to both the source port host and
        # tap service(destination) port host
        rpc_msg = {
            'tap_flow': tf,
            'port_mac': port_mac,
            'taas_id': taas_id,
            'port': port
        }

        self.agent_rpc.create_tap_flow(context, rpc_msg, host)

        return tf
예제 #3
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