def delete_gateway_port_vlan(self, vlan_id):
     req_params = {
         'vlan_id': vlan_id
     }
     nuage_gw_vlan = nuagelib.NuageVlan(create_params=req_params)
     self.restproxy.delete(
         nuage_gw_vlan.get_resource() + '?responseChoice=1')
 def delete_gateway_port_vlan(self, vlan_id):
     req_params = {'vlan_id': vlan_id}
     nuage_gw_vlan = nuagelib.NuageVlan(create_params=req_params)
     response = self.restproxy.rest_call(
         'DELETE',
         nuage_gw_vlan.get_resource() + '?responseChoice=1', '')
     if not nuage_gw_vlan.validate(response):
         raise restproxy.RESTProxyError(nuage_gw_vlan.error_msg)
def process_provider_network(restproxy_serv, pg_obj, params):
    pnet_binding = params.get('pnet_binding')
    np_id = params['netpart_id']

    gw_port = pnet_binding['physical_network']
    req_params = {
        'port_id': gw_port,
        'np_id': params['netpart_id']
    }

    nuage_gw_port = nuagelib.NuageGatewayPort(create_params=req_params)
    response = restproxy_serv.rest_call('GET', nuage_gw_port.get_resource(),
                                        '')
    if not nuage_gw_port.validate(response):
        raise restproxy.RESTProxyError(nuage_gw_port.error_msg)
    nuage_gw_id = nuage_gw_port.get_gw(response)

    gw_params = {
        'gw_id': nuage_gw_id,
        'np_id': params['netpart_id']
    }

    gw_port_ent_perm = False
    gw_ent_perm = check_gw_enterprise_permissions(restproxy_serv, gw_params)
    if not gw_ent_perm:
        gw_port_ent_perm = check_gw_port_enterprise_permissions(
            restproxy_serv, req_params)
    # create vlan on gw port
    vlan_id = pnet_binding['vlan_id']
    response = restproxy_serv.rest_call('POST', nuage_gw_port.post_vlan(),
                                        nuage_gw_port.post_vlan_data(vlan_id))
    if not nuage_gw_port.validate(response):
        raise restproxy.RESTProxyError(nuage_gw_port.error_msg)
    nuage_vlan_id = nuage_gw_port.get_response_id(response)
    params['nuage_vlan_id'] = nuage_vlan_id

    # if the enterprise permission is not set for gateway
    # and gateway port,  set enterprise permission for vlan
    # for the current net partition
    if not gw_ent_perm and not gw_port_ent_perm:
        # Add permissions to extend the vlan on gateway port for this np
        req_params = {
            'vlan_id': nuage_vlan_id,
            'np_id': params['netpart_id']
        }
        nuage_vlan = nuagelib.NuageVlan(create_params=req_params)
        response = restproxy_serv.rest_call('POST',
                                            nuage_vlan.get_ent_perm(),
                                            nuage_vlan.ent_perm_update(np_id))
        if not nuage_vlan.validate(response):
            raise restproxy.RESTProxyError(nuage_vlan.error_msg)

    # Get gateway personality, as for gateway of type VSG, policygroup of
    # type hardware to be used
    gw_type = get_gw_personality(restproxy_serv, gw_params)

    params['gw_type'] = gw_type
    create_bridge_vport_iface_for_pnet(restproxy_serv, pg_obj, params)
