blob: 37175ec032231010975c12c3b7c3238900e63888 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
Tony Mack31d34132013-04-15 00:02:06 -04002import commands
Siobhan Tully4bc09f22013-04-10 21:15:21 -04003from django.db import models
Siobhan Tully30fd4292013-05-10 08:59:56 -04004from core.models import PlCoreBase
5from core.models import Slice
Siobhan Tully73291342013-05-10 10:50:08 -04006from openstack.manager import OpenStackManager
Siobhan Tully4bc09f22013-04-10 21:15:21 -04007
8# Create your models here.
9
10class Subnet(PlCoreBase):
Tony Mackcdec0902013-04-15 00:38:49 -040011 subnet_id = models.CharField(max_length=256, unique=True)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040012 cidr = models.CharField(max_length=20)
13 ip_version = models.IntegerField()
14 start = models.IPAddressField()
15 end = models.IPAddressField()
Tony Mack771f4b92013-04-12 01:49:57 -040016 slice = models.ForeignKey(Slice, related_name='subnet')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040017
Tony Mackf79ad8e2013-04-12 13:52:44 -040018 def __unicode__(self): return u'%s' % (self.slice.name)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040019
Tony Mack31d34132013-04-15 00:02:06 -040020 def save(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040021 if not hasattr(self, 'os_manager'):
22 setattr(self, 'os_manager', OpenStackManager())
23 self.os_manager.save_subnet(self)
Tony Mack31d34132013-04-15 00:02:06 -040024 super(Subnet, self).save(*args, **kwds)
25
26 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040027 if not hasattr(self, 'os_manager'):
28 setattr(self, 'os_manager', OpenStackManager())
29 self.os_manager.delete_subnet(self)
Tony Mack31d34132013-04-15 00:02:06 -040030 super(Subnet, self).delete(*args, **kwds)