Commit 02da2000 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add FloatingIP model

Add Floating IP model to represent a floating IP that has been reserved
by a user. Each FloatingIP has an owner(UUID), an IPv4 address, the
network(pool) that has reserved from and the date is was reserved. Also,
it may be related to a VirtualMachine, if there is some VM that uses
this IP.

Also, create the corresponding model factory for tests.
parent 7cf9699b
......@@ -702,6 +702,31 @@ class NetworkInterface(models.Model):
return '%s@%s' % (self.machine.name, self.network.name)
class FloatingIP(models.Model):
userid = models.CharField("UUID of the owner", max_length=128,
null=False, db_index=True)
ipv4 = models.IPAddressField(null=False, unique=True, db_index=True)
network = models.ForeignKey(Network, related_name="floating_ips",
null=False)
machine = models.ForeignKey(VirtualMachine, related_name="floating_ips",
null=True)
created = models.DateTimeField(auto_now_add=True)
deleted = models.BooleanField(default=False, null=False)
serial = models.ForeignKey(QuotaHolderSerial,
related_name="floating_ips", null=True)
objects = ForUpdateManager()
def __unicode__(self):
return "<%s@%s>" % (self.ipv4, self.network.id)
def in_use(self):
if self.machine is None:
return False
else:
return (not self.machine.deleted)
class PoolTable(models.Model):
available_map = models.TextField(default="", null=False)
reserved_map = models.TextField(default="", null=False)
......
......@@ -181,6 +181,15 @@ class NetworkInterfaceFactory(factory.DjangoModelFactory):
factory.Sequence(round_seq_first(FACTORY_FOR.FIREWALL_PROFILES))
class FloatingIPFactory(factory.DjangoModelFactory):
FACTORY_FOR = models.FloatingIP
machine = factory.SubFactory(VirtualMachineFactory)
network = factory.SubFactory(NetworkFactory, public=False, deleted=False)
ipv4 = factory.LazyAttributeSequence(lambda a, n: a.network.subnet[:-4] +
'{0}'.format(int(n) + 2))
class BridgePoolTableFactory(factory.DjangoModelFactory):
FACTORY_FOR = models.BridgePoolTable
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment