blob: dce13e8dc63153f6baef2ba515d128fa701b5128 [file] [log] [blame]
Scott Baker8e6647a2016-06-20 17:16:20 -07001from django.contrib import admin
2
3from services.volt.models import *
4from django import forms
5from django.utils.safestring import mark_safe
6from django.contrib.auth.admin import UserAdmin
7from django.contrib.admin.widgets import FilteredSelectMultiple
8from django.contrib.auth.forms import ReadOnlyPasswordHashField
9from django.contrib.auth.signals import user_logged_in
10from django.utils import timezone
11from django.contrib.contenttypes import generic
12from suit.widgets import LinkedSelect
13from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
14from core.middleware import get_request
15
16from functools import update_wrapper
17from django.contrib.admin.views.main import ChangeList
18from django.core.urlresolvers import reverse
19from django.contrib.admin.utils import quote
20
21#-----------------------------------------------------------------------------
22# vOLT
23#-----------------------------------------------------------------------------
24
25class VOLTServiceAdmin(ReadOnlyAwareAdmin):
26 model = VOLTService
27 verbose_name = "vOLT Service"
28 verbose_name_plural = "vOLT Service"
29 list_display = ("backend_status_icon", "name", "enabled")
30 list_display_links = ('backend_status_icon', 'name', )
31 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
32 readonly_fields = ('backend_status_text', )
33 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
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'),
44 ('serviceprivileges','Privileges'),
45 )
46
47 suit_form_includes = (('voltadmin.html', 'top', 'administration'),
48 ) #('hpctools.html', 'top', 'tools') )
49
50 def queryset(self, request):
51 return VOLTService.get_service_objects_by_user(request.user)
52
53class VOLTTenantForm(forms.ModelForm):
54 s_tag = forms.CharField()
55 c_tag = forms.CharField()
56 creator = forms.ModelChoiceField(queryset=User.objects.all())
57
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:
81 model = VOLTTenant
Zack Williams56c12862016-06-27 08:28:55 -070082 fields = '__all__'
83
Scott Baker8e6647a2016-06-20 17:16:20 -070084
85class VOLTTenantAdmin(ReadOnlyAwareAdmin):
86 list_display = ('backend_status_icon', 'id', 'service_specific_id', 's_tag', 'c_tag', 'subscriber_root' )
87 list_display_links = ('backend_status_icon', 'id')
88 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_root', 'service_specific_id', # 'service_specific_attribute',
89 's_tag', 'c_tag', 'creator'],
90 'classes':['suit-tab suit-tab-general']})]
91 readonly_fields = ('backend_status_text', 'service_specific_attribute')
92 form = VOLTTenantForm
93
94 suit_form_tabs = (('general','Details'),)
95
96 def queryset(self, request):
97 return VOLTTenant.get_tenant_objects_by_user(request.user)
98
99class AccessDeviceInline(XOSTabularInline):
100 model = AccessDevice
101 fields = ['volt_device','uplink','vlan']
102 readonly_fields = []
103 extra = 0
104# max_num = 0
105 suit_classes = 'suit-tab suit-tab-accessdevices'
106
107# @property
108# def selflink_reverse_path(self):
109# return "admin:cord_volttenant_change"
110
111class VOLTDeviceAdmin(ReadOnlyAwareAdmin):
112 list_display = ('backend_status_icon', 'name', 'openflow_id', 'driver' )
113 list_display_links = ('backend_status_icon', 'name', 'openflow_id')
114 fieldsets = [ (None, {'fields': ['backend_status_text','name','volt_service','openflow_id','driver','access_agent'],
115 'classes':['suit-tab suit-tab-general']})]
116 readonly_fields = ('backend_status_text',)
117 inlines = [AccessDeviceInline]
118
119 suit_form_tabs = (('general','Details'), ('accessdevices','Access Devices'))
120
121class AccessDeviceAdmin(ReadOnlyAwareAdmin):
122 list_display = ('backend_status_icon', 'id', 'volt_device', 'uplink', 'vlan' )
123 list_display_links = ('backend_status_icon', 'id')
124 fieldsets = [ (None, {'fields': ['backend_status_text','volt_device','uplink','vlan'],
125 'classes':['suit-tab suit-tab-general']})]
126 readonly_fields = ('backend_status_text',)
127
128 suit_form_tabs = (('general','Details'),)
129
130class AgentPortMappingInline(XOSTabularInline):
131 model = AgentPortMapping
132 fields = ['access_agent', 'mac', 'port']
133 readonly_fields = []
134 extra = 0
135# max_num = 0
136 suit_classes = 'suit-tab suit-tab-accessportmaps'
137
138# @property
139# def selflink_reverse_path(self):
140# return "admin:cord_volttenant_change"
141
142class AccessAgentAdmin(ReadOnlyAwareAdmin):
143 list_display = ('backend_status_icon', 'name', 'mac' )
144 list_display_links = ('backend_status_icon', 'name')
145 fieldsets = [ (None, {'fields': ['backend_status_text','name','volt_service','mac'],
146 'classes':['suit-tab suit-tab-general']})]
147 readonly_fields = ('backend_status_text',)
148 inlines= [AgentPortMappingInline]
149
150 suit_form_tabs = (('general','Details'), ('accessportmaps', 'Port Mappings'))
151
152# -------------------------------------------
153# CORDSubscriberRoot
154# -------------------------------------------
155
156class VOLTTenantInline(XOSTabularInline):
157 model = VOLTTenant
158 fields = ['provider_service', 'subscriber_root', 'service_specific_id']
159 readonly_fields = ['provider_service', 'subscriber_root', 'service_specific_id']
160 extra = 0
161 max_num = 0
162 suit_classes = 'suit-tab suit-tab-volttenants'
163 fk_name = 'subscriber_root'
164 verbose_name = 'subscribed tenant'
165 verbose_name_plural = 'subscribed tenants'
166
167 @property
168 def selflink_reverse_path(self):
169 return "admin:cord_volttenant_change"
170
171 def queryset(self, request):
172 qs = super(VOLTTenantInline, self).queryset(request)
173 return qs.filter(kind=VOLT_KIND)
174
175class CordSubscriberRootForm(forms.ModelForm):
176 url_filter_level = forms.CharField(required = False)
177 uplink_speed = forms.CharField(required = False)
178 downlink_speed = forms.CharField(required = False)
179 status = forms.ChoiceField(choices=CordSubscriberRoot.status_choices, required=True)
180 enable_uverse = forms.BooleanField(required=False)
181 cdn_enable = forms.BooleanField(required=False)
182
183 def __init__(self,*args,**kwargs):
184 super (CordSubscriberRootForm,self ).__init__(*args,**kwargs)
185 self.fields['kind'].widget.attrs['readonly'] = True
186 if self.instance:
187 self.fields['url_filter_level'].initial = self.instance.url_filter_level
188 self.fields['uplink_speed'].initial = self.instance.uplink_speed
189 self.fields['downlink_speed'].initial = self.instance.downlink_speed
190 self.fields['status'].initial = self.instance.status
191 self.fields['enable_uverse'].initial = self.instance.enable_uverse
192 self.fields['cdn_enable'].initial = self.instance.cdn_enable
193 if (not self.instance) or (not self.instance.pk):
194 # default fields for an 'add' form
195 self.fields['kind'].initial = CORD_SUBSCRIBER_KIND
196 self.fields['uplink_speed'].initial = CordSubscriberRoot.get_default_attribute("uplink_speed")
197 self.fields['downlink_speed'].initial = CordSubscriberRoot.get_default_attribute("downlink_speed")
198 self.fields['status'].initial = CordSubscriberRoot.get_default_attribute("status")
199 self.fields['enable_uverse'].initial = CordSubscriberRoot.get_default_attribute("enable_uverse")
200 self.fields['cdn_enable'].initial = CordSubscriberRoot.get_default_attribute("cdn_enable")
201
202 def save(self, commit=True):
203 self.instance.url_filter_level = self.cleaned_data.get("url_filter_level")
204 self.instance.uplink_speed = self.cleaned_data.get("uplink_speed")
205 self.instance.downlink_speed = self.cleaned_data.get("downlink_speed")
206 self.instance.status = self.cleaned_data.get("status")
207 self.instance.enable_uverse = self.cleaned_data.get("enable_uverse")
208 self.instance.cdn_enable = self.cleaned_data.get("cdn_enable")
209 return super(CordSubscriberRootForm, self).save(commit=commit)
210
211 class Meta:
212 model = CordSubscriberRoot
Zack Williams56c12862016-06-27 08:28:55 -0700213 fields = '__all__'
Scott Baker8e6647a2016-06-20 17:16:20 -0700214
215class CordSubscriberRootAdmin(ReadOnlyAwareAdmin):
216 list_display = ('backend_status_icon', 'id', 'name', )
217 list_display_links = ('backend_status_icon', 'id', 'name', )
218 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'service_specific_id', # 'service_specific_attribute',
219 'url_filter_level', "uplink_speed", "downlink_speed", "status", "enable_uverse", "cdn_enable"],
220 'classes':['suit-tab suit-tab-general']})]
221 readonly_fields = ('backend_status_text', 'service_specific_attribute',)
222 form = CordSubscriberRootForm
223 inlines = (VOLTTenantInline, TenantRootPrivilegeInline)
224
225 suit_form_tabs =(('general', 'Cord Subscriber Root Details'),
226 ('volttenants','VOLT Tenancy'),
227 ('tenantrootprivileges','Privileges')
228 )
229
230 def queryset(self, request):
231 return CordSubscriberRoot.get_tenant_objects_by_user(request.user)
232
233admin.site.register(VOLTService, VOLTServiceAdmin)
234admin.site.register(VOLTTenant, VOLTTenantAdmin)
235admin.site.register(VOLTDevice, VOLTDeviceAdmin)
236admin.site.register(AccessDevice, AccessDeviceAdmin)
237admin.site.register(AccessAgent, AccessAgentAdmin)
238
239admin.site.register(CordSubscriberRoot, CordSubscriberRootAdmin)
240