def update_router(self, nuage_domain_id, router, params):
        nuage_pat = self._nuage_pat_enabled_or_disabled(router, params)
        tunnel_types = constants.VSD_TUNNEL_TYPES
        update_dict = {
            'name':
            router['id'],
            'description':
            router['name'],
            'PATEnabled':
            nuage_pat,
            'underlayEnabled':
            nuage_pat,
            'routeDistinguisher':
            router.get('rd'),
            'routeTarget':
            router.get('rt'),
            'tunnelType':
            tunnel_types.get(router.get('tunnel_type'),
                             router.get('tunnel_type')),
            'ECMPCount':
            router.get('ecmp_count'),
            'backHaulVNID':
            router.get('nuage_backhaul_vnid'),
            'backHaulRouteDistinguisher':
            router.get('nuage_backhaul_rd'),
            'backHaulRouteTarget':
            router.get('nuage_backhaul_rt')
        }

        nuagel3domain = nuagelib.NuageL3Domain()
        self.restproxy.put(nuagel3domain.delete_resource(nuage_domain_id),
                           update_dict)
Exemple #2
0
def get_l3domain_np_id(restproxy_serv, l3dom_id):
    req_params = {
        'domain_id': l3dom_id
    }
    nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)
    return restproxy_serv.get(nuage_l3_domain.get_resource(),
                              required=True)[0]['parentID']
    def check_if_l2Dom_in_correct_ent(self, nuage_l2dom_id, nuage_netpart):
        nuagesubn = nuagelib.NuageSubnet()
        resp_subn = self.restproxy.rest_call(
            'GET', nuagesubn.get_resource(nuage_l2dom_id), '')
        if not nuagesubn.validate(resp_subn):
            nuagel2dom = nuagelib.NuageL2Domain()
            response = self.restproxy.rest_call(
                'GET', nuagel2dom.get_resource(nuage_l2dom_id), '')
            if not nuagel2dom.validate(response):
                raise restproxy.RESTProxyError(nuagel2dom.error_msg)
            else:
                if response[3][0]['parentID'] == nuage_netpart['id']:
                    return True
                return False
        else:
            req_params = {'zone_id': resp_subn[3][0]['parentID']}
            nuagezone = nuagelib.NuageZone(create_params=req_params)
            resp_zone = self.restproxy.rest_call('GET',
                                                 nuagezone.get_resource(), '')

            if not nuagezone.validate(resp_zone):
                raise restproxy.RESTProxyError(nuagezone.error_msg)

            req_params = {'domain_id': resp_zone[3][0]['parentID']}
            nuage_l3domain = nuagelib.NuageL3Domain(create_params=req_params)
            dom_resp = self.restproxy.rest_call('GET',
                                                nuage_l3domain.get_resource(),
                                                '')

            if not nuage_l3domain.validate(dom_resp):
                raise restproxy.RESTProxyError(nuage_l3domain.error_msg)
            if dom_resp[3][0]['parentID'] == nuage_netpart['id']:
                return True
            return False
Exemple #4
0
    def get_zone_by_routerid(self, neutron_router_id, shared=False):
        nuage_rtr_id = helper.get_l3domid_by_router_id(
            self.restproxy, neutron_router_id)
        l3dom_tmplt_id = helper.get_l3dom_template_id_by_dom_id(
            self.restproxy, nuage_rtr_id)

        req_params = {
            'domain_id': nuage_rtr_id
        }
        nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)

        if shared:
            zone_name = (plugin_constants.DEF_NUAGE_ZONE_PREFIX + '-pub-' +
                         l3dom_tmplt_id)
        else:
            zone_name = (plugin_constants.DEF_NUAGE_ZONE_PREFIX + '-' +
                         l3dom_tmplt_id)

        nuage_extra_headers = nuage_l3_domain.extra_headers_get_name(zone_name)
        zones = self.restproxy.get(nuage_l3_domain.get_all_zones(),
                                   extra_headers=nuage_extra_headers)
        if zones:
            return zones[0]
        zone_name = TEMPLATE_SHARED_ZONE if shared else TEMPLATE_ISOLATED_ZONE
        nuage_extra_headers = nuage_l3_domain.extra_headers_get_name(
            zone_name)
        zones = self.restproxy.get(nuage_l3_domain.get_all_zones(),
                                   extra_headers=nuage_extra_headers)
        return zones[0] if zones else None
