def get_gateway_ports(self, tenant_id, filters):
        if 'gateway' in filters:
            req_params = {'gw_id': filters['gateway'][0]}
            if 'name' in filters:
                extra_params = {'gw_port_name': filters['name'][0]}
                return self._get_gateway_ports(req_params, extra_params)
            elif 'physicalName' in filters:
                extra_params = {'physical_name': filters['physicalName'][0]}
                return self._get_gateway_ports(req_params, extra_params)
            elif 'id' in filters:
                port = gw_helper.get_gateway_port(self.restproxy,
                                                  filters['id'][0],
                                                  gw_id=filters['gateway'][0])
                return [port] if port else []
            elif 'gatewayport' in filters:
                # We don't need the gateway that is being passed in
                port = gw_helper.get_gateway_port(self.restproxy,
                                                  filters['gatewayport'][0],
                                                  gw_id=filters['gateway'][0])
                return [port] if port else []
            else:
                req_params = {'gw_id': filters['gateway'][0]}
                return self._get_gateway_ports(req_params)

        elif 'id' in filters:
            port = gw_helper.get_gateway_port(self.restproxy, filters['id'][0])
            return [port] if port else []

        else:
            gws = self.get_gateways(tenant_id, filters)
            ports = []
            for gw in gws:
                req_params = {'gw_id': gw['ID']}
                ports.extend(self._get_gateway_ports(req_params))
            return ports
    def create_gateway_port_vlan(self, vlan_dict):
        gw_id = vlan_dict.get('gateway')
        gw_port_id = vlan_dict['gatewayport']
        vlan_value = vlan_dict['value']

        # Confirm that the gatewayport belongs to the gateway
        gw_port = gw_helper.get_gateway_port(self.restproxy, gw_port_id, gw_id)
        if not gw_port:
            msg = (_("Port %(port)s not found on gateway %(gw)s") % {
                'port': gw_port_id,
                'gw': gw_id
            })
            raise restproxy.RESTProxyError(msg)

        if not gw_id:
            gw_id = gw_port['parentID']
        gw = gw_helper.get_gateway(self.restproxy, gw_id)

        req_params = {'port_id': gw_port_id, 'personality': gw['personality']}

        nuage_gw_vlan = nuagelib.NuageVlanBase.factory(
            create_params=req_params,
            extra_params=None,
            redundant=gw['redundant'])
        response = self.restproxy.rest_call(
            'POST', nuage_gw_vlan.post_vlan(),
            nuage_gw_vlan.post_vlan_data(vlan_value))
        if not nuage_gw_vlan.validate(response):
            raise restproxy.RESTProxyError(nuage_gw_vlan.error_msg)

        return nuage_gw_vlan.get_response_objlist(response)
    def _get_gateway_port_vlans(self,
                                tenant_id,
                                req_params,
                                extra_params=None):
        if not req_params.get('personality'):
            gw_port = gw_helper.get_gateway_port(self.restproxy,
                                                 req_params['port_id'])
            gw = gw_helper.get_gateway(self.restproxy, gw_port['parentID'])
            req_params['personality'] = gw['personality']
            redundant = 'redundantGatewayStatus' in gw
        else:
            redundant = req_params['redundant']
        nuage_gw_vlan = nuagelib.NuageVlanBase.factory(
            create_params=req_params,
            extra_params=extra_params,
            redundant=redundant)

        resource_url = nuage_gw_vlan.get_resource_by_port()

        extra_headers = dict()
        if extra_params and 'vlan_value' in extra_params:
            vlan_val = extra_params['vlan_value']
            if not helper.is_vlan_valid(vlan_val):
                return []
            extra_headers = nuage_gw_vlan.extra_headers_by_value()

        response = self.restproxy.rest_call('GET',
                                            resource_url,
                                            '',
                                            extra_headers=extra_headers)
        if not nuage_gw_vlan.validate(response):
            raise restproxy.RESTProxyError(nuage_gw_vlan.error_msg)

        return nuage_gw_vlan.get_response_objlist(response)
    def create_gateway_port_vlan(self, vlan_dict):
        gw_id = vlan_dict.get('gateway')
        gw_port_id = vlan_dict['gatewayport']
        vlan_value = vlan_dict['value']

        # Confirm that the gatewayport belongs to the gateway
        gw_port = gw_helper.get_gateway_port(self.restproxy, gw_port_id, gw_id)
        if not gw_port:
            if gw_id:
                msg = (_("Port %(port)s not found on gateway %(gw)s") % {
                    'port': gw_port_id,
                    'gw': gw_id
                })
            else:
                msg = (_("Port %(port)s not found") % {'port': gw_port_id})
            raise restproxy.ResourceNotFoundException(msg)

        if not gw_id:
            gw_id = gw_port['parentID']
        gw = gw_helper.get_gateway(self.restproxy, gw_id)

        req_params = {'port_id': gw_port_id, 'personality': gw['personality']}

        nuage_gw_vlan = nuagelib.NuageVlanBase.factory(
            create_params=req_params,
            extra_params=None,
            redundant=gw['redundant'])
        return self.restproxy.post(nuage_gw_vlan.post_vlan(),
                                   nuage_gw_vlan.post_vlan_data(vlan_value))
    def _get_gateway_port_vlans(self,
                                tenant_id,
                                req_params,
                                extra_params=None):
        if not req_params.get('personality'):
            gw_port = gw_helper.get_gateway_port(self.restproxy,
                                                 req_params['port_id'])
            gw = gw_helper.get_gateway(self.restproxy, gw_port['parentID'])
            req_params['personality'] = gw['personality']
            redundant = 'redundantGatewayStatus' in gw
        else:
            redundant = req_params['redundant']
        nuage_gw_vlan = nuagelib.NuageVlanBase.factory(
            create_params=req_params,
            extra_params=extra_params,
            redundant=redundant)

        resource_url = nuage_gw_vlan.get_resource_by_port()

        extra_headers = dict()
        if extra_params and 'vlan_value' in extra_params:
            vlan_val = extra_params['vlan_value']
            if not helper.is_vlan_valid(vlan_val):
                return []
            extra_headers = nuage_gw_vlan.extra_headers_by_value()
        gw_vlans = self.restproxy.get(resource_url,
                                      extra_headers=extra_headers,
                                      required=True)
        return gw_vlans if gw_vlans else []
    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
示例#8
0
 def get_gateway_port(self, tenant_id, gw_port_id):
     resp = gw_helper.get_gateway_port(self.restproxy, gw_port_id)
     if resp:
         return gw_helper.make_gw_port_dict(resp)
     else:
         return []