def get_gateway_port_vlan(restproxy_serv, nuage_vlan_id):
    req_params = {
        'vlan_id': nuage_vlan_id
    }
    nuage_gw_vlan = nuagelib.NuageVlan(create_params=req_params)
    response = restproxy_serv.rest_call('GET',
                                        nuage_gw_vlan.get_resource(), '')
    if not nuage_gw_vlan.validate(response):
        error_code = nuage_gw_vlan.get_error_code(response)
        raise restproxy.RESTProxyError(nuage_gw_vlan.error_msg, error_code)

    return nuage_gw_vlan.get_response_obj(response)
    def _check_parent_permissions(self, tenant_id, vlan_id, netpart_id):
        req_params = {'vlan_id': vlan_id}

        nuage_vlan = nuagelib.NuageVlan(create_params=req_params)
        response = self.restproxy.rest_call('GET', nuage_vlan.get_resource(),
                                            '')
        if not nuage_vlan.get_validate(response):
            raise restproxy.RESTProxyError(nuage_vlan.error_msg)

        # Get ent permissions on port
        gw_port_id = nuage_vlan.get_response_parentid(response)
        gw_port = gw_helper.get_gateway_port(self.restproxy, gw_port_id)
        gw = gw_helper.get_gateway(self.restproxy, gw_port['parentID'])
        req_params['port_id'] = gw_port_id
        nuage_ent_perm = nuagelib.NuageEntPermission(create_params=req_params)
        response = self.restproxy.rest_call(
            'GET', nuage_ent_perm.get_resource_by_port(gw['redundant']), '')
        if not nuage_ent_perm.validate(response):
            raise restproxy.RESTProxyError(nuage_ent_perm.error_msg)

        ent_perm = nuage_ent_perm.get_response_obj(response)
        if ent_perm:
            ent_id = nuage_ent_perm.get_permitted_entity_id(response)
            if ent_id != netpart_id:
                ent_type = nuage_ent_perm.get_permitted_entity_type(response)
                LOG.debug(
                    "Port %(port)s already assigned to %(ent)s with id"
                    " %(ent_id)s", {
                        'port': vlan_id,
                        'ent': ent_type,
                        'ent_id': ent_id
                    })
                return False
            else:
                LOG.debug("Port %(port)s is assigned to enterprise %(ent)s", {
                    'port': gw_port_id,
                    'ent': ent_id
                })
                return True

        # Get ent permissions on gateway
        gw_port = gw_helper.get_gateway_port(self.restproxy, gw_port_id)
        if not gw_port:
            msg = (_("Port %s not found on gateway ", gw_port_id))  # noqa H702
            raise restproxy.RESTProxyError(msg)

        gw_id = gw_port['parentID']
        req_params['gw_id'] = gw_id
        nuage_ent_perm = nuagelib.NuageEntPermission(create_params=req_params)
        response = self.restproxy.rest_call(
            'GET', nuage_ent_perm.get_resource_by_gw(), '')
        if not nuage_ent_perm.validate(response):
            raise restproxy.RESTProxyError(nuage_ent_perm.error_msg)

        ent_perm = nuage_ent_perm.get_response_obj(response)
        if ent_perm:
            ent_id = nuage_ent_perm.get_permitted_entity_id(response)
            if ent_id != netpart_id:
                ent_type = nuage_ent_perm.get_permitted_entity_type(response)
                LOG.debug(
                    "Gateway %(gw)s already assigned to %(ent)s with "
                    "id %(ent_id)s", {
                        'gw': gw_id,
                        'ent': ent_type,
                        'ent_id': ent_id
                    })
                return False
            else:
                LOG.debug("Gateway %(gw)s is assigned to enterprise %(ent)s", {
                    'gw': gw_id,
                    'ent': ent_id
                })
                return True
    def _check_parent_permissions(self, tenant_id, vlan_id, netpart_id):
        req_params = {'vlan_id': vlan_id}

        nuage_vlan = nuagelib.NuageVlan(create_params=req_params)
        vlans = self.restproxy.get(nuage_vlan.get_resource(), required=True)
        # Get ent permissions on port
        gw_port_id = vlans[0]['parentID']
        gw_port = gw_helper.get_gateway_port(self.restproxy, gw_port_id)
        gw = gw_helper.get_gateway(self.restproxy, gw_port['parentID'])
        req_params['port_id'] = gw_port_id
        nuage_ent_perm = nuagelib.NuageEntPermission(create_params=req_params)
        permissions = self.restproxy.get(nuage_ent_perm.get_resource_by_port(
            gw['redundant']),
                                         required=True)
        ent_perm = permissions[0] if permissions else None
        if ent_perm:
            ent_id = ent_perm['permittedEntityID']
            if ent_id != netpart_id:
                ent_type = ent_perm['permittedEntityType']
                LOG.debug(
                    "Port %(port)s already assigned to %(ent)s with id"
                    " %(ent_id)s", {
                        'port': vlan_id,
                        'ent': ent_type,
                        'ent_id': ent_id
                    })
                return False
            else:
                LOG.debug("Port %(port)s is assigned to enterprise %(ent)s", {
                    'port': gw_port_id,
                    'ent': ent_id
                })
                return True

        # Get ent permissions on gateway
        gw_port = gw_helper.get_gateway_port(self.restproxy, gw_port_id,
                                             gw_port['parentID'])
        if not gw_port:
            msg = (_("Port %s not found on gateway ", gw_port_id))  # noqa H702
            raise restproxy.ResourceNotFoundException(msg)

        gw_id = gw_port['parentID']
        req_params['gw_id'] = gw_id
        nuage_ent_perm = nuagelib.NuageEntPermission(create_params=req_params)
        permissions = self.restproxy.get(nuage_ent_perm.get_resource_by_gw(),
                                         required=True)
        ent_perm = permissions[0] if permissions else None
        if ent_perm:
            ent_id = ent_perm['permittedEntityID']
            if ent_id != netpart_id:
                ent_type = ent_perm['permittedEntityType']
                LOG.debug(
                    "Gateway %(gw)s already assigned to %(ent)s with "
                    "id %(ent_id)s", {
                        'gw': gw_id,
                        'ent': ent_type,
                        'ent_id': ent_id
                    })
                return False
            else:
                LOG.debug("Gateway %(gw)s is assigned to enterprise %(ent)s", {
                    'gw': gw_id,
                    'ent': ent_id
                })
                return True
        return False
Exemple #7
0
def get_gateway_port_vlan(restproxy_serv, nuage_vlan_id):
    req_params = {'vlan_id': nuage_vlan_id}
    nuage_gw_vlan = nuagelib.NuageVlan(create_params=req_params)
    return restproxy_serv.get(nuage_gw_vlan.get_resource(), required=True)[0]