Added support for Generic Tags. Tags can be applied to Node, Site, Slice, Sliver. Adjusted relation_name for SliceTags to not conflict with generic tag.
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index aafa6e5..d947c6e 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -11,8 +11,9 @@
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.contrib.auth.signals import user_logged_in
from django.utils import timezone
-import django_evolution
+from django.contrib.contenttypes import generic
+import django_evolution
class ReadonlyTabularInline(admin.TabularInline):
can_delete = False
@@ -30,6 +31,11 @@
def has_add_permission(self, request):
return False
+class TagInline(generic.GenericTabularInline):
+ model = Tag
+ exclude = ['enacted']
+ extra = 1
+
class SliverInline(admin.TabularInline):
model = Sliver
fields = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'node', 'deploymentNetwork']
@@ -186,7 +192,7 @@
]
list_display = ('name', 'login_base','site_url', 'enabled')
filter_horizontal = ('deployments',)
- inlines = [NodeInline, UserInline, SitePrivilegeInline]
+ inlines = [TagInline, NodeInline, UserInline, SitePrivilegeInline]
search_fields = ['name']
def queryset(self, request):
@@ -262,7 +268,7 @@
class SliceAdmin(PlanetStackBaseAdmin):
fields = ['name', 'site', 'serviceClass', 'description', 'slice_url']
list_display = ('name', 'site','serviceClass', 'slice_url')
- inlines = [SliverInline, SliceMembershipInline, SliceTagInline]
+ inlines = [SliverInline, SliceMembershipInline, TagInline, SliceTagInline]
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'site':
@@ -371,6 +377,7 @@
class NodeAdmin(admin.ModelAdmin):
list_display = ('name', 'site', 'deployment')
list_filter = ('deployment',)
+ inlines = [TagInline]
class SliverForm(forms.ModelForm):
@@ -389,6 +396,7 @@
('Sliver', {'fields': ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'key', 'node', 'deploymentNetwork']})
]
list_display = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'key', 'node', 'deploymentNetwork']
+ inlines = [TagInline]
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'slice':
@@ -684,10 +692,9 @@
admin.site.register(Deployment, DeploymentAdmin)
admin.site.register(Site, SiteAdmin)
admin.site.register(Slice, SliceAdmin)
-#admin.site.register(Subnet)
-
if showAll:
+ admin.site.register(Tag)
admin.site.register(Node, NodeAdmin)
admin.site.register(SliceMembership, SliceMembershipAdmin)
admin.site.register(SitePrivilege, SitePrivilegeAdmin)
diff --git a/planetstack/core/models/__init__.py b/planetstack/core/models/__init__.py
index 4f8bd85..4e6cc83 100644
--- a/planetstack/core/models/__init__.py
+++ b/planetstack/core/models/__init__.py
@@ -1,5 +1,6 @@
from .plcorebase import PlCoreBase
from .deployment import Deployment
+from .tag import Tag
from .site import Site
from .site import SitePrivilege
from .image import Image
diff --git a/planetstack/core/models/node.py b/planetstack/core/models/node.py
index fcc3a6a..0781609 100644
--- a/planetstack/core/models/node.py
+++ b/planetstack/core/models/node.py
@@ -3,6 +3,8 @@
from core.models import PlCoreBase
from core.models import Site
from core.models import Deployment
+from core.models import Tag
+from django.contrib.contenttypes import generic
# Create your models here.
@@ -10,5 +12,6 @@
name = models.CharField(max_length=200, unique=True, help_text="Name of the Node")
site = models.ForeignKey(Site, related_name='nodes')
deployment = models.ForeignKey(Deployment, related_name='nodes')
+ tags = generic.GenericRelation(Tag)
def __unicode__(self): return u'%s' % (self.name)
diff --git a/planetstack/core/models/site.py b/planetstack/core/models/site.py
index 53a1a6c..5c84d1b 100644
--- a/planetstack/core/models/site.py
+++ b/planetstack/core/models/site.py
@@ -2,6 +2,8 @@
from django.db import models
from core.models import PlCoreBase
from core.models import Deployment
+from core.models import Tag
+from django.contrib.contenttypes import generic
class Site(PlCoreBase):
@@ -16,6 +18,7 @@
abbreviated_name = models.CharField(max_length=80)
deployments = models.ManyToManyField(Deployment, blank=True, related_name='sites')
+ tags = generic.GenericRelation(Tag)
def __unicode__(self): return u'%s' % (self.name)
diff --git a/planetstack/core/models/slice.py b/planetstack/core/models/slice.py
index 63754e4..74815b2 100644
--- a/planetstack/core/models/slice.py
+++ b/planetstack/core/models/slice.py
@@ -6,6 +6,8 @@
from core.models import Role
from core.models import Deployment
from core.models import ServiceClass
+from core.models import Tag
+from django.contrib.contenttypes import generic
# Create your models here.
@@ -21,6 +23,8 @@
router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id")
subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id")
+ tags = generic.GenericRelation(Tag)
+
serviceClass = models.ForeignKey(ServiceClass, related_name = "slices", null=True, default=ServiceClass.get_default)
creator = models.ForeignKey(User, related_name='slices', blank=True, null=True)
diff --git a/planetstack/core/models/slicetag.py b/planetstack/core/models/slicetag.py
index 38343b3..76cc669 100644
--- a/planetstack/core/models/slicetag.py
+++ b/planetstack/core/models/slicetag.py
@@ -4,7 +4,7 @@
from core.models import Slice
class SliceTag(PlCoreBase):
- slice = models.ForeignKey(Slice, related_name='tags')
+ slice = models.ForeignKey(Slice, related_name='slicetags')
NAME_CHOICES = (('privatekey', 'Private Key'), ('publickey', 'Public Key'))
name = models.CharField(help_text="The name of this tag", max_length=30, choices=NAME_CHOICES)
diff --git a/planetstack/core/models/sliver.py b/planetstack/core/models/sliver.py
index 13eb353..44a6af1 100644
--- a/planetstack/core/models/sliver.py
+++ b/planetstack/core/models/sliver.py
@@ -8,6 +8,8 @@
from core.models import Site
from core.models import Deployment
from core.models import User
+from core.models import Tag
+from django.contrib.contenttypes import generic
# Create your models here.
class Sliver(PlCoreBase):
@@ -22,7 +24,7 @@
node = models.ForeignKey(Node, related_name='slivers')
deploymentNetwork = models.ForeignKey(Deployment, verbose_name='deployment', related_name='sliver_deploymentNetwork')
numberCores = models.IntegerField(verbose_name="Number of Cores", help_text="Number of cores for sliver", default=0)
-
+ tags = generic.GenericRelation(Tag)
def __unicode__(self): return u'%s' % (self.instance_name)
diff --git a/planetstack/core/models/tag.py b/planetstack/core/models/tag.py
new file mode 100644
index 0000000..786b036
--- /dev/null
+++ b/planetstack/core/models/tag.py
@@ -0,0 +1,21 @@
+import os
+from django.db import models
+from core.models import PlCoreBase
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.contenttypes import generic
+
+# Create your models here.
+
+class Tag(PlCoreBase):
+
+ name = models.SlugField(help_text="The name of this tag", max_length=128)
+ value = models.CharField(help_text="The value of this tag", max_length=1024)
+
+ # The required fields to do a ObjectType lookup, and object_id assignment
+ content_type = models.ForeignKey(ContentType)
+ object_id = models.PositiveIntegerField()
+ content_object = generic.GenericForeignKey('content_type', 'object_id')
+
+ def __unicode__(self):
+ return self.name
+