blob: 18f1e816463053724876bb7ea882a9aecac275c1 [file] [log] [blame]
Scott Bakerbb2a2a22015-04-21 16:59:04 -07001from django.contrib import admin
2
Scott Baker98f51552015-12-31 10:18:28 -08003from services.cord.models import *
Scott Bakerbb2a2a22015-04-21 16:59:04 -07004from 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 Bakerd145efe2015-09-10 16:01:58 -070014from core.middleware import get_request
Scott Bakerbb2a2a22015-04-21 16:59:04 -070015
16from functools import update_wrapper
17from django.contrib.admin.views.main import ChangeList
18from django.core.urlresolvers import reverse
19from django.contrib.admin.utils import quote
20
Scott Baker27b768d2015-04-21 17:15:18 -070021#-----------------------------------------------------------------------------
22# vOLT
23#-----------------------------------------------------------------------------
Scott Bakerbb2a2a22015-04-21 16:59:04 -070024
25class VOLTServiceAdmin(ReadOnlyAwareAdmin):
26 model = VOLTService
27 verbose_name = "vOLT Service"
28 verbose_name_plural = "vOLT Service"
29 list_display = ("backend_status_icon", "name", "enabled")
30 list_display_links = ('backend_status_icon', 'name', )
Scott Baker27b768d2015-04-21 17:15:18 -070031 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 -070032 readonly_fields = ('backend_status_text', )
Scott Baker9da53042015-05-15 09:08:19 -070033 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Bakerbb2a2a22015-04-21 16:59:04 -070034
35 extracontext_registered_admins = True
36
37 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
38
39 suit_form_tabs =(('general', 'vOLT Service Details'),
40 ('administration', 'Administration'),
41 #('tools', 'Tools'),
42 ('slices','Slices'),
43 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -070044 ('serviceprivileges','Privileges'),
Scott Bakerbb2a2a22015-04-21 16:59:04 -070045 )
46
47 suit_form_includes = (('voltadmin.html', 'top', 'administration'),
48 ) #('hpctools.html', 'top', 'tools') )
49
50 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -070051 return VOLTService.get_service_objects_by_user(request.user)
Scott Bakerbb2a2a22015-04-21 16:59:04 -070052
53class VOLTTenantForm(forms.ModelForm):
Scott Bakerf1527cd2015-11-09 20:25:21 -080054 s_tag = forms.CharField()
55 c_tag = forms.CharField()
Scott Bakereefe65c2015-07-13 13:08:07 -070056 creator = forms.ModelChoiceField(queryset=User.objects.all())
57
Sapan Bhatia16be1432016-01-14 11:41:38 -050058 def __init__(self,*args,**kwargs):
59 super (VOLTTenantForm,self ).__init__(*args,**kwargs)
60 self.fields['kind'].widget.attrs['readonly'] = True
61 self.fields['provider_service'].queryset = VOLTService.get_service_objects().all()
62 if self.instance:
63 # fields for the attributes
64 self.fields['c_tag'].initial = self.instance.c_tag
65 self.fields['s_tag'].initial = self.instance.s_tag
66 self.fields['creator'].initial = self.instance.creator
67 if (not self.instance) or (not self.instance.pk):
68 # default fields for an 'add' form
69 self.fields['kind'].initial = VOLT_KIND
70 self.fields['creator'].initial = get_request().user
71 if VOLTService.get_service_objects().exists():
72 self.fields["provider_service"].initial = VOLTService.get_service_objects().all()[0]
73
74 def save(self, commit=True):
75 self.instance.s_tag = self.cleaned_data.get("s_tag")
76 self.instance.c_tag = self.cleaned_data.get("c_tag")
77 self.instance.creator = self.cleaned_data.get("creator")
78 return super(VOLTTenantForm, self).save(commit=commit)
79
80 class Meta:
Scott Bakerbb2a2a22015-04-21 16:59:04 -070081 model = VOLTTenant
82
83class VOLTTenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerf1527cd2015-11-09 20:25:21 -080084 list_display = ('backend_status_icon', 'id', 'service_specific_id', 's_tag', 'c_tag', 'subscriber_root' )
Scott Baker27b768d2015-04-21 17:15:18 -070085 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -070086 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_root', 'service_specific_id', # 'service_specific_attribute',
Scott Bakerf1527cd2015-11-09 20:25:21 -080087 's_tag', 'c_tag', 'creator'],
Scott Baker80a39292015-07-21 18:18:25 -070088 'classes':['suit-tab suit-tab-general']})]
Scott Bakereefe65c2015-07-13 13:08:07 -070089 readonly_fields = ('backend_status_text', 'service_specific_attribute')
Scott Bakerbb2a2a22015-04-21 16:59:04 -070090 form = VOLTTenantForm
91
92 suit_form_tabs = (('general','Details'),)
93
94 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -070095 return VOLTTenant.get_tenant_objects_by_user(request.user)
Scott Bakerbb2a2a22015-04-21 16:59:04 -070096
Scott Baker27b36bc2016-05-23 20:57:00 -070097class AccessDeviceInline(XOSTabularInline):
98 model = AccessDevice
99 fields = ['volt_device','uplink','vlan']
100 readonly_fields = []
101 extra = 0
102# max_num = 0
103 suit_classes = 'suit-tab suit-tab-accessdevices'
104
105# @property
106# def selflink_reverse_path(self):
107# return "admin:cord_volttenant_change"
108
109class VOLTDeviceAdmin(ReadOnlyAwareAdmin):
Scott Baker3424ab12016-05-24 15:27:19 -0700110 list_display = ('backend_status_icon', 'name', 'openflow_id', 'driver' )
111 list_display_links = ('backend_status_icon', 'name', 'openflow_id')
112 fieldsets = [ (None, {'fields': ['backend_status_text','name','volt_service','openflow_id','driver','access_agent'],
Scott Baker27b36bc2016-05-23 20:57:00 -0700113 'classes':['suit-tab suit-tab-general']})]
114 readonly_fields = ('backend_status_text',)
115 inlines = [AccessDeviceInline]
116
117 suit_form_tabs = (('general','Details'), ('accessdevices','Access Devices'))
118
119class AccessDeviceAdmin(ReadOnlyAwareAdmin):
120 list_display = ('backend_status_icon', 'id', 'volt_device', 'uplink', 'vlan' )
121 list_display_links = ('backend_status_icon', 'id')
122 fieldsets = [ (None, {'fields': ['backend_status_text','volt_device','uplink','vlan'],
123 'classes':['suit-tab suit-tab-general']})]
124 readonly_fields = ('backend_status_text',)
125
126 suit_form_tabs = (('general','Details'),)
127
128class AgentPortMappingInline(XOSTabularInline):
129 model = AgentPortMapping
130 fields = ['access_agent', 'mac', 'port']
131 readonly_fields = []
132 extra = 0
133# max_num = 0
134 suit_classes = 'suit-tab suit-tab-accessportmaps'
135
136# @property
137# def selflink_reverse_path(self):
138# return "admin:cord_volttenant_change"
139
140class AccessAgentAdmin(ReadOnlyAwareAdmin):
Scott Baker3424ab12016-05-24 15:27:19 -0700141 list_display = ('backend_status_icon', 'name', 'mac' )
142 list_display_links = ('backend_status_icon', 'name')
143 fieldsets = [ (None, {'fields': ['backend_status_text','name','volt_service','mac'],
Scott Baker27b36bc2016-05-23 20:57:00 -0700144 'classes':['suit-tab suit-tab-general']})]
145 readonly_fields = ('backend_status_text',)
146 inlines= [AgentPortMappingInline]
147
148 suit_form_tabs = (('general','Details'), ('accessportmaps', 'Port Mappings'))
149
Scott Baker27b768d2015-04-21 17:15:18 -0700150#-----------------------------------------------------------------------------
151# vCPE
152#-----------------------------------------------------------------------------
153
Scott Bakerf91e6152016-02-11 12:07:10 -0800154class VSGServiceForm(forms.ModelForm):
Scott Baker2b56cf42015-07-15 18:08:06 -0700155 bbs_api_hostname = forms.CharField(required=False)
156 bbs_api_port = forms.IntegerField(required=False)
Scott Baker80157da2015-07-15 17:42:43 -0700157 bbs_server = forms.CharField(required=False)
158 backend_network_label = forms.CharField(required=False)
159 bbs_slice = forms.ModelChoiceField(queryset=Slice.objects.all(), required=False)
Scott Bakerae6187c2016-02-23 14:58:49 -0800160 dns_servers = forms.CharField(required=False)
Scott Baker9b870572016-03-10 19:23:10 -0800161 url_filter_kind = forms.ChoiceField(choices=VSGService.URL_FILTER_KIND_CHOICES, required=False)
Scott Baker67074ab2016-03-04 11:29:02 -0800162 node_label = forms.CharField(required=False)
Scott Baker62312972015-07-13 14:30:25 -0700163
Sapan Bhatia16be1432016-01-14 11:41:38 -0500164 def __init__(self,*args,**kwargs):
Scott Bakerf91e6152016-02-11 12:07:10 -0800165 super (VSGServiceForm,self ).__init__(*args,**kwargs)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500166 if self.instance:
167 self.fields['bbs_api_hostname'].initial = self.instance.bbs_api_hostname
168 self.fields['bbs_api_port'].initial = self.instance.bbs_api_port
169 self.fields['bbs_server'].initial = self.instance.bbs_server
170 self.fields['backend_network_label'].initial = self.instance.backend_network_label
171 self.fields['bbs_slice'].initial = self.instance.bbs_slice
Scott Bakerae6187c2016-02-23 14:58:49 -0800172 self.fields['dns_servers'].initial = self.instance.dns_servers
Scott Baker9b870572016-03-10 19:23:10 -0800173 self.fields['url_filter_kind']. initial = self.instance.url_filter_kind
Scott Baker67074ab2016-03-04 11:29:02 -0800174 self.fields['node_label'].initial = self.instance.node_label
Sapan Bhatia16be1432016-01-14 11:41:38 -0500175
176 def save(self, commit=True):
177 self.instance.bbs_api_hostname = self.cleaned_data.get("bbs_api_hostname")
178 self.instance.bbs_api_port = self.cleaned_data.get("bbs_api_port")
179 self.instance.bbs_server = self.cleaned_data.get("bbs_server")
180 self.instance.backend_network_label = self.cleaned_data.get("backend_network_label")
181 self.instance.bbs_slice = self.cleaned_data.get("bbs_slice")
Scott Bakerae6187c2016-02-23 14:58:49 -0800182 self.instance.dns_servers = self.cleaned_data.get("dns_servers")
Scott Baker9b870572016-03-10 19:23:10 -0800183 self.instance.url_filter_kind = self.cleaned_data.get("url_filter_kind")
Scott Baker67074ab2016-03-04 11:29:02 -0800184 self.instance.node_label = self.cleaned_data.get("node_label")
Scott Bakerf91e6152016-02-11 12:07:10 -0800185 return super(VSGServiceForm, self).save(commit=commit)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500186
187 class Meta:
Scott Bakerf91e6152016-02-11 12:07:10 -0800188 model = VSGService
Scott Baker62312972015-07-13 14:30:25 -0700189
Scott Bakerf91e6152016-02-11 12:07:10 -0800190class VSGServiceAdmin(ReadOnlyAwareAdmin):
191 model = VSGService
Scott Bakerae6187c2016-02-23 14:58:49 -0800192 verbose_name = "vSG Service"
193 verbose_name_plural = "vSG Service"
Scott Baker27b768d2015-04-21 17:15:18 -0700194 list_display = ("backend_status_icon", "name", "enabled")
195 list_display_links = ('backend_status_icon', 'name', )
Scott Baker67074ab2016-03-04 11:29:02 -0800196 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "service_specific_attribute", "node_label"],
Scott Baker80157da2015-07-15 17:42:43 -0700197 'classes':['suit-tab suit-tab-general']}),
Scott Baker9b870572016-03-10 19:23:10 -0800198 ("backend config", {'fields': [ "backend_network_label", "url_filter_kind", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"],
Scott Bakerae6187c2016-02-23 14:58:49 -0800199 'classes':['suit-tab suit-tab-backend']}),
Scott Baker451050f2016-04-19 17:55:56 -0700200 ("vSG config", {'fields': ["dns_servers"],
Scott Bakerae6187c2016-02-23 14:58:49 -0800201 'classes':['suit-tab suit-tab-vsg']}) ]
Scott Baker62312972015-07-13 14:30:25 -0700202 readonly_fields = ('backend_status_text', "service_specific_attribute")
Scott Baker9da53042015-05-15 09:08:19 -0700203 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Bakerf91e6152016-02-11 12:07:10 -0800204 form = VSGServiceForm
Scott Baker27b768d2015-04-21 17:15:18 -0700205
206 extracontext_registered_admins = True
207
208 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
209
Scott Baker80157da2015-07-15 17:42:43 -0700210 suit_form_tabs =(('general', 'Service Details'),
211 ('backend', 'Backend Config'),
Scott Bakerae6187c2016-02-23 14:58:49 -0800212 ('vsg', 'vSG Config'),
Scott Baker27b768d2015-04-21 17:15:18 -0700213 ('administration', 'Administration'),
214 #('tools', 'Tools'),
215 ('slices','Slices'),
216 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -0700217 ('serviceprivileges','Privileges') ,
Scott Baker27b768d2015-04-21 17:15:18 -0700218 )
219
220 suit_form_includes = (('vcpeadmin.html', 'top', 'administration'),
221 ) #('hpctools.html', 'top', 'tools') )
222
223 def queryset(self, request):
Scott Bakerf91e6152016-02-11 12:07:10 -0800224 return VSGService.get_service_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700225
Scott Baker4c052b22016-02-11 11:08:42 -0800226class VSGTenantForm(forms.ModelForm):
Scott Baker80a39292015-07-21 18:18:25 -0700227 bbs_account = forms.CharField(required=False)
228 creator = forms.ModelChoiceField(queryset=User.objects.all())
Tony Mackd8515472015-08-19 11:58:18 -0400229 instance = forms.ModelChoiceField(queryset=Instance.objects.all(),required=False)
Scott Baker80a39292015-07-21 18:18:25 -0700230 last_ansible_hash = forms.CharField(required=False)
Scott Bakere6780e92016-02-13 14:38:43 -0800231 wan_container_ip = forms.CharField(required=False)
Scott Bakercf6eb992016-02-18 06:43:02 -0800232 wan_container_mac = forms.CharField(required=False)
Scott Baker80a39292015-07-21 18:18:25 -0700233
Sapan Bhatia16be1432016-01-14 11:41:38 -0500234 def __init__(self,*args,**kwargs):
Scott Baker4c052b22016-02-11 11:08:42 -0800235 super (VSGTenantForm,self ).__init__(*args,**kwargs)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500236 self.fields['kind'].widget.attrs['readonly'] = True
Scott Bakerf91e6152016-02-11 12:07:10 -0800237 self.fields['provider_service'].queryset = VSGService.get_service_objects().all()
Sapan Bhatia16be1432016-01-14 11:41:38 -0500238 if self.instance:
239 # fields for the attributes
240 self.fields['bbs_account'].initial = self.instance.bbs_account
241 self.fields['creator'].initial = self.instance.creator
242 self.fields['instance'].initial = self.instance.instance
243 self.fields['last_ansible_hash'].initial = self.instance.last_ansible_hash
Scott Bakere6780e92016-02-13 14:38:43 -0800244 self.fields['wan_container_ip'].initial = self.instance.wan_container_ip
Scott Bakercf6eb992016-02-18 06:43:02 -0800245 self.fields['wan_container_mac'].initial = self.instance.wan_container_mac
Sapan Bhatia16be1432016-01-14 11:41:38 -0500246 if (not self.instance) or (not self.instance.pk):
247 # default fields for an 'add' form
248 self.fields['kind'].initial = VCPE_KIND
249 self.fields['creator'].initial = get_request().user
Scott Bakerf91e6152016-02-11 12:07:10 -0800250 if VSGService.get_service_objects().exists():
251 self.fields["provider_service"].initial = VSGService.get_service_objects().all()[0]
Sapan Bhatia16be1432016-01-14 11:41:38 -0500252
253 def save(self, commit=True):
254 self.instance.creator = self.cleaned_data.get("creator")
255 self.instance.instance = self.cleaned_data.get("instance")
256 self.instance.last_ansible_hash = self.cleaned_data.get("last_ansible_hash")
Scott Baker4c052b22016-02-11 11:08:42 -0800257 return super(VSGTenantForm, self).save(commit=commit)
Sapan Bhatia16be1432016-01-14 11:41:38 -0500258
259 class Meta:
Scott Baker4c052b22016-02-11 11:08:42 -0800260 model = VSGTenant
Scott Baker27b768d2015-04-21 17:15:18 -0700261
Scott Baker4c052b22016-02-11 11:08:42 -0800262class VSGTenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerb3cf9212015-07-06 14:40:20 -0700263 list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
Scott Baker27b768d2015-04-21 17:15:18 -0700264 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -0700265 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute',
Scott Bakercf6eb992016-02-18 06:43:02 -0800266 'wan_container_ip', 'wan_container_mac', 'bbs_account', 'creator', 'instance', 'last_ansible_hash'],
Scott Baker80a39292015-07-21 18:18:25 -0700267 'classes':['suit-tab suit-tab-general']})]
Scott Bakercf6eb992016-02-18 06:43:02 -0800268 readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account', 'wan_container_ip', 'wan_container_mac')
Scott Baker4c052b22016-02-11 11:08:42 -0800269 form = VSGTenantForm
Scott Baker27b768d2015-04-21 17:15:18 -0700270
271 suit_form_tabs = (('general','Details'),)
272
273 def queryset(self, request):
Scott Baker4c052b22016-02-11 11:08:42 -0800274 return VSGTenant.get_tenant_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700275
276#-----------------------------------------------------------------------------
277# vBNG
278#-----------------------------------------------------------------------------
279
Scott Baker21d18932015-07-21 18:24:21 -0700280class VBNGServiceForm(forms.ModelForm):
281 vbng_url = forms.CharField(required=False)
282
Sapan Bhatia16be1432016-01-14 11:41:38 -0500283 def __init__(self,*args,**kwargs):
284 super (VBNGServiceForm,self ).__init__(*args,**kwargs)
285 if self.instance:
286 self.fields['vbng_url'].initial = self.instance.vbng_url
287
288 def save(self, commit=True):
289 self.instance.vbng_url = self.cleaned_data.get("vbng_url")
290 return super(VBNGServiceForm, self).save(commit=commit)
291
292 class Meta:
Scott Baker21d18932015-07-21 18:24:21 -0700293 model = VBNGService
294
Scott Baker27b768d2015-04-21 17:15:18 -0700295class VBNGServiceAdmin(ReadOnlyAwareAdmin):
296 model = VBNGService
297 verbose_name = "vBNG Service"
298 verbose_name_plural = "vBNG Service"
299 list_display = ("backend_status_icon", "name", "enabled")
300 list_display_links = ('backend_status_icon', 'name', )
Scott Baker21d18932015-07-21 18:24:21 -0700301 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url",
302 'vbng_url' ],
303 'classes':['suit-tab suit-tab-general']})]
Scott Baker27b768d2015-04-21 17:15:18 -0700304 readonly_fields = ('backend_status_text', )
Scott Baker9da53042015-05-15 09:08:19 -0700305 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Baker21d18932015-07-21 18:24:21 -0700306 form = VBNGServiceForm
Scott Baker27b768d2015-04-21 17:15:18 -0700307
308 extracontext_registered_admins = True
309
310 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
311
312 suit_form_tabs =(('general', 'vBNG Service Details'),
313 ('administration', 'Administration'),
314 #('tools', 'Tools'),
315 ('slices','Slices'),
316 ('serviceattrs','Additional Attributes'),
Scott Baker9da53042015-05-15 09:08:19 -0700317 ('serviceprivileges','Privileges'),
Scott Baker27b768d2015-04-21 17:15:18 -0700318 )
319
320 suit_form_includes = (('vbngadmin.html', 'top', 'administration'),
321 ) #('hpctools.html', 'top', 'tools') )
322
323 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700324 return VBNGService.get_service_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700325
326class VBNGTenantForm(forms.ModelForm):
Scott Baker80a39292015-07-21 18:18:25 -0700327 routeable_subnet = forms.CharField(required=False)
328 mapped_hostname = forms.CharField(required=False)
329 mapped_ip = forms.CharField(required=False)
330 mapped_mac = forms.CharField(required=False)
331
Sapan Bhatia16be1432016-01-14 11:41:38 -0500332 def __init__(self,*args,**kwargs):
333 super (VBNGTenantForm,self ).__init__(*args,**kwargs)
334 self.fields['kind'].widget.attrs['readonly'] = True
335 self.fields['provider_service'].queryset = VBNGService.get_service_objects().all()
336 if self.instance:
337 # fields for the attributes
338 self.fields['routeable_subnet'].initial = self.instance.routeable_subnet
339 self.fields['mapped_hostname'].initial = self.instance.mapped_hostname
340 self.fields['mapped_ip'].initial = self.instance.mapped_ip
341 self.fields['mapped_mac'].initial = self.instance.mapped_mac
342 if (not self.instance) or (not self.instance.pk):
343 # default fields for an 'add' form
344 self.fields['kind'].initial = VBNG_KIND
345 if VBNGService.get_service_objects().exists():
346 self.fields["provider_service"].initial = VBNGService.get_service_objects().all()[0]
347
348 def save(self, commit=True):
349 self.instance.routeable_subnet = self.cleaned_data.get("routeable_subnet")
350 self.instance.mapped_hostname = self.cleaned_data.get("mapped_hostname")
351 self.instance.mapped_ip = self.cleaned_data.get("mapped_ip")
352 self.instance.mapped_mac = self.cleaned_data.get("mapped_mac")
353 return super(VBNGTenantForm, self).save(commit=commit)
354
355 class Meta:
Scott Baker27b768d2015-04-21 17:15:18 -0700356 model = VBNGTenant
357
358class VBNGTenantAdmin(ReadOnlyAwareAdmin):
Scott Bakerb3cf9212015-07-06 14:40:20 -0700359 list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
Scott Baker27b768d2015-04-21 17:15:18 -0700360 list_display_links = ('backend_status_icon', 'id')
Scott Baker80a39292015-07-21 18:18:25 -0700361 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute',
362 'routeable_subnet', 'mapped_hostname', 'mapped_ip', 'mapped_mac'],
363 'classes':['suit-tab suit-tab-general']})]
364 readonly_fields = ('backend_status_text', 'service_specific_attribute')
Scott Baker27b768d2015-04-21 17:15:18 -0700365 form = VBNGTenantForm
366
367 suit_form_tabs = (('general','Details'),)
368
369 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700370 return VBNGTenant.get_tenant_objects_by_user(request.user)
Scott Baker27b768d2015-04-21 17:15:18 -0700371
Scott Baker6dddd2f2015-07-23 12:06:26 -0700372#-----------------------------------------------------------------------------
373# CordSubscriberRoot
374#-----------------------------------------------------------------------------
375
Scott Baker4124e962015-07-24 10:15:01 -0700376class VOLTTenantInline(XOSTabularInline):
377 model = VOLTTenant
378 fields = ['provider_service', 'subscriber_root', 'service_specific_id']
379 readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id']
380 extra = 0
381 max_num = 0
382 suit_classes = 'suit-tab suit-tab-volttenants'
383 fk_name = 'subscriber_root'
384 verbose_name = 'subscribed tenant'
385 verbose_name_plural = 'subscribed tenants'
386
387 @property
388 def selflink_reverse_path(self):
389 return "admin:cord_volttenant_change"
390
391 def queryset(self, request):
392 qs = super(VOLTTenantInline, self).queryset(request)
393 return qs.filter(kind=VOLT_KIND)
394
Scott Baker6dddd2f2015-07-23 12:06:26 -0700395class CordSubscriberRootForm(forms.ModelForm):
396 url_filter_level = forms.CharField(required = False)
Scott Baker669212f2016-03-01 20:14:35 -0800397 uplink_speed = forms.CharField(required = False)
398 downlink_speed = forms.CharField(required = False)
399 status = forms.ChoiceField(choices=CordSubscriberRoot.status_choices, required=True)
400 enable_uverse = forms.BooleanField(required=False)
Scott Bakerd0447e52016-03-09 12:44:07 -0800401 cdn_enable = forms.BooleanField(required=False)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700402
Sapan Bhatia16be1432016-01-14 11:41:38 -0500403 def __init__(self,*args,**kwargs):
404 super (CordSubscriberRootForm,self ).__init__(*args,**kwargs)
405 self.fields['kind'].widget.attrs['readonly'] = True
406 if self.instance:
407 self.fields['url_filter_level'].initial = self.instance.url_filter_level
Scott Baker669212f2016-03-01 20:14:35 -0800408 self.fields['uplink_speed'].initial = self.instance.uplink_speed
409 self.fields['downlink_speed'].initial = self.instance.downlink_speed
410 self.fields['status'].initial = self.instance.status
411 self.fields['enable_uverse'].initial = self.instance.enable_uverse
Scott Bakerd0447e52016-03-09 12:44:07 -0800412 self.fields['cdn_enable'].initial = self.instance.cdn_enable
Sapan Bhatia16be1432016-01-14 11:41:38 -0500413 if (not self.instance) or (not self.instance.pk):
414 # default fields for an 'add' form
415 self.fields['kind'].initial = CORD_SUBSCRIBER_KIND
Scott Baker669212f2016-03-01 20:14:35 -0800416 self.fields['uplink_speed'].initial = CordSubscriberRoot.get_default_attribute("uplink_speed")
417 self.fields['downlink_speed'].initial = CordSubscriberRoot.get_default_attribute("downlink_speed")
418 self.fields['status'].initial = CordSubscriberRoot.get_default_attribute("status")
419 self.fields['enable_uverse'].initial = CordSubscriberRoot.get_default_attribute("enable_uverse")
Scott Bakerd0447e52016-03-09 12:44:07 -0800420 self.fields['cdn_enable'].initial = CordSubscriberRoot.get_default_attribute("cdn_enable")
Sapan Bhatia16be1432016-01-14 11:41:38 -0500421
422 def save(self, commit=True):
423 self.instance.url_filter_level = self.cleaned_data.get("url_filter_level")
Scott Baker669212f2016-03-01 20:14:35 -0800424 self.instance.uplink_speed = self.cleaned_data.get("uplink_speed")
425 self.instance.downlink_speed = self.cleaned_data.get("downlink_speed")
426 self.instance.status = self.cleaned_data.get("status")
427 self.instance.enable_uverse = self.cleaned_data.get("enable_uverse")
Scott Bakerd0447e52016-03-09 12:44:07 -0800428 self.instance.cdn_enable = self.cleaned_data.get("cdn_enable")
Sapan Bhatia16be1432016-01-14 11:41:38 -0500429 return super(CordSubscriberRootForm, self).save(commit=commit)
430
431 class Meta:
Scott Baker6dddd2f2015-07-23 12:06:26 -0700432 model = CordSubscriberRoot
433
434class CordSubscriberRootAdmin(ReadOnlyAwareAdmin):
435 list_display = ('backend_status_icon', 'id', 'name', )
436 list_display_links = ('backend_status_icon', 'id', 'name', )
437 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute',
Scott Bakerd0447e52016-03-09 12:44:07 -0800438 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse", "cdn_enable"],
Scott Baker6dddd2f2015-07-23 12:06:26 -0700439 'classes':['suit-tab suit-tab-general']})]
Scott Baker669212f2016-03-01 20:14:35 -0800440 readonly_fields = ('backend_status_text', 'service_specific_attribute',)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700441 form = CordSubscriberRootForm
Scott Baker4124e962015-07-24 10:15:01 -0700442 inlines = (VOLTTenantInline, TenantRootPrivilegeInline)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700443
444 suit_form_tabs =(('general', 'Cord Subscriber Root Details'),
Scott Baker4124e962015-07-24 10:15:01 -0700445 ('volttenants','VOLT Tenancy'),
Scott Baker6dddd2f2015-07-23 12:06:26 -0700446 ('tenantrootprivileges','Privileges')
447 )
448
449 def queryset(self, request):
Scott Baker27de6012015-07-24 15:36:02 -0700450 return CordSubscriberRoot.get_tenant_objects_by_user(request.user)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700451
Scott Bakerbb2a2a22015-04-21 16:59:04 -0700452admin.site.register(VOLTService, VOLTServiceAdmin)
453admin.site.register(VOLTTenant, VOLTTenantAdmin)
Scott Baker27b36bc2016-05-23 20:57:00 -0700454admin.site.register(VOLTDevice, VOLTDeviceAdmin)
455admin.site.register(AccessDevice, AccessDeviceAdmin)
456admin.site.register(AccessAgent, AccessAgentAdmin)
457
Scott Bakerf91e6152016-02-11 12:07:10 -0800458admin.site.register(VSGService, VSGServiceAdmin)
Scott Baker4c052b22016-02-11 11:08:42 -0800459admin.site.register(VSGTenant, VSGTenantAdmin)
Scott Baker27b768d2015-04-21 17:15:18 -0700460admin.site.register(VBNGService, VBNGServiceAdmin)
461admin.site.register(VBNGTenant, VBNGTenantAdmin)
Scott Baker6dddd2f2015-07-23 12:06:26 -0700462admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin)
Scott Bakerbb2a2a22015-04-21 16:59:04 -0700463