Exemple #1
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
    def create_tap_service(self, context, tap_service):
        LOG.debug("create_tap_service() called")

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

        t_s = tap_service['tap_service']
        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!")

        # Create tap service in the db model
        ts = super(TaasPlugin, self).create_tap_service(context, tap_service)
        # Get taas id associated with the Tap Service
        tap_id_association = self.get_tap_id_association(
            context, tap_service_id=ts['id'])

        taas_vlan_id = (tap_id_association['taas_id'] +
                        cfg.CONF.taas.vlan_range_start)

        if taas_vlan_id > cfg.CONF.taas.vlan_range_end:
            raise taas_ex.TapServiceLimitReached()

        rpc_msg = {'tap_service': ts, 'taas_id': taas_vlan_id, 'port': port}

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

        return ts
    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