Exemple #5
0
    def update_router(self, nuage_domain_id, router, updates):
        tunnel_types = constants.VSD_TUNNEL_TYPES
        update_dict = {
            'name': router['id'],
            'description': router['name'],
            'routeDistinguisher': router.get('rd'),
            'routeTarget': router.get('rt'),
            'tunnelType': tunnel_types.get(router.get('tunnel_type'),
                                           router.get('tunnel_type')),
            'ECMPCount': router.get('ecmp_count'),
            'backHaulVNID': router.get('nuage_backhaul_vnid'),
            'backHaulRouteDistinguisher': router.get('nuage_backhaul_rd'),
            'backHaulRouteTarget': router.get('nuage_backhaul_rt')
        }

        underlay_routing = updates.get(plugin_constants.NUAGE_UNDERLAY)
        if underlay_routing is not None:
            pat_enabled, underlay_enabled = \
                self._calculate_pat_and_underlay(updates)
            update_dict['PATEnabled'] = pat_enabled
            update_dict['underlayEnabled'] = underlay_enabled

        nuagel3domain = nuagelib.NuageL3Domain()
        self.restproxy.put(nuagel3domain.put_resource(nuage_domain_id),
                           update_dict)
Exemple #6
0
def get_l3dom_template_id_by_dom_id(restproxy_serv, dom_id):
    req_params = {
        'domain_id': dom_id
    }
    nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)
    l3domain_template = restproxy_serv.get(nuage_l3_domain.get_resource(),
                                           required=True)[0]
    return l3domain_template['templateID']
Exemple #7
0
 def get_router_by_id(self, nuage_l3domain_id, required=False):
     params = {
         'domain_id': nuage_l3domain_id
     }
     nuage_router = nuagelib.NuageL3Domain(create_params=params)
     response = self.restproxy.get(nuage_router.get_resource(),
                                   required=required)
     return response[0] if response else None
def get_l3dom_by_router_id(restproxy_serv, rtr_id):
    req_params = {'externalID': get_vsd_external_id(rtr_id)}
    nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)
    l3domain = restproxy_serv.get(
        nuage_l3_domain.get_all_resources(),
        extra_headers=nuage_l3_domain.extra_headers_get(),
        required=True)
    return l3domain[0] if l3domain else None
    def get_router_by_external(self, ext_id):
        params = {'externalID': get_vsd_external_id(ext_id)}

        nuagerouter = nuagelib.NuageL3Domain(create_params=params)
        l3_doms = self.restproxy.get(
            nuagerouter.get_resource_with_ext_id(),
            extra_headers=nuagerouter.extra_headers_get(),
            required=True)
        return l3_doms[0] if l3_doms else None
Exemple #10
0
 def get_fip_underlay_enabled_domain_by_netpart(self, netpart_id):
     nuagel3dom = nuagelib.NuageL3Domain({'net_partition_id': netpart_id})
     fip_enabled_domain = self.restproxy.get(
         nuagel3dom.get_all_resources_in_ent(),
         extra_headers=nuagel3dom.extra_headers_get_fipunderlay(True))
     if fip_enabled_domain:
         return fip_enabled_domain[0]['ID']
     else:
         return None
Exemple #11
0
    def get_router_np_id(self, router_id):
        req_params = {'domain_id': router_id}
        nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)
        response = self.restproxy.rest_call('GET',
                                            nuage_l3_domain.get_resource(), '')

        if not nuage_l3_domain.validate(response):
            raise restproxy.RESTProxyError(nuage_l3_domain.error_msg)

        if response[3]:
            return response[3][0]['parentID']
