add node label feature
diff --git a/xos/core/admin.py b/xos/core/admin.py
index 28d99fd..910ee97 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -1266,6 +1266,14 @@
list_display_links = ('backend_status_icon', 'name', )
class NodeForm(forms.ModelForm):
+ labels = forms.ModelMultipleChoiceField(
+ queryset=NodeLabel.objects.all(),
+ required=False,
+ help_text="Select which labels apply to this node",
+ widget=FilteredSelectMultiple(
+ verbose_name=('Labels'), is_stacked=False
+ )
+ )
class Meta:
model = Node
widgets = {
@@ -1273,6 +1281,31 @@
'deployment': LinkedSelect
}
+ def __init__(self, *args, **kwargs):
+ request = kwargs.pop('request', None)
+ super(NodeForm, self).__init__(*args, **kwargs)
+
+ if self.instance and self.instance.pk:
+ self.fields['labels'].initial = self.instance.labels.all()
+
+ def save(self, commit=True):
+ node = super(NodeForm, self).save(commit=False)
+
+ node.labels = self.cleaned_data['labels']
+
+ if commit:
+ node.save()
+
+ return node
+
+
+class NodeLabelAdmin(XOSBaseAdmin):
+ list_display = ('name',)
+ list_display_links = ('name', )
+
+ fields = ('name', )
+
+
class NodeAdmin(XOSBaseAdmin):
form = NodeForm
list_display = ('backend_status_icon', 'name', 'site_deployment')
@@ -1280,13 +1313,14 @@
list_filter = ('site_deployment',)
inlines = [TagInline,InstanceInline]
- fieldsets = [('Node Details', {'fields': ['backend_status_text', 'name', 'site_deployment'], 'classes':['suit-tab suit-tab-details']})]
+ fieldsets = [('Node Details', {'fields': ['backend_status_text', 'name', 'site_deployment'], 'classes':['suit-tab suit-tab-details']}),
+ ('Labels', {'fields': ['labels'], 'classes':['suit-tab suit-tab-labels']})]
readonly_fields = ('backend_status_text', )
user_readonly_fields = ['name','site_deployment']
user_readonly_inlines = [TagInline,InstanceInline]
- suit_form_tabs =(('details','Node Details'),('instances','Instances'))
+ suit_form_tabs =(('details','Node Details'),('instances','Instances'), ('labels', 'Labels'))
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'site':
@@ -2107,6 +2141,7 @@
admin.site.register(SiteRole)
admin.site.register(SliceRole)
admin.site.register(Node, NodeAdmin)
+ admin.site.register(NodeLabel, NodeLabelAdmin)
#admin.site.register(SlicePrivilege, SlicePrivilegeAdmin)
#admin.site.register(SitePrivilege, SitePrivilegeAdmin)
admin.site.register(Instance, InstanceAdmin)
diff --git a/xos/core/models/__init__.py b/xos/core/models/__init__.py
index 628a3bb..2ee6b94 100644
--- a/xos/core/models/__init__.py
+++ b/xos/core/models/__init__.py
@@ -21,7 +21,7 @@
from .credential import UserCredential,SiteCredential,SliceCredential
from .site import SiteRole
from .site import SitePrivilege
-from .node import Node
+from .node import Node, NodeLabel
from .slicetag import SliceTag
from .instance import Instance
from .reservation import ReservedResource
diff --git a/xos/core/models/node.py b/xos/core/models/node.py
index 5496d6b..b825787 100644
--- a/xos/core/models/node.py
+++ b/xos/core/models/node.py
@@ -28,3 +28,9 @@
def can_update(self, user):
return user.can_update_site(self.site, allow=['tech'])
+
+class NodeLabel(PlCoreBase):
+ name = StrippedCharField(max_length=200, help_text="label name", unique=True)
+ node = models.ManyToManyField(Node, related_name="labels", blank=True)
+
+ def __unicode__(self): return u'%s' % (self.name)