Commit c4776f8e by tarokkk

network serializer

parent bd497c80
......@@ -467,12 +467,28 @@ def delete_instance_pre(sender, instance, using, **kwargs):
class Interface(models.Model):
"""Network interface for an instance.
"""
vlan = models.ForeignKey(Vlan)
host = models.ForeignKey(Host, blank=True, null=True)
instance = models.ForeignKey(Instance, related_name='interface_set')
def mac_generator(self):
# MAC 02:XX:XX:X:VID
pass
def get_vmnetwork_desc(self):
return {
'name': 'cloud-' + self.instance.id + '-' + self.vlan.vid,
'bridge': 'cloud',
'mac': self.mac_generator(),
'ipv4': self.host.ipv4 if self.host is not None else None,
'ipv6': self.host.ipv6 if self.host is not None else None,
'vlan': self.vlan.vid,
'managed': self.host is not None
}
@classmethod
def create_from_template(cls, instance, template):
"""Create a new interface for an instance based on an
......
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 sign in to comment