blob: b84ee22181ccf24996ff3b2ed8728bdf6b092e83 [file] [log] [blame]
Scott Bakerbb2a2a22015-04-21 16:59:04 -07001from django.contrib import admin
2
3from cord.models import *
4from django import forms
5from django.utils.safestring import mark_safe
6from django.contrib.auth.admin import UserAdmin
7from django.contrib.admin.widgets import FilteredSelectMultiple
8from django.contrib.auth.forms import ReadOnlyPasswordHashField
9from django.contrib.auth.signals import user_logged_in
10from django.utils import timezone
11from django.contrib.contenttypes import generic
12from suit.widgets import LinkedSelect
Scott Baker6dddd2f2015-07-23 12:06:26 -070013from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
Scott Bakerbb2a2a22015-04-21 16:59:04 -070014
15from functools import update_wrapper
16from django.contrib.admin.views.main import ChangeList
17from django.core.urlresolvers import reverse
18from django.contrib.admin.utils import quote
19
Scott Baker27b768d2015-04-21 17:15:18 -070020#-----------------------------------------------------------------------------
21# vOLT
22#-----------------------------------------------------------------------------
Scott Bakerbb2a2a22015-04-21 16:59:04 -070023
24class VOLTServiceAdmin(ReadOnlyAwareAdmin):
25 model = VOLTService
26 verbose_name = "vOLT Service"
27 verbose_name_plural = "vOLT Service"
28 list_display = ("backend_status_icon", "name", "enabled")
29 list_display_links = ('backend_status_icon', 'name', )
Scott Baker27b768d2015-04-21 17:15:18 -070030 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
Scott Bakerbb2a2a22015-04-21 16:59:04 -070031 readonly_fields = ('backend_status_text', )
Scott Baker9da53042015-05-15 09:08:19 -070032 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Bakerbb2a2a22015-04-21 16:59:04 -070033
34 extracontext_registered_admins = True
35
36 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
37
38 suit_form_tabs =(('general', 'vOLT Service Details'),
39 ('administration', 'Administration'),
40 #('tools', 'Tools'),
41 ('slices','Slices'),
42 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -070043 ('serviceprivileges','Privileges'),
Scott Bakerbb2a2a22015-04-21 16:59:04 -070044 )
45
46 suit_form_includes = (('voltadmin.html', 'top', 'administration'),
47 ) #('hpctools.html', 'top', 'tools') )
48
49 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -070050 return VOLTService.get_service_objects_by_user(request.user)
Scott Bakerbb2a2a22015-04-21 16:59:04 -070051
52class VOLTTenantForm(forms.ModelForm):
Scott Bakereefe65c2015-07-13 13:08:07 -070053 vlan_id = forms.CharField()
54 creator = forms.ModelChoiceField(queryset=User.objects.all())
55
Scott Bakerbb2a2a22015-04-21 16:59:04 -070056 def __init__(self,*args,**kwargs):
57 super (VOLTTenantForm,self ).__init__(*args,**kwargs)
58 self.fields['kind'].default = "vOLT"
59 self.fields['kind'].widget.attrs['readonly'] = True
60 self.fields['provider_service'].queryset = VOLTService.get_service_objects().all()
Scott Bakereefe65c2015-07-13 13:08:07 -070061 if self.instance:
62 # fields for the attributes
63 self.fields['vlan_id'].initial = self.instance.vlan_id
64 self.fields['creator'].initial = self.instance.creator
65
66 def save(self, commit=True):
67 self.instance.vlan_id = self.cleaned_data.get("vlan_id")
68 self.instance.creator = self.cleaned_data.get("creator")
69 return super(VOLTTenantForm, self).save(commit=commit)
Scott Bakerbb2a2a22015-04-21 16:59:04 -070070
71 class Meta:
72 model = VOLTTenant
73
74class VOLTTenantAdmin(ReadOnlyAwareAdmin):
Scott Baker836fbe62015-07-06 17:20:37 -070075 list_display = ('backend_status_icon', 'id', 'service_specific_id', 'vlan_id', 'subscriber_root' )
Scott Baker27b768d2015-04-21 17:15:18 -070076 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -070077 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_root', 'service_specific_id', # 'service_specific_attribute',
78 'vlan_id', 'creator'],
79 'classes':['suit-tab suit-tab-general']})]
Scott Bakereefe65c2015-07-13 13:08:07 -070080 readonly_fields = ('backend_status_text', 'service_specific_attribute')
Scott Bakerbb2a2a22015-04-21 16:59:04 -070081 form = VOLTTenantForm
82
83 suit_form_tabs = (('general','Details'),)
84
85 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -070086 return VOLTTenant.get_tenant_objects_by_user(request.user)
Scott Bakerbb2a2a22015-04-21 16:59:04 -070087
Scott Baker27b768d2015-04-21 17:15:18 -070088#-----------------------------------------------------------------------------
89# vCPE
90#-----------------------------------------------------------------------------
91
Scott Baker62312972015-07-13 14:30:25 -070092class VCPEServiceForm(forms.ModelForm):
Scott Baker2b56cf42015-07-15 18:08:06 -070093 bbs_api_hostname = forms.CharField(required=False)
94 bbs_api_port = forms.IntegerField(required=False)
Scott Baker80157da2015-07-15 17:42:43 -070095 bbs_server = forms.CharField(required=False)
96 backend_network_label = forms.CharField(required=False)
97 bbs_slice = forms.ModelChoiceField(queryset=Slice.objects.all(), required=False)
Scott Baker62312972015-07-13 14:30:25 -070098
99 def __init__(self,*args,**kwargs):
100 super (VCPEServiceForm,self ).__init__(*args,**kwargs)
101 if self.instance:
Scott Baker2b56cf42015-07-15 18:08:06 -0700102 self.fields['bbs_api_hostname'].initial = self.instance.bbs_api_hostname
103 self.fields['bbs_api_port'].initial = self.instance.bbs_api_port
Scott Baker80157da2015-07-15 17:42:43 -0700104 self.fields['bbs_server'].initial = self.instance.bbs_server
Scott Bakerd4829ea2015-07-15 18:04:22 -0700105 self.fields['backend_network_label'].initial = self.instance.backend_network_label
Scott Baker80157da2015-07-15 17:42:43 -0700106 self.fields['bbs_slice'].initial = self.instance.bbs_slice
Scott Baker62312972015-07-13 14:30:25 -0700107
108 def save(self, commit=True):
Scott Baker2b56cf42015-07-15 18:08:06 -0700109 self.instance.bbs_api_hostname = self.cleaned_data.get("bbs_api_hostname")
110 self.instance.bbs_api_port = self.cleaned_data.get("bbs_api_port")
Scott Baker80157da2015-07-15 17:42:43 -0700111 self.instance.bbs_server = self.cleaned_data.get("bbs_server")
Scott Bakerd4829ea2015-07-15 18:04:22 -0700112 self.instance.backend_network_label = self.cleaned_data.get("backend_network_label")
Scott Baker80157da2015-07-15 17:42:43 -0700113 self.instance.bbs_slice = self.cleaned_data.get("bbs_slice")
Scott Baker62312972015-07-13 14:30:25 -0700114 return super(VCPEServiceForm, self).save(commit=commit)
115
116 class Meta:
117 model = VCPEService
118
Scott Baker27b768d2015-04-21 17:15:18 -0700119class VCPEServiceAdmin(ReadOnlyAwareAdmin):
120 model = VCPEService
121 verbose_name = "vCPE Service"
122 verbose_name_plural = "vCPE Service"
123 list_display = ("backend_status_icon", "name", "enabled")
124 list_display_links = ('backend_status_icon', 'name', )
Scott Baker80157da2015-07-15 17:42:43 -0700125 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "service_specific_attribute",],
126 'classes':['suit-tab suit-tab-general']}),
Scott Baker2b56cf42015-07-15 18:08:06 -0700127 ("backend config", {'fields': [ "backend_network_label", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"],
Scott Baker80157da2015-07-15 17:42:43 -0700128 'classes':['suit-tab suit-tab-backend']}) ]
Scott Baker62312972015-07-13 14:30:25 -0700129 readonly_fields = ('backend_status_text', "service_specific_attribute")
Scott Baker9da53042015-05-15 09:08:19 -0700130 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Baker62312972015-07-13 14:30:25 -0700131 form = VCPEServiceForm
Scott Baker27b768d2015-04-21 17:15:18 -0700132
133 extracontext_registered_admins = True
134
135 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
136
Scott Baker80157da2015-07-15 17:42:43 -0700137 suit_form_tabs =(('general', 'Service Details'),
138 ('backend', 'Backend Config'),
Scott Baker27b768d2015-04-21 17:15:18 -0700139 ('administration', 'Administration'),
140 #('tools', 'Tools'),
141 ('slices','Slices'),
142 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -0700143 ('serviceprivileges','Privileges') ,
Scott Baker27b768d2015-04-21 17:15:18 -0700144 )
145
146 suit_form_includes = (('vcpeadmin.html', 'top', 'administration'),
147 ) #('hpctools.html', 'top', 'tools') )
148
149 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700150 return VCPEService.get_service_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700151
152class VCPETenantForm(forms.ModelForm):
Scott Baker80a39292015-07-21 18:18:25 -0700153 bbs_account = forms.CharField(required=False)
154 creator = forms.ModelChoiceField(queryset=User.objects.all())
155 sliver = forms.ModelChoiceField(queryset=Sliver.objects.all(),required=False)
156 last_ansible_hash = forms.CharField(required=False)
157
Scott Baker27b768d2015-04-21 17:15:18 -0700158 def __init__(self,*args,**kwargs):
159 super (VCPETenantForm,self ).__init__(*args,**kwargs)
160 self.fields['kind'].default = "vCPE"
161 self.fields['kind'].widget.attrs['readonly'] = True
162 self.fields['provider_service'].queryset = VCPEService.get_service_objects().all()
Scott Baker80a39292015-07-21 18:18:25 -0700163 if self.instance:
164 # fields for the attributes
165 self.fields['bbs_account'].initial = self.instance.bbs_account
166 self.fields['creator'].initial = self.instance.creator
167 self.fields['sliver'].initial = self.instance.sliver
168 self.fields['last_ansible_hash'].initial = self.instance.last_ansible_hash
169
170 def save(self, commit=True):
171 self.instance.creator = self.cleaned_data.get("creator")
172 self.instance.sliver = self.cleaned_data.get("sliver")
173 self.instance.last_ansible_hash = self.cleaned_data.get("last_ansible_hash")
174 return super(VCPETenantForm, self).save(commit=commit)
Scott Baker27b768d2015-04-21 17:15:18 -0700175
176 class Meta:
177 model = VCPETenant
178
179class VCPETenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerb3cf9212015-07-06 14:40:20 -0700180 list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
Scott Baker27b768d2015-04-21 17:15:18 -0700181 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -0700182 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute',
183 'bbs_account', 'creator', 'sliver', 'last_ansible_hash'],
184 'classes':['suit-tab suit-tab-general']})]
185 readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account')
Scott Baker27b768d2015-04-21 17:15:18 -0700186 form = VCPETenantForm
187
188 suit_form_tabs = (('general','Details'),)
189
190 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700191 return VCPETenant.get_tenant_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700192
193#-----------------------------------------------------------------------------
194# vBNG
195#-----------------------------------------------------------------------------
196
Scott Baker21d18932015-07-21 18:24:21 -0700197class VBNGServiceForm(forms.ModelForm):
198 vbng_url = forms.CharField(required=False)
199
200 def __init__(self,*args,**kwargs):
201 super (VBNGServiceForm,self ).__init__(*args,**kwargs)
202 if self.instance:
203 self.fields['vbng_url'].initial = self.instance.vbng_url
204
205 def save(self, commit=True):
206 self.instance.vbng_url = self.cleaned_data.get("vbng_url")
207 return super(VBNGServiceForm, self).save(commit=commit)
208
209 class Meta:
210 model = VBNGService
211
Scott Baker27b768d2015-04-21 17:15:18 -0700212class VBNGServiceAdmin(ReadOnlyAwareAdmin):
213 model = VBNGService
214 verbose_name = "vBNG Service"
215 verbose_name_plural = "vBNG Service"
216 list_display = ("backend_status_icon", "name", "enabled")
217 list_display_links = ('backend_status_icon', 'name', )
Scott Baker21d18932015-07-21 18:24:21 -0700218 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url",
219 'vbng_url' ],
220 'classes':['suit-tab suit-tab-general']})]
Scott Baker27b768d2015-04-21 17:15:18 -0700221 readonly_fields = ('backend_status_text', )
Scott Baker9da53042015-05-15 09:08:19 -0700222 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Baker21d18932015-07-21 18:24:21 -0700223 form = VBNGServiceForm
Scott Baker27b768d2015-04-21 17:15:18 -0700224
225 extracontext_registered_admins = True
226
227 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
228
229 suit_form_tabs =(('general', 'vBNG Service Details'),
230 ('administration', 'Administration'),
231 #('tools', 'Tools'),
232 ('slices','Slices'),
233 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -0700234 ('serviceprivileges','Privileges'),
Scott Baker27b768d2015-04-21 17:15:18 -0700235 )
236
237 suit_form_includes = (('vbngadmin.html', 'top', 'administration'),
238 ) #('hpctools.html', 'top', 'tools') )
239
240 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700241 return VBNGService.get_service_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700242
243class VBNGTenantForm(forms.ModelForm):
Scott Baker80a39292015-07-21 18:18:25 -0700244 routeable_subnet = forms.CharField(required=False)
245 mapped_hostname = forms.CharField(required=False)
246 mapped_ip = forms.CharField(required=False)
247 mapped_mac = forms.CharField(required=False)
248
Scott Baker27b768d2015-04-21 17:15:18 -0700249 def __init__(self,*args,**kwargs):
250 super (VBNGTenantForm,self ).__init__(*args,**kwargs)
251 self.fields['kind'].default = "vBNG"
252 self.fields['kind'].widget.attrs['readonly'] = True
253 self.fields['provider_service'].queryset = VBNGService.get_service_objects().all()
Scott Baker80a39292015-07-21 18:18:25 -0700254 if self.instance:
255 # fields for the attributes
256 self.fields['routeable_subnet'].initial = self.instance.routeable_subnet
257 self.fields['mapped_hostname'].initial = self.instance.mapped_hostname
258 self.fields['mapped_ip'].initial = self.instance.mapped_ip
259 self.fields['mapped_mac'].initial = self.instance.mapped_mac
260
261 def save(self, commit=True):
262 self.instance.routeable_subnet = self.cleaned_data.get("routeable_subnet")
263 self.instance.mapped_hostname = self.cleaned_data.get("mapped_hostname")
264 self.instance.mapped_ip = self.cleaned_data.get("mapped_ip")
265 self.instance.mapped_mac = self.cleaned_data.get("mapped_mac")
266 return super(VBNGTenantForm, self).save(commit=commit)
Scott Baker27b768d2015-04-21 17:15:18 -0700267
268 class Meta:
269 model = VBNGTenant
270
271class VBNGTenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerb3cf9212015-07-06 14:40:20 -0700272 list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
Scott Baker27b768d2015-04-21 17:15:18 -0700273 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -0700274 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute',
275 'routeable_subnet', 'mapped_hostname', 'mapped_ip', 'mapped_mac'],
276 'classes':['suit-tab suit-tab-general']})]
277 readonly_fields = ('backend_status_text', 'service_specific_attribute')
Scott Baker27b768d2015-04-21 17:15:18 -0700278 form = VBNGTenantForm
279
280 suit_form_tabs = (('general','Details'),)
281
282 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700283 return VBNGTenant.get_tenant_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700284
Scott Baker6dddd2f2015-07-23 12:06:26 -0700285#-----------------------------------------------------------------------------
286# CordSubscriberRoot
287#-----------------------------------------------------------------------------
288
Scott Baker4124e962015-07-24 10:15:01 -0700289class VOLTTenantInline(XOSTabularInline):
290 model = VOLTTenant
291 fields = ['provider_service', 'subscriber_root', 'service_specific_id']
292 readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id']
293 extra = 0
294 max_num = 0
295 suit_classes = 'suit-tab suit-tab-volttenants'
296 fk_name = 'subscriber_root'
297 verbose_name = 'subscribed tenant'
298 verbose_name_plural = 'subscribed tenants'
299
300 @property
301 def selflink_reverse_path(self):
302 return "admin:cord_volttenant_change"
303
304 def queryset(self, request):
305 qs = super(VOLTTenantInline, self).queryset(request)
306 return qs.filter(kind=VOLT_KIND)
307
Scott Baker6dddd2f2015-07-23 12:06:26 -0700308class CordSubscriberRootForm(forms.ModelForm):
309 url_filter_level = forms.CharField(required = False)
310
311 def __init__(self,*args,**kwargs):
312 super (CordSubscriberRootForm,self ).__init__(*args,**kwargs)
313 self.fields['kind'].default = CORD_SUBSCRIBER_KIND
314 self.fields['kind'].widget.attrs['readonly'] = True
315 if self.instance:
316 self.fields['url_filter_level'].initial = self.instance.url_filter_level
317
318 def save(self, commit=True):
319 self.instance.url_filter_level = self.cleaned_data.get("url_filter_level")
320 return super(CordSubscriberRootForm, self).save(commit=commit)
321
322 class Meta:
323 model = CordSubscriberRoot
324
325class CordSubscriberRootAdmin(ReadOnlyAwareAdmin):
326 list_display = ('backend_status_icon', 'id', 'name', )
327 list_display_links = ('backend_status_icon', 'id', 'name', )
328 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute',
329 'url_filter_level'],
330 'classes':['suit-tab suit-tab-general']})]
331 readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account')
332 form = CordSubscriberRootForm
Scott Baker4124e962015-07-24 10:15:01 -0700333 inlines = (VOLTTenantInline, TenantRootPrivilegeInline)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700334
335 suit_form_tabs =(('general', 'Cord Subscriber Root Details'),
Scott Baker4124e962015-07-24 10:15:01 -0700336 ('volttenants','VOLT Tenancy'),
Scott Baker6dddd2f2015-07-23 12:06:26 -0700337 ('tenantrootprivileges','Privileges')
338 )
339
340 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700341 return CordSubscriberRoot.get_tenant_objects_by_user(request.user)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700342
Scott Bakerbb2a2a22015-04-21 16:59:04 -0700343admin.site.register(VOLTService, VOLTServiceAdmin)
344admin.site.register(VOLTTenant, VOLTTenantAdmin)
Scott Baker27b768d2015-04-21 17:15:18 -0700345admin.site.register(VCPEService, VCPEServiceAdmin)
346admin.site.register(VCPETenant, VCPETenantAdmin)
347admin.site.register(VBNGService, VBNGServiceAdmin)
348admin.site.register(VBNGTenant, VBNGTenantAdmin)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700349admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin)
Scott Bakerbb2a2a22015-04-21 16:59:04 -0700350