Exemple #12
0
 def get_zone_by_domainid(self, domain_id):
     nuage_l3_domain = nuagelib.NuageL3Domain({'domain_id': domain_id})
     zones = self.restproxy.get(nuage_l3_domain.get_all_zones(),
                                required=True)
     res = []
     for zone in zones:
         np_dict = dict()
         np_dict['zone_name'] = zone['name']
         np_dict['zone_id'] = zone['ID']
         res.append(np_dict)
     return res
Exemple #13
0
def get_nuage_domain_by_zoneid(restproxy_serv, zone_id):
    nuage_dom = get_nuage_zone_by_id(restproxy_serv, zone_id)
    req_params = {
        'domain_id': nuage_dom['nuage_parent_id']
    }
    nuage_l3domain = nuagelib.NuageL3Domain(create_params=req_params)
    l3domain = restproxy_serv.get(nuage_l3domain.get_resource(),
                                  required=True)[0]

    return {'nuage_domain_id': l3domain['ID'],
            'externalID': (strip_cms_id(l3domain['externalID'])
                           if l3domain['externalID'] else None)}
Exemple #14
0
def get_l3dom_template_id_by_dom_id(restproxy_serv, dom_id):
    req_params = {'domain_id': dom_id}

    nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)
    response = restproxy_serv.rest_call('GET', nuage_l3_domain.get_resource(),
                                        '', '')

    if not nuage_l3_domain.validate(response):
        raise restproxy.RESTProxyError(nuage_l3_domain.error_msg)

    if response[VSD_RESP_OBJ]:
        return response[VSD_RESP_OBJ][0]['templateID']
 def get_routers_by_netpart(self, netpart_id):
     nuagel3dom = nuagelib.NuageL3Domain({'net_partition_id': netpart_id})
     response = self.restproxy.rest_call(
         'GET', nuagel3dom.get_all_resources_in_ent(), '')
     if not nuagel3dom.validate(response):
         raise restproxy.RESTProxyError(nuagel3dom.error_msg)
     res = []
     for l3dom in nuagel3dom.get_response_objlist(response):
         np_dict = dict()
         np_dict['domain_name'] = l3dom['name']
         np_dict['domain_id'] = l3dom['ID']
         res.append(np_dict)
     return res
 def _create_domain(self, req_params, extra_params):
     nuage_l3domain = nuagelib.NuageL3Domain(create_params=req_params,
                                             extra_params=extra_params)
     created_domain = self.restproxy.post(nuage_l3domain.post_resource(),
                                          nuage_l3domain.post_data())[0]
     req_params = {'domain_id': created_domain['ID']}
     nuage_zone = nuagelib.NuageZone(req_params)
     zone_list = self.restproxy.get(nuage_zone.list_resource())
     if not zone_list:
         self.delete_l3domain(created_domain['ID'])
         msg = ("Cannot find zone under the created domain {} on VSD. "
                "Delete the created domain".format(created_domain['ID']))
         raise restproxy.ResourceNotFoundException(msg)
     return created_domain, zone_list
