Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
Scott Baker | 98f5155 | 2015-12-31 10:18:28 -0800 | [diff] [blame] | 3 | from services.cord.models import * |
Scott Baker | bb2a2a2 | 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 | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 13 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline |
Scott Baker | d145efe | 2015-09-10 16:01:58 -0700 | [diff] [blame] | 14 | from core.middleware import get_request |
Scott Baker | bb2a2a2 | 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 | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 21 | #----------------------------------------------------------------------------- |
| 22 | # vOLT |
| 23 | #----------------------------------------------------------------------------- |
Scott Baker | bb2a2a2 | 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 | 27b768d | 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 | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 32 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 33 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | bb2a2a2 | 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 | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 44 | ('serviceprivileges','Privileges'), |
Scott Baker | bb2a2a2 | 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 | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 51 | return VOLTService.get_service_objects_by_user(request.user) |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 52 | |
| 53 | class VOLTTenantForm(forms.ModelForm): |
Scott Baker | f1527cd | 2015-11-09 20:25:21 -0800 | [diff] [blame] | 54 | s_tag = forms.CharField() |
| 55 | c_tag = forms.CharField() |
Scott Baker | eefe65c | 2015-07-13 13:08:07 -0700 | [diff] [blame] | 56 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
| 57 | |
Sapan Bhatia | 16be143 | 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 | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 81 | model = VOLTTenant |
| 82 | |
| 83 | class VOLTTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | f1527cd | 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 | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 85 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 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 | f1527cd | 2015-11-09 20:25:21 -0800 | [diff] [blame] | 87 | 's_tag', 'c_tag', 'creator'], |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 88 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | eefe65c | 2015-07-13 13:08:07 -0700 | [diff] [blame] | 89 | readonly_fields = ('backend_status_text', 'service_specific_attribute') |
Scott Baker | bb2a2a2 | 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 | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 95 | return VOLTTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 96 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 97 | #----------------------------------------------------------------------------- |
| 98 | # vCPE |
| 99 | #----------------------------------------------------------------------------- |
| 100 | |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 101 | class VSGServiceForm(forms.ModelForm): |
Scott Baker | 2b56cf4 | 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 | 80157da | 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 | cf6eb99 | 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 | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 110 | dns_servers = forms.CharField(required=False) |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 111 | node_label = forms.CharField(required=False) |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 112 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 113 | def __init__(self,*args,**kwargs): |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 114 | super (VSGServiceForm,self ).__init__(*args,**kwargs) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 115 | if self.instance: |
| 116 | self.fields['bbs_api_hostname'].initial = self.instance.bbs_api_hostname |
| 117 | self.fields['bbs_api_port'].initial = self.instance.bbs_api_port |
| 118 | self.fields['bbs_server'].initial = self.instance.bbs_server |
| 119 | self.fields['backend_network_label'].initial = self.instance.backend_network_label |
| 120 | self.fields['bbs_slice'].initial = self.instance.bbs_slice |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 121 | self.fields['wan_container_gateway_ip'].initial = self.instance.wan_container_gateway_ip |
| 122 | self.fields['wan_container_gateway_mac'].initial = self.instance.wan_container_gateway_mac |
| 123 | self.fields['wan_container_netbits'].initial = self.instance.wan_container_netbits |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 124 | self.fields['dns_servers'].initial = self.instance.dns_servers |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 125 | self.fields['node_label'].initial = self.instance.node_label |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 126 | |
| 127 | def save(self, commit=True): |
| 128 | self.instance.bbs_api_hostname = self.cleaned_data.get("bbs_api_hostname") |
| 129 | self.instance.bbs_api_port = self.cleaned_data.get("bbs_api_port") |
| 130 | self.instance.bbs_server = self.cleaned_data.get("bbs_server") |
| 131 | self.instance.backend_network_label = self.cleaned_data.get("backend_network_label") |
| 132 | self.instance.bbs_slice = self.cleaned_data.get("bbs_slice") |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 133 | self.instance.wan_container_gateway_ip = self.cleaned_data.get("wan_container_gateway_ip") |
| 134 | self.instance.wan_container_gateway_mac = self.cleaned_data.get("wan_container_gateway_mac") |
| 135 | self.instance.wan_container_netbits = self.cleaned_data.get("wan_container_netbits") |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 136 | self.instance.dns_servers = self.cleaned_data.get("dns_servers") |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 137 | self.instance.node_label = self.cleaned_data.get("node_label") |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 138 | return super(VSGServiceForm, self).save(commit=commit) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 139 | |
| 140 | class Meta: |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 141 | model = VSGService |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 142 | |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 143 | class VSGServiceAdmin(ReadOnlyAwareAdmin): |
| 144 | model = VSGService |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 145 | verbose_name = "vSG Service" |
| 146 | verbose_name_plural = "vSG Service" |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 147 | list_display = ("backend_status_icon", "name", "enabled") |
| 148 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 149 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "service_specific_attribute", "node_label"], |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 150 | 'classes':['suit-tab suit-tab-general']}), |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 151 | ("backend config", {'fields': [ "backend_network_label", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"], |
| 152 | 'classes':['suit-tab suit-tab-backend']}), |
| 153 | ("vSG config", {'fields': [ "wan_container_gateway_ip", "wan_container_gateway_mac", "wan_container_netbits", "dns_servers"], |
| 154 | 'classes':['suit-tab suit-tab-vsg']}) ] |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 155 | readonly_fields = ('backend_status_text', "service_specific_attribute") |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 156 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 157 | form = VSGServiceForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 158 | |
| 159 | extracontext_registered_admins = True |
| 160 | |
| 161 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 162 | |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 163 | suit_form_tabs =(('general', 'Service Details'), |
| 164 | ('backend', 'Backend Config'), |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 165 | ('vsg', 'vSG Config'), |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 166 | ('administration', 'Administration'), |
| 167 | #('tools', 'Tools'), |
| 168 | ('slices','Slices'), |
| 169 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 170 | ('serviceprivileges','Privileges') , |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 171 | ) |
| 172 | |
| 173 | suit_form_includes = (('vcpeadmin.html', 'top', 'administration'), |
| 174 | ) #('hpctools.html', 'top', 'tools') ) |
| 175 | |
| 176 | def queryset(self, request): |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 177 | return VSGService.get_service_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 178 | |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 179 | class VSGTenantForm(forms.ModelForm): |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 180 | bbs_account = forms.CharField(required=False) |
| 181 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
Tony Mack | d851547 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 182 | instance = forms.ModelChoiceField(queryset=Instance.objects.all(),required=False) |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 183 | last_ansible_hash = forms.CharField(required=False) |
Scott Baker | e6780e9 | 2016-02-13 14:38:43 -0800 | [diff] [blame] | 184 | wan_container_ip = forms.CharField(required=False) |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 185 | wan_container_mac = forms.CharField(required=False) |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 186 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 187 | def __init__(self,*args,**kwargs): |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 188 | super (VSGTenantForm,self ).__init__(*args,**kwargs) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 189 | self.fields['kind'].widget.attrs['readonly'] = True |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 190 | self.fields['provider_service'].queryset = VSGService.get_service_objects().all() |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 191 | if self.instance: |
| 192 | # fields for the attributes |
| 193 | self.fields['bbs_account'].initial = self.instance.bbs_account |
| 194 | self.fields['creator'].initial = self.instance.creator |
| 195 | self.fields['instance'].initial = self.instance.instance |
| 196 | self.fields['last_ansible_hash'].initial = self.instance.last_ansible_hash |
Scott Baker | e6780e9 | 2016-02-13 14:38:43 -0800 | [diff] [blame] | 197 | self.fields['wan_container_ip'].initial = self.instance.wan_container_ip |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 198 | self.fields['wan_container_mac'].initial = self.instance.wan_container_mac |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 199 | if (not self.instance) or (not self.instance.pk): |
| 200 | # default fields for an 'add' form |
| 201 | self.fields['kind'].initial = VCPE_KIND |
| 202 | self.fields['creator'].initial = get_request().user |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 203 | if VSGService.get_service_objects().exists(): |
| 204 | self.fields["provider_service"].initial = VSGService.get_service_objects().all()[0] |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 205 | |
| 206 | def save(self, commit=True): |
| 207 | self.instance.creator = self.cleaned_data.get("creator") |
| 208 | self.instance.instance = self.cleaned_data.get("instance") |
| 209 | self.instance.last_ansible_hash = self.cleaned_data.get("last_ansible_hash") |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 210 | return super(VSGTenantForm, self).save(commit=commit) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 211 | |
| 212 | class Meta: |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 213 | model = VSGTenant |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 214 | |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 215 | class VSGTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | b3cf921 | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 216 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 217 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 218 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute', |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 219 | 'wan_container_ip', 'wan_container_mac', 'bbs_account', 'creator', 'instance', 'last_ansible_hash'], |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 220 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 221 | readonly_fields = ('backend_status_text', 'service_specific_attribute', 'bbs_account', 'wan_container_ip', 'wan_container_mac') |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 222 | form = VSGTenantForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 223 | |
| 224 | suit_form_tabs = (('general','Details'),) |
| 225 | |
| 226 | def queryset(self, request): |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 227 | return VSGTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 228 | |
| 229 | #----------------------------------------------------------------------------- |
| 230 | # vBNG |
| 231 | #----------------------------------------------------------------------------- |
| 232 | |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 233 | class VBNGServiceForm(forms.ModelForm): |
| 234 | vbng_url = forms.CharField(required=False) |
| 235 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 236 | def __init__(self,*args,**kwargs): |
| 237 | super (VBNGServiceForm,self ).__init__(*args,**kwargs) |
| 238 | if self.instance: |
| 239 | self.fields['vbng_url'].initial = self.instance.vbng_url |
| 240 | |
| 241 | def save(self, commit=True): |
| 242 | self.instance.vbng_url = self.cleaned_data.get("vbng_url") |
| 243 | return super(VBNGServiceForm, self).save(commit=commit) |
| 244 | |
| 245 | class Meta: |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 246 | model = VBNGService |
| 247 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 248 | class VBNGServiceAdmin(ReadOnlyAwareAdmin): |
| 249 | model = VBNGService |
| 250 | verbose_name = "vBNG Service" |
| 251 | verbose_name_plural = "vBNG Service" |
| 252 | list_display = ("backend_status_icon", "name", "enabled") |
| 253 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 254 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", |
| 255 | 'vbng_url' ], |
| 256 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 257 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 258 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 259 | form = VBNGServiceForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 260 | |
| 261 | extracontext_registered_admins = True |
| 262 | |
| 263 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 264 | |
| 265 | suit_form_tabs =(('general', 'vBNG Service Details'), |
| 266 | ('administration', 'Administration'), |
| 267 | #('tools', 'Tools'), |
| 268 | ('slices','Slices'), |
| 269 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 270 | ('serviceprivileges','Privileges'), |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 271 | ) |
| 272 | |
| 273 | suit_form_includes = (('vbngadmin.html', 'top', 'administration'), |
| 274 | ) #('hpctools.html', 'top', 'tools') ) |
| 275 | |
| 276 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 277 | return VBNGService.get_service_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 278 | |
| 279 | class VBNGTenantForm(forms.ModelForm): |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 280 | routeable_subnet = forms.CharField(required=False) |
| 281 | mapped_hostname = forms.CharField(required=False) |
| 282 | mapped_ip = forms.CharField(required=False) |
| 283 | mapped_mac = forms.CharField(required=False) |
| 284 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 285 | def __init__(self,*args,**kwargs): |
| 286 | super (VBNGTenantForm,self ).__init__(*args,**kwargs) |
| 287 | self.fields['kind'].widget.attrs['readonly'] = True |
| 288 | self.fields['provider_service'].queryset = VBNGService.get_service_objects().all() |
| 289 | if self.instance: |
| 290 | # fields for the attributes |
| 291 | self.fields['routeable_subnet'].initial = self.instance.routeable_subnet |
| 292 | self.fields['mapped_hostname'].initial = self.instance.mapped_hostname |
| 293 | self.fields['mapped_ip'].initial = self.instance.mapped_ip |
| 294 | self.fields['mapped_mac'].initial = self.instance.mapped_mac |
| 295 | if (not self.instance) or (not self.instance.pk): |
| 296 | # default fields for an 'add' form |
| 297 | self.fields['kind'].initial = VBNG_KIND |
| 298 | if VBNGService.get_service_objects().exists(): |
| 299 | self.fields["provider_service"].initial = VBNGService.get_service_objects().all()[0] |
| 300 | |
| 301 | def save(self, commit=True): |
| 302 | self.instance.routeable_subnet = self.cleaned_data.get("routeable_subnet") |
| 303 | self.instance.mapped_hostname = self.cleaned_data.get("mapped_hostname") |
| 304 | self.instance.mapped_ip = self.cleaned_data.get("mapped_ip") |
| 305 | self.instance.mapped_mac = self.cleaned_data.get("mapped_mac") |
| 306 | return super(VBNGTenantForm, self).save(commit=commit) |
| 307 | |
| 308 | class Meta: |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 309 | model = VBNGTenant |
| 310 | |
| 311 | class VBNGTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | b3cf921 | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 312 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 313 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 314 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute', |
| 315 | 'routeable_subnet', 'mapped_hostname', 'mapped_ip', 'mapped_mac'], |
| 316 | 'classes':['suit-tab suit-tab-general']})] |
| 317 | readonly_fields = ('backend_status_text', 'service_specific_attribute') |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 318 | form = VBNGTenantForm |
| 319 | |
| 320 | suit_form_tabs = (('general','Details'),) |
| 321 | |
| 322 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 323 | return VBNGTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 324 | |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 325 | #----------------------------------------------------------------------------- |
| 326 | # CordSubscriberRoot |
| 327 | #----------------------------------------------------------------------------- |
| 328 | |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 329 | class VOLTTenantInline(XOSTabularInline): |
| 330 | model = VOLTTenant |
| 331 | fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 332 | readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id'] |
| 333 | extra = 0 |
| 334 | max_num = 0 |
| 335 | suit_classes = 'suit-tab suit-tab-volttenants' |
| 336 | fk_name = 'subscriber_root' |
| 337 | verbose_name = 'subscribed tenant' |
| 338 | verbose_name_plural = 'subscribed tenants' |
| 339 | |
| 340 | @property |
| 341 | def selflink_reverse_path(self): |
| 342 | return "admin:cord_volttenant_change" |
| 343 | |
| 344 | def queryset(self, request): |
| 345 | qs = super(VOLTTenantInline, self).queryset(request) |
| 346 | return qs.filter(kind=VOLT_KIND) |
| 347 | |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 348 | class CordSubscriberRootForm(forms.ModelForm): |
| 349 | url_filter_level = forms.CharField(required = False) |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 350 | uplink_speed = forms.CharField(required = False) |
| 351 | downlink_speed = forms.CharField(required = False) |
| 352 | status = forms.ChoiceField(choices=CordSubscriberRoot.status_choices, required=True) |
| 353 | enable_uverse = forms.BooleanField(required=False) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 354 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 355 | def __init__(self,*args,**kwargs): |
| 356 | super (CordSubscriberRootForm,self ).__init__(*args,**kwargs) |
| 357 | self.fields['kind'].widget.attrs['readonly'] = True |
| 358 | if self.instance: |
| 359 | self.fields['url_filter_level'].initial = self.instance.url_filter_level |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 360 | self.fields['uplink_speed'].initial = self.instance.uplink_speed |
| 361 | self.fields['downlink_speed'].initial = self.instance.downlink_speed |
| 362 | self.fields['status'].initial = self.instance.status |
| 363 | self.fields['enable_uverse'].initial = self.instance.enable_uverse |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 364 | if (not self.instance) or (not self.instance.pk): |
| 365 | # default fields for an 'add' form |
| 366 | self.fields['kind'].initial = CORD_SUBSCRIBER_KIND |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 367 | self.fields['uplink_speed'].initial = CordSubscriberRoot.get_default_attribute("uplink_speed") |
| 368 | self.fields['downlink_speed'].initial = CordSubscriberRoot.get_default_attribute("downlink_speed") |
| 369 | self.fields['status'].initial = CordSubscriberRoot.get_default_attribute("status") |
| 370 | self.fields['enable_uverse'].initial = CordSubscriberRoot.get_default_attribute("enable_uverse") |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 371 | |
| 372 | def save(self, commit=True): |
| 373 | self.instance.url_filter_level = self.cleaned_data.get("url_filter_level") |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 374 | self.instance.uplink_speed = self.cleaned_data.get("uplink_speed") |
| 375 | self.instance.downlink_speed = self.cleaned_data.get("downlink_speed") |
| 376 | self.instance.status = self.cleaned_data.get("status") |
| 377 | self.instance.enable_uverse = self.cleaned_data.get("enable_uverse") |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 378 | return super(CordSubscriberRootForm, self).save(commit=commit) |
| 379 | |
| 380 | class Meta: |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 381 | model = CordSubscriberRoot |
| 382 | |
| 383 | class CordSubscriberRootAdmin(ReadOnlyAwareAdmin): |
| 384 | list_display = ('backend_status_icon', 'id', 'name', ) |
| 385 | list_display_links = ('backend_status_icon', 'id', 'name', ) |
| 386 | fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute', |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 387 | 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse"], |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 388 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 389 | readonly_fields = ('backend_status_text', 'service_specific_attribute',) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 390 | form = CordSubscriberRootForm |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 391 | inlines = (VOLTTenantInline, TenantRootPrivilegeInline) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 392 | |
| 393 | suit_form_tabs =(('general', 'Cord Subscriber Root Details'), |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 394 | ('volttenants','VOLT Tenancy'), |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 395 | ('tenantrootprivileges','Privileges') |
| 396 | ) |
| 397 | |
| 398 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 399 | return CordSubscriberRoot.get_tenant_objects_by_user(request.user) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 400 | |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 401 | admin.site.register(VOLTService, VOLTServiceAdmin) |
| 402 | admin.site.register(VOLTTenant, VOLTTenantAdmin) |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 403 | admin.site.register(VSGService, VSGServiceAdmin) |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 404 | admin.site.register(VSGTenant, VSGTenantAdmin) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 405 | admin.site.register(VBNGService, VBNGServiceAdmin) |
| 406 | admin.site.register(VBNGTenant, VBNGTenantAdmin) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 407 | admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin) |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 408 | |