Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
Scott Baker | e01ee76 | 2015-12-31 10:18:28 -0800 | [diff] [blame] | 3 | from services.cord.models import * |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 4 | from django import forms |
| 5 | from django.utils.safestring import mark_safe |
| 6 | from django.contrib.auth.admin import UserAdmin |
| 7 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 8 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 9 | from django.contrib.auth.signals import user_logged_in |
| 10 | from django.utils import timezone |
| 11 | from django.contrib.contenttypes import generic |
| 12 | from suit.widgets import LinkedSelect |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 13 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline |
Scott Baker | b2f5efe | 2015-09-10 16:01:58 -0700 | [diff] [blame] | 14 | from core.middleware import get_request |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 15 | |
| 16 | from functools import update_wrapper |
| 17 | from django.contrib.admin.views.main import ChangeList |
| 18 | from django.core.urlresolvers import reverse |
| 19 | from django.contrib.admin.utils import quote |
| 20 | |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 21 | #----------------------------------------------------------------------------- |
| 22 | # vOLT |
| 23 | #----------------------------------------------------------------------------- |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 24 | |
| 25 | class 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 Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 31 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 32 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 33 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 34 | |
| 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 Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 44 | ('serviceprivileges','Privileges'), |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 45 | ) |
| 46 | |
| 47 | suit_form_includes = (('voltadmin.html', 'top', 'administration'), |
| 48 | ) #('hpctools.html', 'top', 'tools') ) |
| 49 | |
| 50 | def queryset(self, request): |
Scott Baker | 16573d3 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 51 | return VOLTService.get_service_objects_by_user(request.user) |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 52 | |
| 53 | class VOLTTenantForm(forms.ModelForm): |
Scott Baker | 89a338c | 2015-11-09 20:25:21 -0800 | [diff] [blame] | 54 | s_tag = forms.CharField() |
| 55 | c_tag = forms.CharField() |
Scott Baker | 800f9c1 | 2015-07-13 13:08:07 -0700 | [diff] [blame] | 56 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
| 57 | |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 58 | 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 Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 81 | model = VOLTTenant |
| 82 | |
| 83 | class VOLTTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 89a338c | 2015-11-09 20:25:21 -0800 | [diff] [blame] | 84 | list_display = ('backend_status_icon', 'id', 'service_specific_id', 's_tag', 'c_tag', 'subscriber_root' ) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 85 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 86 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_root', 'service_specific_id', # 'service_specific_attribute', |
Scott Baker | 89a338c | 2015-11-09 20:25:21 -0800 | [diff] [blame] | 87 | 's_tag', 'c_tag', 'creator'], |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 88 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 800f9c1 | 2015-07-13 13:08:07 -0700 | [diff] [blame] | 89 | readonly_fields = ('backend_status_text', 'service_specific_attribute') |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 90 | form = VOLTTenantForm |
| 91 | |
| 92 | suit_form_tabs = (('general','Details'),) |
| 93 | |
| 94 | def queryset(self, request): |
Scott Baker | 16573d3 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 95 | return VOLTTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 96 | |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 97 | #----------------------------------------------------------------------------- |
| 98 | # vCPE |
| 99 | #----------------------------------------------------------------------------- |
| 100 | |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 101 | class VSGServiceForm(forms.ModelForm): |
Scott Baker | a0886fb | 2015-07-15 18:08:06 -0700 | [diff] [blame] | 102 | bbs_api_hostname = forms.CharField(required=False) |
| 103 | bbs_api_port = forms.IntegerField(required=False) |
Scott Baker | 3d2493b | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 104 | bbs_server = forms.CharField(required=False) |
| 105 | backend_network_label = forms.CharField(required=False) |
| 106 | bbs_slice = forms.ModelChoiceField(queryset=Slice.objects.all(), required=False) |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 107 | wan_container_gateway_ip = forms.CharField(required=False) |
| 108 | wan_container_gateway_mac = forms.CharField(required=False) |
| 109 | wan_container_netbits = forms.CharField(required=False) |
Scott Baker | 7ba272e | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 110 | |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 111 | def __init__(self,*args,**kwargs): |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 112 | super (VSGServiceForm,self ).__init__(*args,**kwargs) |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 113 | if self.instance: |
| 114 | self.fields['bbs_api_hostname'].initial = self.instance.bbs_api_hostname |
| 115 | self.fields['bbs_api_port'].initial = self.instance.bbs_api_port |
| 116 | self.fields['bbs_server'].initial = self.instance.bbs_server |
| 117 | self.fields['backend_network_label'].initial = self.instance.backend_network_label |
| 118 | self.fields['bbs_slice'].initial = self.instance.bbs_slice |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 119 | self.fields['wan_container_gateway_ip'].initial = self.instance.wan_container_gateway_ip |
| 120 | self.fields['wan_container_gateway_mac'].initial = self.instance.wan_container_gateway_mac |
| 121 | self.fields['wan_container_netbits'].initial = self.instance.wan_container_netbits |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 122 | |
| 123 | def save(self, commit=True): |
| 124 | self.instance.bbs_api_hostname = self.cleaned_data.get("bbs_api_hostname") |
| 125 | self.instance.bbs_api_port = self.cleaned_data.get("bbs_api_port") |
| 126 | self.instance.bbs_server = self.cleaned_data.get("bbs_server") |
| 127 | self.instance.backend_network_label = self.cleaned_data.get("backend_network_label") |
| 128 | self.instance.bbs_slice = self.cleaned_data.get("bbs_slice") |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 129 | self.instance.wan_container_gateway_ip = self.cleaned_data.get("wan_container_gateway_ip") |
| 130 | self.instance.wan_container_gateway_mac = self.cleaned_data.get("wan_container_gateway_mac") |
| 131 | self.instance.wan_container_netbits = self.cleaned_data.get("wan_container_netbits") |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 132 | return super(VSGServiceForm, self).save(commit=commit) |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 133 | |
| 134 | class Meta: |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 135 | model = VSGService |
Scott Baker | 7ba272e | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 136 | |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 137 | class VSGServiceAdmin(ReadOnlyAwareAdmin): |
| 138 | model = VSGService |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 139 | verbose_name = "vCPE Service" |
| 140 | verbose_name_plural = "vCPE Service" |
| 141 | list_display = ("backend_status_icon", "name", "enabled") |
| 142 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 3d2493b | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 143 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "service_specific_attribute",], |
| 144 | 'classes':['suit-tab suit-tab-general']}), |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 145 | ("backend config", {'fields': [ "backend_network_label", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice", "wan_container_gateway_ip", "wan_container_gateway_mac", "wan_container_netbits"], |
Scott Baker | 3d2493b | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 146 | 'classes':['suit-tab suit-tab-backend']}) ] |
Scott Baker | 7ba272e | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 147 | readonly_fields = ('backend_status_text', "service_specific_attribute") |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 148 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 149 | form = VSGServiceForm |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 150 | |
| 151 | extracontext_registered_admins = True |
| 152 | |
| 153 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 154 | |
Scott Baker | 3d2493b | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 155 | suit_form_tabs =(('general', 'Service Details'), |
| 156 | ('backend', 'Backend Config'), |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 157 | ('administration', 'Administration'), |
| 158 | #('tools', 'Tools'), |
| 159 | ('slices','Slices'), |
| 160 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 161 | ('serviceprivileges','Privileges') , |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 162 | ) |
| 163 | |
| 164 | suit_form_includes = (('vcpeadmin.html', 'top', 'administration'), |
| 165 | ) #('hpctools.html', 'top', 'tools') ) |
| 166 | |
| 167 | def queryset(self, request): |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 168 | return VSGService.get_service_objects_by_user(request.user) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 169 | |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 170 | class VSGTenantForm(forms.ModelForm): |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 171 | bbs_account = forms.CharField(required=False) |
| 172 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 173 | instance = forms.ModelChoiceField(queryset=Instance.objects.all(),required=False) |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 174 | last_ansible_hash = forms.CharField(required=False) |
Scott Baker | 27fab49 | 2016-02-13 14:38:43 -0800 | [diff] [blame] | 175 | wan_container_ip = forms.CharField(required=False) |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 176 | wan_container_mac = forms.CharField(required=False) |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 177 | |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 178 | def __init__(self,*args,**kwargs): |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 179 | super (VSGTenantForm,self ).__init__(*args,**kwargs) |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 180 | self.fields['kind'].widget.attrs['readonly'] = True |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 181 | self.fields['provider_service'].queryset = VSGService.get_service_objects().all() |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 182 | if self.instance: |
| 183 | # fields for the attributes |
| 184 | self.fields['bbs_account'].initial = self.instance.bbs_account |
| 185 | self.fields['creator'].initial = self.instance.creator |
| 186 | self.fields['instance'].initial = self.instance.instance |
| 187 | self.fields['last_ansible_hash'].initial = self.instance.last_ansible_hash |
Scott Baker | 27fab49 | 2016-02-13 14:38:43 -0800 | [diff] [blame] | 188 | self.fields['wan_container_ip'].initial = self.instance.wan_container_ip |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 189 | self.fields['wan_container_mac'].initial = self.instance.wan_container_mac |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 190 | if (not self.instance) or (not self.instance.pk): |
| 191 | # default fields for an 'add' form |
| 192 | self.fields['kind'].initial = VCPE_KIND |
| 193 | self.fields['creator'].initial = get_request().user |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 194 | if VSGService.get_service_objects().exists(): |
| 195 | self.fields["provider_service"].initial = VSGService.get_service_objects().all()[0] |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 196 | |
| 197 | def save(self, commit=True): |
| 198 | self.instance.creator = self.cleaned_data.get("creator") |
| 199 | self.instance.instance = self.cleaned_data.get("instance") |
| 200 | self.instance.last_ansible_hash = self.cleaned_data.get("last_ansible_hash") |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 201 | return super(VSGTenantForm, self).save(commit=commit) |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 202 | |
| 203 | class Meta: |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 204 | model = VSGTenant |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 205 | |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 206 | class VSGTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 207 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 208 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 209 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute', |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 210 | 'wan_container_ip', 'wan_container_mac', 'bbs_account', 'creator', 'instance', 'last_ansible_hash'], |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 211 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 4d3cc75 | 2016-02-18 06:43:02 -0800 | [diff] [blame^] | 212 | readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account', 'wan_container_ip', 'wan_container_mac') |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 213 | form = VSGTenantForm |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 214 | |
| 215 | suit_form_tabs = (('general','Details'),) |
| 216 | |
| 217 | def queryset(self, request): |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 218 | return VSGTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 219 | |
| 220 | #----------------------------------------------------------------------------- |
| 221 | # vBNG |
| 222 | #----------------------------------------------------------------------------- |
| 223 | |
Scott Baker | 3d7ec1a | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 224 | class VBNGServiceForm(forms.ModelForm): |
| 225 | vbng_url = forms.CharField(required=False) |
| 226 | |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 227 | def __init__(self,*args,**kwargs): |
| 228 | super (VBNGServiceForm,self ).__init__(*args,**kwargs) |
| 229 | if self.instance: |
| 230 | self.fields['vbng_url'].initial = self.instance.vbng_url |
| 231 | |
| 232 | def save(self, commit=True): |
| 233 | self.instance.vbng_url = self.cleaned_data.get("vbng_url") |
| 234 | return super(VBNGServiceForm, self).save(commit=commit) |
| 235 | |
| 236 | class Meta: |
Scott Baker | 3d7ec1a | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 237 | model = VBNGService |
| 238 | |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 239 | class VBNGServiceAdmin(ReadOnlyAwareAdmin): |
| 240 | model = VBNGService |
| 241 | verbose_name = "vBNG Service" |
| 242 | verbose_name_plural = "vBNG Service" |
| 243 | list_display = ("backend_status_icon", "name", "enabled") |
| 244 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 3d7ec1a | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 245 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", |
| 246 | 'vbng_url' ], |
| 247 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 248 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 249 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 3d7ec1a | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 250 | form = VBNGServiceForm |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 251 | |
| 252 | extracontext_registered_admins = True |
| 253 | |
| 254 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 255 | |
| 256 | suit_form_tabs =(('general', 'vBNG Service Details'), |
| 257 | ('administration', 'Administration'), |
| 258 | #('tools', 'Tools'), |
| 259 | ('slices','Slices'), |
| 260 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 559be72 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 261 | ('serviceprivileges','Privileges'), |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 262 | ) |
| 263 | |
| 264 | suit_form_includes = (('vbngadmin.html', 'top', 'administration'), |
| 265 | ) #('hpctools.html', 'top', 'tools') ) |
| 266 | |
| 267 | def queryset(self, request): |
Scott Baker | 16573d3 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 268 | return VBNGService.get_service_objects_by_user(request.user) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 269 | |
| 270 | class VBNGTenantForm(forms.ModelForm): |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 271 | routeable_subnet = forms.CharField(required=False) |
| 272 | mapped_hostname = forms.CharField(required=False) |
| 273 | mapped_ip = forms.CharField(required=False) |
| 274 | mapped_mac = forms.CharField(required=False) |
| 275 | |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 276 | def __init__(self,*args,**kwargs): |
| 277 | super (VBNGTenantForm,self ).__init__(*args,**kwargs) |
| 278 | self.fields['kind'].widget.attrs['readonly'] = True |
| 279 | self.fields['provider_service'].queryset = VBNGService.get_service_objects().all() |
| 280 | if self.instance: |
| 281 | # fields for the attributes |
| 282 | self.fields['routeable_subnet'].initial = self.instance.routeable_subnet |
| 283 | self.fields['mapped_hostname'].initial = self.instance.mapped_hostname |
| 284 | self.fields['mapped_ip'].initial = self.instance.mapped_ip |
| 285 | self.fields['mapped_mac'].initial = self.instance.mapped_mac |
| 286 | if (not self.instance) or (not self.instance.pk): |
| 287 | # default fields for an 'add' form |
| 288 | self.fields['kind'].initial = VBNG_KIND |
| 289 | if VBNGService.get_service_objects().exists(): |
| 290 | self.fields["provider_service"].initial = VBNGService.get_service_objects().all()[0] |
| 291 | |
| 292 | def save(self, commit=True): |
| 293 | self.instance.routeable_subnet = self.cleaned_data.get("routeable_subnet") |
| 294 | self.instance.mapped_hostname = self.cleaned_data.get("mapped_hostname") |
| 295 | self.instance.mapped_ip = self.cleaned_data.get("mapped_ip") |
| 296 | self.instance.mapped_mac = self.cleaned_data.get("mapped_mac") |
| 297 | return super(VBNGTenantForm, self).save(commit=commit) |
| 298 | |
| 299 | class Meta: |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 300 | model = VBNGTenant |
| 301 | |
| 302 | class VBNGTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 303 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 304 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | bb482ae | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 305 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute', |
| 306 | 'routeable_subnet', 'mapped_hostname', 'mapped_ip', 'mapped_mac'], |
| 307 | 'classes':['suit-tab suit-tab-general']})] |
| 308 | readonly_fields = ('backend_status_text', 'service_specific_attribute') |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 309 | form = VBNGTenantForm |
| 310 | |
| 311 | suit_form_tabs = (('general','Details'),) |
| 312 | |
| 313 | def queryset(self, request): |
Scott Baker | 16573d3 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 314 | return VBNGTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 315 | |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 316 | #----------------------------------------------------------------------------- |
| 317 | # CordSubscriberRoot |
| 318 | #----------------------------------------------------------------------------- |
| 319 | |
Scott Baker | ab12310 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 320 | class VOLTTenantInline(XOSTabularInline): |
| 321 | model = VOLTTenant |
| 322 | fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 323 | readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 324 | extra = 0 |
| 325 | max_num = 0 |
| 326 | suit_classes = 'suit-tab suit-tab-volttenants' |
| 327 | fk_name = 'subscriber_root' |
| 328 | verbose_name = 'subscribed tenant' |
| 329 | verbose_name_plural = 'subscribed tenants' |
| 330 | |
| 331 | @property |
| 332 | def selflink_reverse_path(self): |
| 333 | return "admin:cord_volttenant_change" |
| 334 | |
| 335 | def queryset(self, request): |
| 336 | qs = super(VOLTTenantInline, self).queryset(request) |
| 337 | return qs.filter(kind=VOLT_KIND) |
| 338 | |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 339 | class CordSubscriberRootForm(forms.ModelForm): |
| 340 | url_filter_level = forms.CharField(required = False) |
| 341 | |
Sapan Bhatia | 67ea0d7 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 342 | def __init__(self,*args,**kwargs): |
| 343 | super (CordSubscriberRootForm,self ).__init__(*args,**kwargs) |
| 344 | self.fields['kind'].widget.attrs['readonly'] = True |
| 345 | if self.instance: |
| 346 | self.fields['url_filter_level'].initial = self.instance.url_filter_level |
| 347 | if (not self.instance) or (not self.instance.pk): |
| 348 | # default fields for an 'add' form |
| 349 | self.fields['kind'].initial = CORD_SUBSCRIBER_KIND |
| 350 | |
| 351 | def save(self, commit=True): |
| 352 | self.instance.url_filter_level = self.cleaned_data.get("url_filter_level") |
| 353 | return super(CordSubscriberRootForm, self).save(commit=commit) |
| 354 | |
| 355 | class Meta: |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 356 | model = CordSubscriberRoot |
| 357 | |
| 358 | class CordSubscriberRootAdmin(ReadOnlyAwareAdmin): |
| 359 | list_display = ('backend_status_icon', 'id', 'name', ) |
| 360 | list_display_links = ('backend_status_icon', 'id', 'name', ) |
| 361 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute', |
| 362 | 'url_filter_level'], |
| 363 | 'classes':['suit-tab suit-tab-general']})] |
| 364 | readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account') |
| 365 | form = CordSubscriberRootForm |
Scott Baker | ab12310 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 366 | inlines = (VOLTTenantInline, TenantRootPrivilegeInline) |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 367 | |
| 368 | suit_form_tabs =(('general', 'Cord Subscriber Root Details'), |
Scott Baker | ab12310 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 369 | ('volttenants','VOLT Tenancy'), |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 370 | ('tenantrootprivileges','Privileges') |
| 371 | ) |
| 372 | |
| 373 | def queryset(self, request): |
Scott Baker | 16573d3 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 374 | return CordSubscriberRoot.get_tenant_objects_by_user(request.user) |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 375 | |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 376 | admin.site.register(VOLTService, VOLTServiceAdmin) |
| 377 | admin.site.register(VOLTTenant, VOLTTenantAdmin) |
Scott Baker | 4698b92 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 378 | admin.site.register(VSGService, VSGServiceAdmin) |
Scott Baker | 664bbe5 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 379 | admin.site.register(VSGTenant, VSGTenantAdmin) |
Scott Baker | 932a16c | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 380 | admin.site.register(VBNGService, VBNGServiceAdmin) |
| 381 | admin.site.register(VBNGTenant, VBNGTenantAdmin) |
Scott Baker | 527326e | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 382 | admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin) |
Scott Baker | 2986b1e | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 383 | |