示例#1
0
 def add_addr(addr, expect_family):
     if not addr:
         return
     if addr.version != expect_family:
         raise RuntimeError("Wrong family for %r" % a)
     try:
         a = IPAddress.objects.get(
             address=addr,
             vrf=data.get("vrf"),
         )
         result = "Assigned"
     except ObjectDoesNotExist:
         a = IPAddress(
             address=addr,
             vrf=data.get("vrf"),
         )
         result = "Created"
     a.status = IPAddressStatusChoices.STATUS_ACTIVE
     a.dns_name = data["dns_name"]
     if a.interface:
         raise RuntimeError("Address %s is already assigned" % addr)
     a.interface = interface
     a.tenant = data.get("tenant")
     a.save()
     self.log_info("%s IP address %s %s" %
                   (result, a.address, a.vrf or ""))
     setattr(vm, "primary_ip%d" % a.family, a)
示例#2
0
 def add_addr(addr, family):
     if not addr:
         return
     if addr.version != family:
         raise RuntimeError(f"Wrong family for {a}")
     try:
         a = IPAddress.objects.get(
             address=addr,
             vrf=data.get("vrf"),
         )
         result = "Assigned"
     except ObjectDoesNotExist:
         a = IPAddress(
             address=addr,
             vrf=data.get("vrf"),
         )
         result = "Created"
     a.status = IPAddressStatusChoices.STATUS_ACTIVE
     a.dns_name = data["dns_name"]
     if a.assigned_object:
         raise RuntimeError(f"Address {addr} is already assigned")
     a.assigned_object = vminterface
     a.tenant = data.get("tenant")
     a.full_clean()
     a.save()
     #a.tags.set(data[f"primary_ip{family}_tags"])
     self.log_info(f"{result} IP address {a.address} {a.vrf or ''}")
     setattr(vm, f"primary_ip{family}", a)