Commit 6783921c authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Add 'public' attribute to ports

Extend ports (NetworkInterface model) with 'public' attribute, to
indicate that the port is connected to a public network without getting
the network from the DB. Add corresponding DB migration and update the
DB models factory.

Refs: #5109
parent 2059f27c
......@@ -221,7 +221,7 @@ def get_server_public_ip(vm_nics, version=4):
"""
for nic in vm_nics:
for ip in nic.ips.all():
if ip.ipversion == version and ip.public:
if nic.public and ip.ipversion == version:
return ip
return None
......
This diff is collapsed.
......@@ -756,10 +756,6 @@ class IPAddress(models.Model):
class Meta:
unique_together = ("network", "address", "deleted")
@property
def public(self):
return self.network.public
def release_address(self):
"""Release the IPv4 address."""
if self.ipversion == 4:
......@@ -825,6 +821,7 @@ class NetworkInterface(models.Model):
security_groups = models.ManyToManyField("SecurityGroup", null=True)
state = models.CharField(max_length=32, null=False, default="ACTIVE",
choices=STATES)
public = models.BooleanField(default=False)
device_owner = models.CharField('Device owner', max_length=128, null=True)
def __unicode__(self):
......
......@@ -183,6 +183,7 @@ class NetworkInterfaceFactory(factory.DjangoModelFactory):
index = factory.Sequence(lambda x: x, type=int)
mac = factory.Sequence(lambda n: 'aa:{0}{0}:{0}{0}:aa:{0}{0}:{0}{0}'
.format(hex(int(n) % 15)[2:3]))
public = factory.LazyAttribute(lambda self: self.network.public)
state = "ACTIVE"
firewall_profile =\
factory.Sequence(round_seq_first(FACTORY_FOR.FIREWALL_PROFILES))
......
......@@ -498,6 +498,7 @@ def _create_port(userid, network, machine=None, use_ipaddress=None,
state="DOWN",
userid=userid,
device_owner=None,
public=network.public,
name=name)
# add the security groups if any
......
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