示例#1
0
    def create_domain_subnet(self,
                             vsd_zone,
                             ipv4_subnet,
                             ipv6_subnet,
                             network_name,
                             enable_ingress_replication=False):
        subnet = ipv4_subnet or ipv6_subnet
        net = netaddr.IPNetwork(subnet['cidr'])
        req_params = {
            'name': helper.get_subnet_name(subnet),
            'zone': vsd_zone['ID'],
            'externalID': helper.get_subnet_external_id(subnet)
        }
        description = helper.get_subnet_description(subnet)
        extra_params = {
            'description': description,
            'entityState': 'UNDER_CONSTRUCTION',
            'dualStackDynamicIPAllocation': False,
            'ingressReplicationEnabled': enable_ingress_replication
        }
        if ipv4_subnet:
            extra_params.update({
                'address': str(net.ip),
                'netmask': str(net.netmask),
                'gateway': ipv4_subnet['gateway_ip'],
                'enableDHCPv4': ipv4_subnet['enable_dhcp']
            })
        elif ipv6_subnet:
            extra_params.update({
                'IPv6Address': str(net.cidr),
                'IPv6Gateway': ipv6_subnet['gateway_ip'],
                'IPType': constants.IPV6,
                'enableDHCPv6': ipv6_subnet['enable_dhcp']
            })

        # attach dualstack subnet to a router
        if ipv4_subnet and ipv6_subnet:
            params = {
                'network_name': network_name,
                'network_id': subnet['network_id']
            }
            data = helper.get_subnet_update_data(ipv4_subnet, ipv6_subnet,
                                                 params)
            extra_params.update(data)

        vsd_subnet = self._create_subnet(req_params, extra_params)

        nuagedhcpoptions = dhcpoptions.NuageDhcpOptions(self.restproxy)
        if ipv4_subnet:
            nuagedhcpoptions.create_nuage_dhcp(
                ipv4_subnet,
                parent_id=vsd_subnet['ID'],
                network_type=constants.NETWORK_TYPE_L3)
        if ipv6_subnet:
            nuagedhcpoptions.create_nuage_dhcp(
                ipv6_subnet,
                parent_id=vsd_subnet['ID'],
                network_type=constants.NETWORK_TYPE_L3)
        return vsd_subnet
示例#2
0
 def _create_nuage_def_l2domain_adv_fwd_template(self, l2dom_id,
                                                 neutron_subnet):
     nuageadvfwdtmplt = nuagelib.NuageInAdvFwdTemplate()
     external_id = helper.get_subnet_external_id(neutron_subnet)
     response = self.restproxy.post(
         nuageadvfwdtmplt.post_resource_l2(l2dom_id),
         nuageadvfwdtmplt.post_data_default_l2(l2dom_id, external_id),
         ignore_err_codes=[restproxy.REST_DUPLICATE_ACL_PRIORITY])
     return response[0]['ID']
示例#3
0
 def get_l2domain_by_ext_id_and_cidr(self, subnet):
     params = {
         'externalID': helper.get_subnet_external_id(subnet),
         'cidr': netaddr.IPNetwork(subnet['cidr']),
         'ip_type': subnet['ip_version']
     }
     nuagel2domain = nuagelib.NuageL2Domain(create_params=params)
     l2domain = self.restproxy.get(
         nuagel2domain.get_all_resources(),
         extra_headers=nuagel2domain.extra_headers_ext_id_and_cidr_get())
     if l2domain:
         return l2domain[0]
     else:
         msg = ("Cannot find subnet with externalID {} and cidr {}"
                " in L2domains on VSD").format(params['externalID'],
                                               params['cidr'])
         raise restproxy.ResourceNotFoundException(msg)
示例#4
0
    def create_shared_subnet(self, vsd_zone_id, subnet, params):
        req_params = {
            'name': helper.get_subnet_name(subnet),
            'zone': vsd_zone_id,
            'externalID': helper.get_subnet_external_id(subnet)
        }
        net = netaddr.IPNetwork(subnet['cidr'])
        extra_params = {
            'address': str(net.ip),
            'netmask': str(net.netmask),
            'gateway': subnet['gateway_ip'],
            'resourceType': params['resourceType'],
            'description': subnet['name'],
            'IPType': constants.IPV4
        }
        if params.get('underlay'):
            extra_params['underlay'] = params['underlay']

        nuage_subnet = self._create_subnet(req_params, extra_params)
        nuage_subnet['nuage_userid'] = None
        nuage_subnet['nuage_groupid'] = None
        return nuage_subnet
示例#5
0
    def create_subnet(self, ipv4_subnet, ipv6_subnet, params):
        subnet = ipv4_subnet or ipv6_subnet
        req_params = {
            'net_partition_id': params['netpart_id'],
            'name': helper.get_subnet_name(subnet)
        }
        ext_params = {
            'externalID': helper.get_subnet_external_id(subnet),
            'DHCPManaged': True,
            'dualStackDynamicIPAllocation': False
        }

        if ipv4_subnet:
            net = netaddr.IPNetwork(ipv4_subnet['cidr'])
            ext_params.update({
                'address': str(net.ip),
                'netmask': str(net.netmask),
                'gateway': params['dhcp_ip'],
                'IPType': constants.IPV4,
                'enableDHCPv4': ipv4_subnet['enable_dhcp']
            })
        elif ipv6_subnet:
            net = netaddr.IPNetwork(ipv6_subnet['cidr'])
            ext_params.update({
                'IPv6Address': str(net.cidr),
                'IPv6Gateway': params['dhcpv6_ip'],
                'IPType': constants.IPV6,
                'enableDHCPv6': ipv6_subnet['enable_dhcp']
            })
        if ipv4_subnet and ipv6_subnet:
            params.update({'network_id': subnet['network_id']})
            ext_params.update(
                helper.get_subnet_update_data(ipv4_subnet=ipv4_subnet,
                                              ipv6_subnet=ipv6_subnet,
                                              params=params))
        if not ext_params.get('description'):
            ext_params['description'] = helper.get_subnet_description(subnet)

        nuagel2domtmplt = nuagelib.NuageL2DomTemplate(create_params=req_params,
                                                      extra_params=ext_params)
        nuagel2domtemplate = self.restproxy.post(
            nuagel2domtmplt.post_resource(),
            nuagel2domtmplt.post_data(),
            on_res_exists=self.restproxy.retrieve_by_ext_id_and_cidr)[0]

        l2dom_tmplt_id = nuagel2domtemplate['ID']

        req_params['template'] = l2dom_tmplt_id
        req_params['externalID'] = ext_params['externalID']

        ext_params = {
            'address': ext_params.get('address'),
            'IPv6Address': ext_params.get('IPv6Address'),
            'description': ext_params['description'],
            'IPType': ext_params['IPType'],
            'ingressReplicationEnabled': params['ingressReplicationEnabled']
        }

        if (params.get('tunnelType') == constants.VSD_TUNNEL_TYPES['MPLS']):
            ext_params['l2EncapType'] = constants.VSD_TUNNEL_TYPES['MPLS']

        nuagel2domain = nuagelib.NuageL2Domain(create_params=req_params,
                                               extra_params=ext_params)
        try:
            l2domain = self.restproxy.post(
                nuagel2domain.post_resource(),
                nuagel2domain.post_data(),
                on_res_exists=self.restproxy.retrieve_by_ext_id_and_cidr)[0]
        except Exception:
            self.restproxy.delete(
                nuagel2domtmplt.delete_resource(nuagel2domtemplate['ID']))
            raise

        l2domain_id = l2domain['ID']
        subnet_dict = {
            'nuage_l2template_id': l2dom_tmplt_id,
            'nuage_l2domain_id': l2domain_id,
            'nuage_external_id': strip_cms_id(l2domain['externalID']),
            'nuage_parent_id': l2domain['parentID']
        }

        nuagedhcpoptions = dhcpoptions.NuageDhcpOptions(self.restproxy)
        if ipv4_subnet:
            nuagedhcpoptions.create_nuage_dhcp(
                ipv4_subnet,
                parent_id=l2domain_id,
                network_type=constants.NETWORK_TYPE_L2)
        if ipv6_subnet:
            nuagedhcpoptions.create_nuage_dhcp(
                ipv6_subnet,
                parent_id=l2domain_id,
                network_type=constants.NETWORK_TYPE_L2)

        nuage_userid, nuage_groupid = helper.create_usergroup(
            self.restproxy, params['tenant_id'], params['netpart_id'],
            params.get('tenant_name'))
        subnet_dict['nuage_userid'] = nuage_userid
        subnet_dict['nuage_groupid'] = nuage_groupid

        self._attach_nuage_group_to_l2domain(nuage_groupid, l2domain_id,
                                             params['netpart_id'],
                                             params.get('shared'),
                                             params['tenant_id'])
        self._create_nuage_def_l2domain_acl(
            l2domain_id, subnet, allow_non_ip=params['allow_non_ip'])
        self._create_nuage_def_l2domain_adv_fwd_template(l2domain_id, subnet)

        return subnet_dict