def _get_gateway_vport(self, context, tenant_id, netpart_id,
                           nuage_vlan_id):
        ret = {
            'interface': None,
            'vport_id': None,
            'vport_type': None,
            'vport_name': None,
            'port_id': None
        }

        # Get the gw interface
        try:
            nuage_vlan = gw_helper.get_gateway_port_vlan(
                self.restproxy, nuage_vlan_id)
        except Exception as e:
            if e.code == constants.RES_NOT_FOUND:
                return
            raise

        # Check for tenant permission
        # tenant_id is None in case of admin. We don't check permissions
        # for admin.netpart_id will be None when called from
        # delete_gateway_vport. We don't have to check permissions for
        # delete as client always calls get() before delete and we check
        # permissions during get()
        if tenant_id and netpart_id:
            ent_perm = gw_helper.get_ent_permission_on_vlan(
                self.restproxy, nuage_vlan['ID'])
            has_perm = self._check_tenant_perm(nuage_vlan_id, tenant_id,
                                               ent_perm['permittedEntityID'])
            if not has_perm:
                msg = _("Tenant %(ten)s does not have permission for vlan %("
                        "vlan)s" % {
                            'ten': tenant_id,  # noqa H702
                            'vlan': nuage_vlan_id
                        })
                LOG.warn(msg)
                raise restproxy.ResourceConflictException(msg)

        ret['gateway'] = nuage_vlan['gatewayID']
        ret['gatewayport'] = nuage_vlan['parentID']
        ret['value'] = nuage_vlan['value']

        # Check if it is associated with a vport
        nuage_vport_id = nuage_vlan['vportID']
        if not nuage_vport_id:
            msg = _("Nuage gateway interface %s is not associated with any "
                    "vport" % nuage_vlan_id)  # noqa H702
            raise restproxy.ResourceConflictException(msg)

        # Get the vport
        nuage_vport = gw_helper.get_nuage_vport(self.restproxy, nuage_vport_id)
        if nuage_vport:
            ret['nuage_subnet_id'] = nuage_vport['parentID']
            nuage_vport_type = nuage_vport['type']
            if nuage_vport_type == constants.BRIDGE_VPORT_TYPE:
                # Get the bridge interface on the vport
                nuage_br_intf = gw_helper.get_interface_by_vport(
                    self.restproxy, nuage_vport_id, nuage_vport_type)
                if nuage_br_intf:
                    ret['interface'] = nuage_br_intf['ID']

            elif nuage_vport_type == constants.HOST_VPORT_TYPE:
                # Get the host interface on the vport
                nuage_host_intf = gw_helper.get_interface_by_vport(
                    self.restproxy, nuage_vport_id, nuage_vport_type)
                if nuage_host_intf:
                    ret['interface'] = nuage_host_intf['ID']
                    ret['port_id'] = strip_cms_id(
                        nuage_host_intf['externalID'])
            else:
                msg = _("Nuage vport associated with gateway interface %s is"
                        " not connected to a bridge/host interface" %
                        nuage_vlan_id)  # noqa H702
                raise restproxy.ResourceConflictException(msg)

            ret['vport_id'] = nuage_vport_id
            ret['vport_type'] = nuage_vport_type
            ret['vport_name'] = nuage_vport['name']

        return ret
Example #2
0
def get_subnet_external_id(subnet):
    if not subnet:
        raise restproxy.ResourceConflictException(
            "Unable to calculate external ID for subnet.")
    neutron_id = subnet['nuage_l2bridge'] or subnet['network_id']
    return get_vsd_external_id(neutron_id)