Exemple #17
0
def get_l3dom_by_router_id(restproxy_serv, rtr_id):
    req_params = {'externalID': get_vsd_external_id(rtr_id)}

    nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)
    response = restproxy_serv.rest_call(
        'GET',
        nuage_l3_domain.get_all_resources(),
        '',
        extra_headers=nuage_l3_domain.extra_headers_get())

    if not nuage_l3_domain.validate(response):
        raise restproxy.RESTProxyError(nuage_l3_domain.error_msg)

    return (nuage_l3_domain, response)
    def get_router_by_external(self, ext_id):
        params = {'externalID': get_vsd_external_id(ext_id)}

        nuagerouter = nuagelib.NuageL3Domain(create_params=params)
        response = self.restproxy.rest_call(
            'GET',
            nuagerouter.get_resource_with_ext_id(),
            '',
            extra_headers=nuagerouter.extra_headers_get())
        if not nuagerouter.validate(response):
            raise restproxy.RESTProxyError(nuagerouter.error_msg)
        if response[3]:
            return nuagerouter.get_response_obj(response)
        else:
            return None
 def get_zone_by_domainid(self, domain_id):
     nuage_l3_domain = nuagelib.NuageL3Domain({'domain_id': domain_id})
     response = self.restproxy.rest_call('GET',
                                         nuage_l3_domain.get_all_zones(),
                                         '')
     if not nuage_l3_domain.validate(response):
         raise restproxy.RESTProxyError(
             nuage_l3_domain.error_msg,
             nuage_l3_domain.get_error_code(response))
     res = []
     for zone in nuage_l3_domain.get_response_objlist(response):
         np_dict = dict()
         np_dict['zone_name'] = zone['name']
         np_dict['zone_id'] = zone['ID']
         res.append(np_dict)
     return res
Exemple #20
0
    def validate_create_domain_subnet(self, neutron_subn, nuage_subnet_id,
                                      nuage_rtr_id):
        net_cidr = netaddr.IPNetwork(neutron_subn['cidr'])

        nuagel3dom = nuagelib.NuageL3Domain()
        overlapping_subnet = self.restproxy.get(
            nuagel3dom.get_domain_subnets(nuage_rtr_id),
            extra_headers=nuagel3dom.extra_headers_get_address(
                cidr=net_cidr, ip_type=neutron_subn['ip_version']),
            required=True)

        if overlapping_subnet:
            msg = ("Cidr %s of subnet %s overlaps with another subnet in the "
                   "VSD" % (net_cidr, nuage_subnet_id))
            raise restproxy.ResourceConflictException(msg)
        return True
    def validate_port_create_redirect_target(self, params):
        nuage_subnet_id = params.get('nuage_subnet_id')
        if params.get('parent_type') == constants.DOMAIN:
            nuage_domain_id = params.get('parent')
            nuagel3dom = nuagelib.NuageL3Domain()
            l3_subnets = self.restproxy.get(
                nuagel3dom.get_domain_subnets(nuage_domain_id), required=True)

            for subnet in l3_subnets:
                if subnet['ID'] == nuage_subnet_id:
                    return True
        elif params.get('parent_type') == constants.L2DOMAIN:
            nuage_l2domain_id = params.get('parent')
            if nuage_l2domain_id == nuage_subnet_id:
                return True
        return False
