Commit 64c22a19 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Major refactor on NIC model

Major refactor on db models concerning NetworkInterface models. A new
table, namely 'IPAddress' has been created to represent an IPAddress
(IPv4 or IPv6). Each IPAddress is related with a network and the subnet
from which it has been allocated. Also it contains 'floating_ip' attribute
to indicate whether it is a floating or static IP.

Also the dummy SecurityGroup model has been created, although it will
not currently be used.

The NetworkInterface model has been extended with the 'name',
'device_owner' and 'security_groups' attributes.
Signed-off-by: default avatarMarios Kogias <>
parent 0d6f8b2e
......@@ -669,6 +669,40 @@ class BackendNetwork(models.Model):
return '<%s@%s>' % (, self.backend)
class IPAddress(models.Model):
subnet = models.ForeignKey("Subnet", related_name="ips", null=False,
network = models.ForeignKey(Network, related_name="ips", null=False,
nic = models.ForeignKey("NetworkInterface", related_name="ips", null=True,
userid = models.CharField("UUID of the owner", max_length=128, null=False,
address = models.CharField("IP Address", max_length=64, null=False)
floating_ip = models.BooleanField("Floating IP", null=False, default=False)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
deleted = models.BooleanField(default=False, null=False)
serial = models.ForeignKey(QuotaHolderSerial,
related_name="ips", null=True,
def __unicode__(self):
ip_type = "floating" if self.floating_ip else "static"
return u"<IPAddress: %s, Network: %s, Subnet: %s, Type: %s>"\
% (self.address, self.network_id, self.subnet_id, ip_type)
def in_use(self):
if self.machine is None:
return False
return (not self.machine.deleted)
class Meta:
unique_together = ("network", "address")
class NetworkInterface(models.Model):
('ENABLED', 'Enabled'),
......@@ -682,11 +716,9 @@ class NetworkInterface(models.Model):
("ERROR", "Error"),
("FIXED", "Fixed IP Address"),
("FLOATING", "Floating IP Address"),
name = models.CharField('NIC name', max_length=128, null=True)
userid = models.CharField("UUID of the owner", max_length=128,
null=True, db_index=True)
machine = models.ForeignKey(VirtualMachine, related_name='nics',
network = models.ForeignKey(Network, related_name='nics',
......@@ -699,38 +731,23 @@ class NetworkInterface(models.Model):
ipv6 = models.CharField(max_length=100, null=True)
firewall_profile = models.CharField(choices=FIREWALL_PROFILES,
max_length=30, null=True)
security_groups = models.ManyToManyField("SecurityGroup", null=True)
state = models.CharField(max_length=32, null=False, default="ACTIVE",
ip_type = models.CharField(max_length=32, null=False, default="FIXED",
device_owner = models.CharField('Device owner', max_length=128, null=True)
def __unicode__(self):
return "<%s:vm:%s network:%s>" % (, self.machine_id,
def backend_uuid(self):
"""Return the backend id by prepending backend-prefix."""
return "%snic-%s" % (settings.BACKEND_PREFIX_ID, str(
def __unicode__(self):
return "<%s:vm:%s network:%s ipv4:%s ipv6:%s>" % \
(, self.machine_id, self.network_id, self.ipv4,
class Meta:
# Assert than an IPv4 address from the same network will not be
# assigned to more than one NICs
unique_together = ("network", "ipv4")
def delete(self):
"""Custom method for deleting NetworkInterfaces.
In case the NIC is of 'FLOATING' type, this method clears the 'machine'
flag of the FloatingIP object, before deleting the NIC.
if self.ip_type == "FLOATING":
super(NetworkInterface, self).delete()
class SecurityGroup(models.Model):
name = models.CharField('group name', max_length=128)
class FloatingIP(models.Model):
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