Example #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
Example #2
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
    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