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 | 27b36bc | 2016-05-23 20:57:00 -0700 | [diff] [blame] | 97 | class 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 | |
| 109 | class VOLTDeviceAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 3424ab1 | 2016-05-24 15:27:19 -0700 | [diff] [blame] | 110 | 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 Baker | 27b36bc | 2016-05-23 20:57:00 -0700 | [diff] [blame] | 113 | '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 | |
| 119 | class 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 | |
| 128 | class 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 | |
| 140 | class AccessAgentAdmin(ReadOnlyAwareAdmin): |
Scott Baker | 3424ab1 | 2016-05-24 15:27:19 -0700 | [diff] [blame] | 141 | 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 Baker | 27b36bc | 2016-05-23 20:57:00 -0700 | [diff] [blame] | 144 | '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 Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 150 | #----------------------------------------------------------------------------- |
| 151 | # vCPE |
| 152 | #----------------------------------------------------------------------------- |
| 153 | |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 154 | class VSGServiceForm(forms.ModelForm): |
Scott Baker | 2b56cf4 | 2015-07-15 18:08:06 -0700 | [diff] [blame] | 155 | bbs_api_hostname = forms.CharField(required=False) |
| 156 | bbs_api_port = forms.IntegerField(required=False) |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 157 | 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 Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 160 | dns_servers = forms.CharField(required=False) |
Scott Baker | 9b87057 | 2016-03-10 19:23:10 -0800 | [diff] [blame] | 161 | url_filter_kind = forms.ChoiceField(choices=VSGService.URL_FILTER_KIND_CHOICES, required=False) |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 162 | node_label = forms.CharField(required=False) |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 163 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 164 | def __init__(self,*args,**kwargs): |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 165 | super (VSGServiceForm,self ).__init__(*args,**kwargs) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 166 | 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 Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 172 | self.fields['dns_servers'].initial = self.instance.dns_servers |
Scott Baker | 9b87057 | 2016-03-10 19:23:10 -0800 | [diff] [blame] | 173 | self.fields['url_filter_kind']. initial = self.instance.url_filter_kind |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 174 | self.fields['node_label'].initial = self.instance.node_label |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 175 | |
| 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 Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 182 | self.instance.dns_servers = self.cleaned_data.get("dns_servers") |
Scott Baker | 9b87057 | 2016-03-10 19:23:10 -0800 | [diff] [blame] | 183 | self.instance.url_filter_kind = self.cleaned_data.get("url_filter_kind") |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 184 | self.instance.node_label = self.cleaned_data.get("node_label") |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 185 | return super(VSGServiceForm, self).save(commit=commit) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 186 | |
| 187 | class Meta: |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 188 | model = VSGService |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 189 | |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 190 | class VSGServiceAdmin(ReadOnlyAwareAdmin): |
| 191 | model = VSGService |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 192 | verbose_name = "vSG Service" |
| 193 | verbose_name_plural = "vSG Service" |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 194 | list_display = ("backend_status_icon", "name", "enabled") |
| 195 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 67074ab | 2016-03-04 11:29:02 -0800 | [diff] [blame] | 196 | 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] | 197 | 'classes':['suit-tab suit-tab-general']}), |
Scott Baker | 9b87057 | 2016-03-10 19:23:10 -0800 | [diff] [blame] | 198 | ("backend config", {'fields': [ "backend_network_label", "url_filter_kind", "bbs_api_hostname", "bbs_api_port", "bbs_server", "bbs_slice"], |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 199 | 'classes':['suit-tab suit-tab-backend']}), |
Scott Baker | 451050f | 2016-04-19 17:55:56 -0700 | [diff] [blame] | 200 | ("vSG config", {'fields': ["dns_servers"], |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 201 | 'classes':['suit-tab suit-tab-vsg']}) ] |
Scott Baker | 6231297 | 2015-07-13 14:30:25 -0700 | [diff] [blame] | 202 | readonly_fields = ('backend_status_text', "service_specific_attribute") |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 203 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 204 | form = VSGServiceForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 205 | |
| 206 | extracontext_registered_admins = True |
| 207 | |
| 208 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 209 | |
Scott Baker | 80157da | 2015-07-15 17:42:43 -0700 | [diff] [blame] | 210 | suit_form_tabs =(('general', 'Service Details'), |
| 211 | ('backend', 'Backend Config'), |
Scott Baker | ae6187c | 2016-02-23 14:58:49 -0800 | [diff] [blame] | 212 | ('vsg', 'vSG Config'), |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 213 | ('administration', 'Administration'), |
| 214 | #('tools', 'Tools'), |
| 215 | ('slices','Slices'), |
| 216 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 217 | ('serviceprivileges','Privileges') , |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 218 | ) |
| 219 | |
| 220 | suit_form_includes = (('vcpeadmin.html', 'top', 'administration'), |
| 221 | ) #('hpctools.html', 'top', 'tools') ) |
| 222 | |
| 223 | def queryset(self, request): |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 224 | return VSGService.get_service_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 225 | |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 226 | class VSGTenantForm(forms.ModelForm): |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 227 | bbs_account = forms.CharField(required=False) |
| 228 | creator = forms.ModelChoiceField(queryset=User.objects.all()) |
Tony Mack | d851547 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 229 | instance = forms.ModelChoiceField(queryset=Instance.objects.all(),required=False) |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 230 | last_ansible_hash = forms.CharField(required=False) |
Scott Baker | e6780e9 | 2016-02-13 14:38:43 -0800 | [diff] [blame] | 231 | wan_container_ip = forms.CharField(required=False) |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 232 | wan_container_mac = forms.CharField(required=False) |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 233 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 234 | def __init__(self,*args,**kwargs): |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 235 | super (VSGTenantForm,self ).__init__(*args,**kwargs) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 236 | self.fields['kind'].widget.attrs['readonly'] = True |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 237 | self.fields['provider_service'].queryset = VSGService.get_service_objects().all() |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 238 | 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 Baker | e6780e9 | 2016-02-13 14:38:43 -0800 | [diff] [blame] | 244 | self.fields['wan_container_ip'].initial = self.instance.wan_container_ip |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 245 | self.fields['wan_container_mac'].initial = self.instance.wan_container_mac |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 246 | 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 Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 250 | if VSGService.get_service_objects().exists(): |
| 251 | self.fields["provider_service"].initial = VSGService.get_service_objects().all()[0] |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 252 | |
| 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 Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 257 | return super(VSGTenantForm, self).save(commit=commit) |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 258 | |
| 259 | class Meta: |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 260 | model = VSGTenant |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 261 | |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 262 | class VSGTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | b3cf921 | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 263 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 264 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 265 | 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] | 266 | '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] | 267 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | cf6eb99 | 2016-02-18 06:43:02 -0800 | [diff] [blame] | 268 | 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] | 269 | form = VSGTenantForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 270 | |
| 271 | suit_form_tabs = (('general','Details'),) |
| 272 | |
| 273 | def queryset(self, request): |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 274 | return VSGTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 275 | |
| 276 | #----------------------------------------------------------------------------- |
| 277 | # vBNG |
| 278 | #----------------------------------------------------------------------------- |
| 279 | |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 280 | class VBNGServiceForm(forms.ModelForm): |
| 281 | vbng_url = forms.CharField(required=False) |
| 282 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 283 | 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 Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 293 | model = VBNGService |
| 294 | |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 295 | class 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 Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 301 | 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 Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 304 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 305 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
Scott Baker | 21d1893 | 2015-07-21 18:24:21 -0700 | [diff] [blame] | 306 | form = VBNGServiceForm |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 307 | |
| 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 Baker | 9da5304 | 2015-05-15 09:08:19 -0700 | [diff] [blame] | 317 | ('serviceprivileges','Privileges'), |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 318 | ) |
| 319 | |
| 320 | suit_form_includes = (('vbngadmin.html', 'top', 'administration'), |
| 321 | ) #('hpctools.html', 'top', 'tools') ) |
| 322 | |
| 323 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 324 | return VBNGService.get_service_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 325 | |
| 326 | class VBNGTenantForm(forms.ModelForm): |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 327 | 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 Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 332 | 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 Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 356 | model = VBNGTenant |
| 357 | |
| 358 | class VBNGTenantAdmin(ReadOnlyAwareAdmin): |
Scott Baker | b3cf921 | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 359 | list_display = ('backend_status_icon', 'id', 'subscriber_tenant' ) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 360 | list_display_links = ('backend_status_icon', 'id') |
Scott Baker | 80a3929 | 2015-07-21 18:18:25 -0700 | [diff] [blame] | 361 | 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 Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 365 | form = VBNGTenantForm |
| 366 | |
| 367 | suit_form_tabs = (('general','Details'),) |
| 368 | |
| 369 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 370 | return VBNGTenant.get_tenant_objects_by_user(request.user) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 371 | |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 372 | #----------------------------------------------------------------------------- |
| 373 | # CordSubscriberRoot |
| 374 | #----------------------------------------------------------------------------- |
| 375 | |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 376 | class 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 Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 395 | class CordSubscriberRootForm(forms.ModelForm): |
| 396 | url_filter_level = forms.CharField(required = False) |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 397 | 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 Baker | d0447e5 | 2016-03-09 12:44:07 -0800 | [diff] [blame] | 401 | cdn_enable = forms.BooleanField(required=False) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 402 | |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 403 | 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 Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 408 | 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 Baker | d0447e5 | 2016-03-09 12:44:07 -0800 | [diff] [blame] | 412 | self.fields['cdn_enable'].initial = self.instance.cdn_enable |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 413 | 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 Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 416 | 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 Baker | d0447e5 | 2016-03-09 12:44:07 -0800 | [diff] [blame] | 420 | self.fields['cdn_enable'].initial = CordSubscriberRoot.get_default_attribute("cdn_enable") |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 421 | |
| 422 | def save(self, commit=True): |
| 423 | self.instance.url_filter_level = self.cleaned_data.get("url_filter_level") |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 424 | 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 Baker | d0447e5 | 2016-03-09 12:44:07 -0800 | [diff] [blame] | 428 | self.instance.cdn_enable = self.cleaned_data.get("cdn_enable") |
Sapan Bhatia | 16be143 | 2016-01-14 11:41:38 -0500 | [diff] [blame] | 429 | return super(CordSubscriberRootForm, self).save(commit=commit) |
| 430 | |
| 431 | class Meta: |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 432 | model = CordSubscriberRoot |
| 433 | |
| 434 | class 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 Baker | d0447e5 | 2016-03-09 12:44:07 -0800 | [diff] [blame] | 438 | 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse", "cdn_enable"], |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 439 | 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 669212f | 2016-03-01 20:14:35 -0800 | [diff] [blame] | 440 | readonly_fields = ('backend_status_text', 'service_specific_attribute',) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 441 | form = CordSubscriberRootForm |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 442 | inlines = (VOLTTenantInline, TenantRootPrivilegeInline) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 443 | |
| 444 | suit_form_tabs =(('general', 'Cord Subscriber Root Details'), |
Scott Baker | 4124e96 | 2015-07-24 10:15:01 -0700 | [diff] [blame] | 445 | ('volttenants','VOLT Tenancy'), |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 446 | ('tenantrootprivileges','Privileges') |
| 447 | ) |
| 448 | |
| 449 | def queryset(self, request): |
Scott Baker | 27de601 | 2015-07-24 15:36:02 -0700 | [diff] [blame] | 450 | return CordSubscriberRoot.get_tenant_objects_by_user(request.user) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 451 | |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 452 | admin.site.register(VOLTService, VOLTServiceAdmin) |
| 453 | admin.site.register(VOLTTenant, VOLTTenantAdmin) |
Scott Baker | 27b36bc | 2016-05-23 20:57:00 -0700 | [diff] [blame] | 454 | admin.site.register(VOLTDevice, VOLTDeviceAdmin) |
| 455 | admin.site.register(AccessDevice, AccessDeviceAdmin) |
| 456 | admin.site.register(AccessAgent, AccessAgentAdmin) |
| 457 | |
Scott Baker | f91e615 | 2016-02-11 12:07:10 -0800 | [diff] [blame] | 458 | admin.site.register(VSGService, VSGServiceAdmin) |
Scott Baker | 4c052b2 | 2016-02-11 11:08:42 -0800 | [diff] [blame] | 459 | admin.site.register(VSGTenant, VSGTenantAdmin) |
Scott Baker | 27b768d | 2015-04-21 17:15:18 -0700 | [diff] [blame] | 460 | admin.site.register(VBNGService, VBNGServiceAdmin) |
| 461 | admin.site.register(VBNGTenant, VBNGTenantAdmin) |
Scott Baker | 6dddd2f | 2015-07-23 12:06:26 -0700 | [diff] [blame] | 462 | admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin) |
Scott Baker | bb2a2a2 | 2015-04-21 16:59:04 -0700 | [diff] [blame] | 463 | |