Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
Tony Mack | 31d3413 | 2013-04-15 00:02:06 -0400 | [diff] [blame] | 2 | import commands |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 3 | from django.db import models |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 4 | from core.models import PlCoreBase |
| 5 | from core.models import Slice |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame^] | 6 | from openstack.manager import OpenStackManager |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 7 | |
| 8 | # Create your models here. |
| 9 | |
| 10 | class Subnet(PlCoreBase): |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 11 | subnet_id = models.CharField(max_length=256, unique=True) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 12 | cidr = models.CharField(max_length=20) |
| 13 | ip_version = models.IntegerField() |
| 14 | start = models.IPAddressField() |
| 15 | end = models.IPAddressField() |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 16 | slice = models.ForeignKey(Slice, related_name='subnet') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 17 | |
Tony Mack | f79ad8e | 2013-04-12 13:52:44 -0400 | [diff] [blame] | 18 | def __unicode__(self): return u'%s' % (self.slice.name) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 19 | |
Tony Mack | 31d3413 | 2013-04-15 00:02:06 -0400 | [diff] [blame] | 20 | def save(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame^] | 21 | if not hasattr(self, 'os_manager'): |
| 22 | setattr(self, 'os_manager', OpenStackManager()) |
| 23 | self.os_manager.save_subnet(self) |
Tony Mack | 31d3413 | 2013-04-15 00:02:06 -0400 | [diff] [blame] | 24 | super(Subnet, self).save(*args, **kwds) |
| 25 | |
| 26 | def delete(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame^] | 27 | if not hasattr(self, 'os_manager'): |
| 28 | setattr(self, 'os_manager', OpenStackManager()) |
| 29 | self.os_manager.delete_subnet(self) |
Tony Mack | 31d3413 | 2013-04-15 00:02:06 -0400 | [diff] [blame] | 30 | super(Subnet, self).delete(*args, **kwds) |