Ejemplo n.º 1
0
    def _create_ipam(self, ipam_name, proj_obj, subnets=[], type=None):
        ipam_obj = NetworkIpam(name=ipam_name, parent_obj=proj_obj)

        ipam_subnets = []
        for subnet in subnets:
            pfx, pfx_len = subnet.split('/')
            ipam_subnet = IpamSubnetType(subnet=SubnetType(pfx, int(pfx_len)))
            ipam_subnets.append(ipam_subnet)
        if not len(ipam_subnets):
            self._logger.debug("%s - %s subnet is empty for %s" \
                 %(self._name, ipam_name, subnets))

        if type == 'flat-subnet':
            ipam_obj.set_ipam_subnet_method('flat-subnet')
            ipam_obj.set_ipam_subnets(IpamSubnets(ipam_subnets))

        ipam_update = False
        try:
            ipam_uuid = self._vnc_lib.network_ipam_create(ipam_obj)
            ipam_update = True
        except RefsExistError:
            curr_ipam_obj = self._vnc_lib.network_ipam_read(
                fq_name=ipam_obj.get_fq_name())
            ipam_uuid = curr_ipam_obj.get_uuid()
            if type == 'flat-subnet' and not curr_ipam_obj.get_ipam_subnets():
                self._vnc_lib.network_ipam_update(ipam_obj)
                ipam_update = True

        # Cache ipam info.
        NetworkIpamKM.locate(ipam_uuid)

        return ipam_update, ipam_obj, ipam_subnets
Ejemplo n.º 2
0
    def _create_ipam(self, ipam_name, subnets, proj_obj, ipam_type):
        """
        Create an ipam.
        If an ipam with same name exists, return the existing object.
        """
        ipam_subnets = []
        for subnet in subnets:
            pfx, pfx_len = subnet.split('/')
            ipam_subnet = IpamSubnetType(subnet=SubnetType(pfx, int(pfx_len)))
            ipam_subnets.append(ipam_subnet)

        ipam_obj = NetworkIpam(name=ipam_name, parent_obj=proj_obj)
        if ipam_type == 'flat-subnet':
            ipam_obj.set_ipam_subnet_method('flat-subnet')
            ipam_obj.set_ipam_subnets(IpamSubnets(ipam_subnets))

        try:
            self._vnc_lib.network_ipam_create(ipam_obj)
        except RefsExistError:
            pass

        ipam = self._vnc_lib.network_ipam_read(fq_name=ipam_obj.get_fq_name())

        # Cache ipam info.
        NetworkIpamKM.locate(ipam.uuid)

        return ipam_obj, ipam_subnets
Ejemplo n.º 3
0
 def _create_network_ipam(self, name, network_type, subnet, proj_obj,
                          vn_obj=None):
     ipam_obj = NetworkIpam(name=name, parent_obj=proj_obj)
     pfx, pfx_len = subnet.split('/')
     ipam_subnet = IpamSubnetType(subnet=SubnetType(pfx, int(pfx_len)))
     if network_type == 'flat-subnet':
         ipam_obj.set_ipam_subnet_method('flat-subnet')
         ipam_obj.set_ipam_subnets(IpamSubnets([ipam_subnet]))
     try:
         self._vnc_lib.network_ipam_create(ipam_obj)
     except RefsExistError:
         ipam_obj = self._vnc_lib.network_ipam_read(
             fq_name=ipam_obj.get_fq_name())
     if vn_obj:
         if network_type == 'flat-subnet':
             vn_obj.add_network_ipam(ipam_obj, VnSubnetsType([]))
         else:
             vn_obj.add_network_ipam(ipam_obj, VnSubnetsType([ipam_subnet]))
     return ipam_obj