Exemple #22
0
def get_nuage_domain_by_zoneid(restproxy_serv, zone_id):
    nuage_dom = get_nuage_zone_by_id(restproxy_serv, zone_id)
    req_params = {'domain_id': nuage_dom['nuage_parent_id']}
    nuage_l3domain = nuagelib.NuageL3Domain(create_params=req_params)
    dom_resp = restproxy_serv.rest_call('GET', nuage_l3domain.get_resource(),
                                        '')

    if not nuage_l3domain.validate(dom_resp):
        raise restproxy.RESTProxyError(nuage_l3domain.error_msg)

    if len(dom_resp[3]) > 0:
        ret = {'nuage_domain_id': dom_resp[3][0]['ID'], 'externalID': None}
        if dom_resp[3][0]['externalID']:
            ret['externalID'] = strip_cms_id(dom_resp[3][0]['externalID'])

        return ret
    def validate_port_create_redirect_target(self, params):
        nuage_subnet_id = params.get('nuage_subnet_id')
        if params.get('parent_type') == 'domain':
            nuage_domain_id = params.get('parent')
            nuagel3dom = nuagelib.NuageL3Domain()
            l3dom_subnets = self.restproxy.rest_call(
                'GET', nuagel3dom.get_domain_subnets(nuage_domain_id), '')
            if not nuagel3dom.validate(l3dom_subnets):
                raise self.restproxy.RESTProxyError(nuagel3dom.error_msg)

            for subnet in l3dom_subnets[3]:
                if subnet['ID'] == nuage_subnet_id:
                    return True
        elif params.get('parent_type') == constants.L2DOMAIN:
            nuage_l2domain_id = params.get('parent')
            if nuage_l2domain_id == nuage_subnet_id:
                return True
        return False
    def validate_create_domain_subnet(self, neutron_subn, nuage_subnet_id,
                                      nuage_rtr_id):
        net_cidr = netaddr.IPNetwork(neutron_subn['cidr'])
        net_ip = net_cidr.ip

        nuagel3dom = nuagelib.NuageL3Domain()
        nuagel3domsub = self.restproxy.rest_call(
            'GET', nuagel3dom.get_domain_subnets(nuage_rtr_id), '',
            nuagel3dom.extra_headers_get_address(net_ip))

        if not nuagel3dom.validate(nuagel3domsub):
            raise self.restproxy.RESTProxyError(nuagel3dom.error_msg)

        if nuagel3domsub[3]:
            msg = ("Cidr %s of subnet %s overlaps with another subnet in the "
                   "VSD" % (net_cidr, nuage_subnet_id))
            raise restproxy.RESTProxyError(msg)
        return True
 def check_if_l2_dom_in_correct_ent(self, nuage_l2dom_id, nuage_netpart):
     nuagesubn = nuagelib.NuageSubnet()
     try:
         subnet = self.restproxy.get(nuagesubn.get_resource(nuage_l2dom_id),
                                     required=True)[0]
     except restproxy.ResourceNotFoundException:
         nuagel2dom = nuagelib.NuageL2Domain()
         l2_dom = self.restproxy.get(
             nuagel2dom.get_resource(nuage_l2dom_id), required=True)[0]
         return l2_dom['parentID'] == nuage_netpart['id']
     else:
         req_params = {'zone_id': subnet['parentID']}
         nuagezone = nuagelib.NuageZone(create_params=req_params)
         zone = self.restproxy.get(nuagezone.get_resource(),
                                   required=True)[0]
         req_params = {'domain_id': zone['parentID']}
         nuage_l3domain = nuagelib.NuageL3Domain(create_params=req_params)
         l3_dom = self.restproxy.get(nuage_l3domain.get_resource(),
                                     required=True)[0]
         return l3_dom['parentID'] == nuage_netpart['id']
    def create_domain_subnet(self, vsd_zone, os_subnet, pnet_binding):
        req_params = {
            'name': os_subnet['id'],
            'net': netaddr.IPNetwork(os_subnet['cidr']),
            'zone': vsd_zone['ID'],
            'gateway': os_subnet['gateway_ip'],
            'externalID': get_vsd_external_id(os_subnet['id'])
        }
        extra_params = {
            'description': os_subnet.get('name'),
            'entityState': 'UNDER_CONSTRUCTION'
        }
        nuagel3domsub = nuagelib.NuageSubnet(create_params=req_params,
                                             extra_params=extra_params)
        vsd_subnet = self.restproxy.post(nuagel3domsub.post_resource(),
                                         nuagel3domsub.post_data())[0]

        nuagedhcpoptions = dhcpoptions.NuageDhcpOptions(self.restproxy)
        nuagedhcpoptions.create_nuage_dhcp(
            os_subnet,
            parent_id=vsd_subnet['ID'],
            network_type=constants.NETWORK_TYPE_L3)

        if pnet_binding:
            # Get netpart id needed in process_provider_network to check the
            # gateway port enterprise permissions
            req_params = {'domain_id': vsd_zone['parentID']}
            nuage_l3domain = nuagelib.NuageL3Domain(create_params=req_params)
            domain = self.restproxy.get(nuage_l3domain.get_resource())[0]
            np_id = helper.get_l3domain_np_id(self.restproxy, domain['ID'])

            pnet_params = {
                'pnet_binding': pnet_binding,
                'nuage_subnet_id': vsd_subnet['ID'],
                'netpart_id': np_id,
                'neutron_subnet_id': os_subnet['id']
            }
            pnet_helper.process_provider_network(self.restproxy,
                                                 self.policygroups,
                                                 pnet_params)
        return vsd_subnet
    def get_zone_by_routerid(self, neutron_router_id, shared=False):
        nuage_rtr_id = helper.get_l3domid_by_router_id(self.restproxy,
                                                       neutron_router_id)
        l3dom_tmplt_id = helper.get_l3dom_template_id_by_dom_id(
            self.restproxy, nuage_rtr_id)

        req_params = {'domain_id': nuage_rtr_id}
        nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)

        if shared:
            zone_name = constants.DEF_NUAGE_ZONE_PREFIX + '-pub-' + \
                l3dom_tmplt_id
        else:
            zone_name = constants.DEF_NUAGE_ZONE_PREFIX + '-' + l3dom_tmplt_id

        nuage_extra_headers = nuage_l3_domain.extra_headers_get_name(zone_name)
        response = self.restproxy.rest_call('GET',
                                            nuage_l3_domain.get_all_zones(),
                                            '',
                                            extra_headers=nuage_extra_headers)
        if not nuage_l3_domain.validate(response):
            raise restproxy.RESTProxyError(nuage_l3_domain.error_msg)
        if shared:
            if response[constants.VSD_RESP_OBJ]:
                return response[3][0]
            else:
                # TODO(Divya): try seems to be not required here
                try:
                    nuage_extra_headers = (
                        nuage_l3_domain.extra_headers_get_name(
                            TEMPLATE_SHARED_ZONE))
                    shared_zone = self.restproxy.rest_call(
                        'GET',
                        nuage_l3_domain.get_all_zones(),
                        '',
                        extra_headers=nuage_extra_headers)
                    if not nuage_l3_domain.validate(shared_zone):
                        raise restproxy.RESTProxyError(
                            nuage_l3_domain.error_msg)
                    if shared_zone[VSD_RESP_OBJ]:
                        return shared_zone[VSD_RESP_OBJ][0]
                except Exception:
                    return None
        else:
            if response[constants.VSD_RESP_OBJ]:
                return response[3][0]
            else:
                # This is needed for add_router_interface to a router created
                # with nuage-router-template parameter
                # return None when called from router_delete
                # TODO(Divya): try seems to be not required here
                try:
                    nuage_extra_headers = (
                        nuage_l3_domain.extra_headers_get_name(
                            TEMPLATE_ISOLATED_ZONE))
                    isolated_zone = self.restproxy.rest_call(
                        'GET',
                        nuage_l3_domain.get_all_zones(),
                        '',
                        extra_headers=nuage_extra_headers)
                    if not nuage_l3_domain.validate(isolated_zone):
                        raise restproxy.RESTProxyError(
                            nuage_l3_domain.error_msg)
                    if isolated_zone[VSD_RESP_OBJ]:
                        return isolated_zone[VSD_RESP_OBJ][0]
                except Exception:
                    return None

        return None
Exemple #28
0
 def delete_l3domain(self, domain_id):
     nuagel3domain = nuagelib.NuageL3Domain()
     self.restproxy.delete(nuagel3domain.delete_resource(domain_id))
Exemple #29
0
 def get_routers_by_netpart(self, netpart_id):
     nuagel3dom = nuagelib.NuageL3Domain({'net_partition_id': netpart_id})
     return self.restproxy.get(nuagel3dom.get_all_resources_in_ent(),
                               required=True)
Exemple #30
0
 def get_router_np_id(self, router_id):
     req_params = {'domain_id': router_id}
     nuage_l3_domain = nuagelib.NuageL3Domain(create_params=req_params)
     l3_doms = self.restproxy.get(nuage_l3_domain.get_resource(),
                                  required=True)
     return l3_doms[0]['parentID'] if l3_doms else None