blob: f2adf24b12c13cca3405c77ec86152b665168693 [file] [log] [blame]
Scott Baker31acc652016-06-23 15:47:56 -07001from django.contrib import admin
2
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +00003from services.monitoring.models import *
Scott Baker31acc652016-06-23 15:47:56 -07004from django import forms
5from django.utils.safestring import mark_safe
6from django.contrib.auth.admin import UserAdmin
7from django.contrib.admin.widgets import FilteredSelectMultiple
8from django.contrib.auth.forms import ReadOnlyPasswordHashField
9from django.contrib.auth.signals import user_logged_in
10from django.utils import timezone
11from django.contrib.contenttypes import generic
12from suit.widgets import LinkedSelect
rdudyala996d70b2016-10-13 17:40:55 +000013from core.admin import XOSBaseAdmin,ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline, TenantAttrAsTabInline, UploadTextareaWidget
Scott Baker31acc652016-06-23 15:47:56 -070014from 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
21class CeilometerServiceForm(forms.ModelForm):
22 ceilometer_pub_sub_url = forms.CharField(required=False, max_length=1024, help_text="REST URL of ceilometer PUB/SUB component in http://IP:port/ format")
Srikanth Vavilapalli71aa28d2017-01-31 00:43:13 +000023 ceilometer_enable_pub_sub = forms.BooleanField()
Scott Baker31acc652016-06-23 15:47:56 -070024
25 def __init__(self,*args,**kwargs):
26 super (CeilometerServiceForm,self ).__init__(*args,**kwargs)
27 if self.instance:
28 # fields for the attributes
29 self.fields['ceilometer_pub_sub_url'].initial = self.instance.ceilometer_pub_sub_url
Srikanth Vavilapalli71aa28d2017-01-31 00:43:13 +000030 self.fields['ceilometer_enable_pub_sub'].initial = self.instance.ceilometer_enable_pub_sub
Scott Baker31acc652016-06-23 15:47:56 -070031
32 def save(self, commit=True):
33 self.instance.ceilometer_pub_sub_url = self.cleaned_data.get("ceilometer_pub_sub_url")
Srikanth Vavilapalli71aa28d2017-01-31 00:43:13 +000034 self.instance.ceilometer_enable_pub_sub = self.cleaned_data.get("ceilometer_enable_pub_sub")
Scott Baker31acc652016-06-23 15:47:56 -070035 return super(CeilometerServiceForm, self).save(commit=commit)
36
37 class Meta:
38 model = CeilometerService
Zack Williams1861b522016-06-27 08:25:33 -070039 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -070040
41class CeilometerServiceAdmin(ReadOnlyAwareAdmin):
42 model = CeilometerService
43 verbose_name = "Ceilometer Service"
44 verbose_name_plural = "Ceilometer Service"
45 list_display = ("backend_status_icon", "name", "enabled")
46 list_display_links = ('backend_status_icon', 'name', )
Srikanth Vavilapalli71aa28d2017-01-31 00:43:13 +000047 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description','ceilometer_pub_sub_url', 'ceilometer_enable_pub_sub', "view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
48 readonly_fields = ('backend_status_text', 'ceilometer_pub_sub_url',)
Scott Baker31acc652016-06-23 15:47:56 -070049 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
50 form = CeilometerServiceForm
51
52 extracontext_registered_admins = True
53
54 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
55
56 suit_form_tabs =(('general', 'Ceilometer Service Details'),
57 ('administration', 'Administration'),
58 ('slices','Slices'),
59 ('serviceattrs','Additional Attributes'),
60 ('serviceprivileges','Privileges'),
61 )
62
63 suit_form_includes = (('ceilometeradmin.html', 'top', 'administration'),
64 )
rdudyala996d70b2016-10-13 17:40:55 +000065 #actions=['delete_selected_objects']
66
67 #def get_actions(self, request):
68 # actions = super(CeilometerServiceAdmin, self).get_actions(request)
69 # if 'delete_selected' in actions:
70 # del actions['delete_selected']
71 # return actions
72
73 #def delete_selected_objects(self, request, queryset):
74 # for obj in queryset:
75 # obj.delete()
76 #delete_selected_objects.short_description = "Delete Selected Ceilometer Service Objects"
Scott Baker31acc652016-06-23 15:47:56 -070077
Zack Williams031e1b62016-06-27 13:19:50 -070078 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -070079 return CeilometerService.get_service_objects_by_user(request.user)
80
81class MonitoringChannelForm(forms.ModelForm):
82 creator = forms.ModelChoiceField(queryset=User.objects.all())
83
84 def __init__(self,*args,**kwargs):
85 super (MonitoringChannelForm,self ).__init__(*args,**kwargs)
86 self.fields['kind'].widget.attrs['readonly'] = True
87 self.fields['provider_service'].queryset = CeilometerService.get_service_objects().all()
88 if self.instance:
89 # fields for the attributes
90 self.fields['creator'].initial = self.instance.creator
91 if (not self.instance) or (not self.instance.pk):
92 # default fields for an 'add' form
93 self.fields['kind'].initial = CEILOMETER_KIND
94 self.fields['creator'].initial = get_request().user
95 if CeilometerService.get_service_objects().exists():
96 self.fields["provider_service"].initial = CeilometerService.get_service_objects().all()[0]
97
98
99 def save(self, commit=True):
100 self.instance.creator = self.cleaned_data.get("creator")
101 return super(MonitoringChannelForm, self).save(commit=commit)
102
103 class Meta:
104 model = MonitoringChannel
Zack Williams1861b522016-06-27 08:25:33 -0700105 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -0700106
107class MonitoringChannelAdmin(ReadOnlyAwareAdmin):
108 list_display = ('backend_status_icon', 'id', )
109 list_display_links = ('backend_status_icon', 'id')
110 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_attribute',
Srikanth Vavilapalli71aa28d2017-01-31 00:43:13 +0000111 'ceilometer_url', 'ceilometer_ssh_proxy_url', 'kafka_url', 'tenant_list_str',
Scott Baker31acc652016-06-23 15:47:56 -0700112 'instance', 'creator'],
113 'classes':['suit-tab suit-tab-general']})]
Srikanth Vavilapalli71aa28d2017-01-31 00:43:13 +0000114 readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute', 'ceilometer_url', 'ceilometer_ssh_proxy_url', 'kafka_url', 'tenant_list_str')
Scott Baker31acc652016-06-23 15:47:56 -0700115 form = MonitoringChannelForm
116
117 suit_form_tabs = (('general','Details'),)
rdudyala996d70b2016-10-13 17:40:55 +0000118 #actions=['delete_selected_objects']
Scott Baker31acc652016-06-23 15:47:56 -0700119
rdudyala996d70b2016-10-13 17:40:55 +0000120 #def get_actions(self, request):
121 # actions = super(MonitoringChannelAdmin, self).get_actions(request)
122 # if 'delete_selected' in actions:
123 # del actions['delete_selected']
124 # return actions
Scott Baker31acc652016-06-23 15:47:56 -0700125
rdudyala996d70b2016-10-13 17:40:55 +0000126 #def delete_selected_objects(self, request, queryset):
127 # for obj in queryset:
128 # obj.delete()
129 #delete_selected_objects.short_description = "Delete Selected MonitoringChannel Objects"
Scott Baker31acc652016-06-23 15:47:56 -0700130
Zack Williams031e1b62016-06-27 13:19:50 -0700131 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -0700132 return MonitoringChannel.get_tenant_objects_by_user(request.user)
133
134class SFlowServiceForm(forms.ModelForm):
135 sflow_port = forms.IntegerField(required=False)
136 sflow_api_port = forms.IntegerField(required=False)
137
138 def __init__(self,*args,**kwargs):
139 super (SFlowServiceForm,self ).__init__(*args,**kwargs)
140 if self.instance:
141 # fields for the attributes
142 self.fields['sflow_port'].initial = self.instance.sflow_port
143 self.fields['sflow_api_port'].initial = self.instance.sflow_api_port
144 if (not self.instance) or (not self.instance.pk):
145 # default fields for an 'add' form
146 self.fields['sflow_port'].initial = SFLOW_PORT
147 self.fields['sflow_api_port'].initial = SFLOW_API_PORT
148
149 def save(self, commit=True):
150 self.instance.sflow_port = self.cleaned_data.get("sflow_port")
151 self.instance.sflow_api_port = self.cleaned_data.get("sflow_api_port")
152 return super(SFlowServiceForm, self).save(commit=commit)
153
154 class Meta:
155 model = SFlowService
Zack Williams1861b522016-06-27 08:25:33 -0700156 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -0700157
158class SFlowServiceAdmin(ReadOnlyAwareAdmin):
159 model = SFlowService
160 verbose_name = "SFlow Service"
161 verbose_name_plural = "SFlow Service"
162 list_display = ("backend_status_icon", "name", "enabled")
163 list_display_links = ('backend_status_icon', 'name', )
164 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","sflow_port","sflow_api_port","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
165 readonly_fields = ('backend_status_text', )
166 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
167 form = SFlowServiceForm
168
169 extracontext_registered_admins = True
170
171 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
172
173 suit_form_tabs =(('general', 'SFlow Service Details'),
174 ('administration', 'Administration'),
175 ('slices','Slices'),
176 ('serviceattrs','Additional Attributes'),
177 ('serviceprivileges','Privileges'),
178 )
179
180 suit_form_includes = (('sflowadmin.html', 'top', 'administration'),
181 )
182
Zack Williams031e1b62016-06-27 13:19:50 -0700183 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -0700184 return SFlowService.get_service_objects_by_user(request.user)
185
186class SFlowTenantForm(forms.ModelForm):
187 creator = forms.ModelChoiceField(queryset=User.objects.all())
188 listening_endpoint = forms.CharField(max_length=1024, help_text="sFlow listening endpoint in udp://IP:port format")
189
190 def __init__(self,*args,**kwargs):
191 super (SFlowTenantForm,self ).__init__(*args,**kwargs)
192 self.fields['kind'].widget.attrs['readonly'] = True
193 self.fields['provider_service'].queryset = SFlowService.get_service_objects().all()
194 if self.instance:
195 # fields for the attributes
196 self.fields['creator'].initial = self.instance.creator
197 self.fields['listening_endpoint'].initial = self.instance.listening_endpoint
198 if (not self.instance) or (not self.instance.pk):
199 # default fields for an 'add' form
200 self.fields['kind'].initial = SFLOW_KIND
201 self.fields['creator'].initial = get_request().user
202 if SFlowService.get_service_objects().exists():
203 self.fields["provider_service"].initial = SFlowService.get_service_objects().all()[0]
204
205 def save(self, commit=True):
206 self.instance.creator = self.cleaned_data.get("creator")
207 self.instance.listening_endpoint = self.cleaned_data.get("listening_endpoint")
208 return super(SFlowTenantForm, self).save(commit=commit)
209
210 class Meta:
211 model = SFlowTenant
Zack Williams1861b522016-06-27 08:25:33 -0700212 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -0700213
214class SFlowTenantAdmin(ReadOnlyAwareAdmin):
215 list_display = ('backend_status_icon', 'creator', 'listening_endpoint' )
216 list_display_links = ('backend_status_icon', 'listening_endpoint')
217 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_service', 'service_specific_attribute', 'listening_endpoint',
218 'creator'],
219 'classes':['suit-tab suit-tab-general']})]
220 readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute')
221 inlines = [TenantAttrAsTabInline]
222 form = SFlowTenantForm
223
224 suit_form_tabs = (('general','Details'), ('tenantattrs', 'Attributes'))
225
Zack Williams031e1b62016-06-27 13:19:50 -0700226 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -0700227 return SFlowTenant.get_tenant_objects_by_user(request.user)
228
rdudyala996d70b2016-10-13 17:40:55 +0000229class OpenStackServiceMonitoringPublisherForm(forms.ModelForm):
230 creator = forms.ModelChoiceField(queryset=User.objects.all())
231
232 def __init__(self,*args,**kwargs):
233 super (OpenStackServiceMonitoringPublisherForm,self ).__init__(*args,**kwargs)
234 self.fields['kind'].widget.attrs['readonly'] = True
235 self.fields['provider_service'].queryset = CeilometerService.get_service_objects().all()
236 if self.instance:
237 # fields for the attributes
238 self.fields['creator'].initial = self.instance.creator
239 if (not self.instance) or (not self.instance.pk):
240 # default fields for an 'add' form
241 self.fields['kind'].initial = CEILOMETER_PUBLISH_TENANT_OS_KIND
242 self.fields['creator'].initial = get_request().user
243 if CeilometerService.get_service_objects().exists():
244 self.fields["provider_service"].initial = CeilometerService.get_service_objects().all()[0]
245
246 def save(self, commit=True):
247 self.instance.creator = self.cleaned_data.get("creator")
248 return super(OpenStackServiceMonitoringPublisherForm, self).save(commit=commit)
249
250 class Meta:
251 model = OpenStackServiceMonitoringPublisher
252 fields = '__all__'
253
254class OpenStackServiceMonitoringPublisherAdmin(ReadOnlyAwareAdmin):
255 list_display = ('backend_status_icon', 'id', )
256 list_display_links = ('backend_status_icon', 'id')
257 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_attribute', 'creator'],
258 'classes':['suit-tab suit-tab-general']})]
259 readonly_fields = ('backend_status_text', 'service_specific_attribute' )
260 form = OpenStackServiceMonitoringPublisherForm
261
262 suit_form_tabs = (('general','Details'),)
263 actions=['delete_selected_objects']
264
265 def get_actions(self, request):
266 actions = super(OpenStackServiceMonitoringPublisherAdmin, self).get_actions(request)
267 if 'delete_selected' in actions:
268 del actions['delete_selected']
269 return actions
270
271 def delete_selected_objects(self, request, queryset):
272 for obj in queryset:
273 obj.delete()
274 delete_selected_objects.short_description = "Delete Selected OpenStackServiceMonitoringPublisher Objects"
275
276 def get_queryset(self, request):
277 return OpenStackServiceMonitoringPublisher.get_tenant_objects_by_user(request.user)
278
279class ONOSServiceMonitoringPublisherForm(forms.ModelForm):
280 creator = forms.ModelChoiceField(queryset=User.objects.all())
281 onos_service_endpoints = forms.CharField(max_length=1024, help_text="IP addresses of all the ONOS services to be monitored")
282
283 def __init__(self,*args,**kwargs):
284 super (ONOSServiceMonitoringPublisherForm,self ).__init__(*args,**kwargs)
285 self.fields['kind'].widget.attrs['readonly'] = True
286 self.fields['provider_service'].queryset = CeilometerService.get_service_objects().all()
287 if self.instance:
288 # fields for the attributes
289 self.fields['creator'].initial = self.instance.creator
290 self.fields['onos_service_endpoints'].initial = self.instance.onos_service_endpoints
291 if (not self.instance) or (not self.instance.pk):
292 # default fields for an 'add' form
293 self.fields['kind'].initial = CEILOMETER_PUBLISH_TENANT_ONOS_KIND
294 self.fields['creator'].initial = get_request().user
295 if CeilometerService.get_service_objects().exists():
296 self.fields["provider_service"].initial = CeilometerService.get_service_objects().all()[0]
297
298 def save(self, commit=True):
299 self.instance.creator = self.cleaned_data.get("creator")
300 self.instance.onos_service_endpoints = self.cleaned_data.get("onos_service_endpoints")
301 return super(ONOSServiceMonitoringPublisherForm, self).save(commit=commit)
302
303 class Meta:
304 model = ONOSServiceMonitoringPublisher
305 fields = '__all__'
306
307class ONOSServiceMonitoringPublisherAdmin(ReadOnlyAwareAdmin):
308 list_display = ('backend_status_icon', 'id', )
309 list_display_links = ('backend_status_icon', 'id')
310 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_attribute', 'creator', 'onos_service_endpoints'],
311 'classes':['suit-tab suit-tab-general']})]
312 readonly_fields = ('backend_status_text', 'service_specific_attribute' )
313 form = ONOSServiceMonitoringPublisherForm
314
315 suit_form_tabs = (('general','Details'),)
316 actions=['delete_selected_objects']
317
318 def get_actions(self, request):
319 actions = super(ONOSServiceMonitoringPublisherAdmin, self).get_actions(request)
320 if 'delete_selected' in actions:
321 del actions['delete_selected']
322 return actions
323
324 def delete_selected_objects(self, request, queryset):
325 for obj in queryset:
326 obj.delete()
327 delete_selected_objects.short_description = "Delete Selected OpenStackServiceMonitoringPublisher Objects"
328
329 def get_queryset(self, request):
330 return ONOSServiceMonitoringPublisher.get_tenant_objects_by_user(request.user)
331
332class UserServiceMonitoringPublisherForm(forms.ModelForm):
333 creator = forms.ModelChoiceField(queryset=User.objects.all())
334 exclude_service_list = ['ceilometer', 'onos', 'VTN', 'vROUTER', 'vOLT', 'vTR']
335 target_service = forms.ModelChoiceField(queryset=Service.objects.all().exclude(kind__in=exclude_service_list))
336
337 def __init__(self,*args,**kwargs):
338 super (UserServiceMonitoringPublisherForm,self ).__init__(*args,**kwargs)
339 self.fields['kind'].widget.attrs['readonly'] = True
340 self.fields['provider_service'].queryset = CeilometerService.get_service_objects().all()
341 if self.instance:
342 # fields for the attributes
343 self.fields['creator'].initial = self.instance.creator
344 self.fields['target_service'].initial = self.instance.target_service
345 if (not self.instance) or (not self.instance.pk):
346 # default fields for an 'add' form
347 self.fields['kind'].initial = CEILOMETER_PUBLISH_TENANT_USER_KIND
348 self.fields['creator'].initial = get_request().user
349 if CeilometerService.get_service_objects().exists():
350 self.fields["provider_service"].initial = CeilometerService.get_service_objects().all()[0]
351
352 def save(self, commit=True):
353 self.instance.creator = self.cleaned_data.get("creator")
354 self.instance.target_service = self.cleaned_data.get("target_service")
355 return super(UserServiceMonitoringPublisherForm, self).save(commit=commit)
356
357 class Meta:
358 model = UserServiceMonitoringPublisher
359 fields = '__all__'
360
361class UserServiceMonitoringPublisherAdmin(ReadOnlyAwareAdmin):
362 list_display = ('backend_status_icon', 'id', )
363 list_display_links = ('backend_status_icon', 'id')
364 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_attribute', 'creator', 'target_service'],
365 'classes':['suit-tab suit-tab-general']})]
366 readonly_fields = ('backend_status_text', 'service_specific_attribute' )
367 form = UserServiceMonitoringPublisherForm
368
369 suit_form_tabs = (('general','Details'),)
370 actions=['delete_selected_objects']
371
372 def get_actions(self, request):
373 actions = super(UserServiceMonitoringPublisherAdmin, self).get_actions(request)
374 if 'delete_selected' in actions:
375 del actions['delete_selected']
376 return actions
377
378 def delete_selected_objects(self, request, queryset):
379 for obj in queryset:
380 obj.delete()
381 delete_selected_objects.short_description = "Delete Selected UserServiceMonitoringPublisher Objects"
382
383 def get_queryset(self, request):
384 return UserServiceMonitoringPublisher.get_tenant_objects_by_user(request.user)
385
386class InfraMonitoringAgentInfoForm(forms.ModelForm):
387 class Meta:
388 model = InfraMonitoringAgentInfo
389 widgets = {
390 'start_url_json_data': UploadTextareaWidget(attrs={'rows': 5, 'cols': 80, 'class': "input-xxlarge"}),
391 }
392 fields = '__all__'
393
394class InfraMonitoringAgentInfoAdmin(XOSBaseAdmin):
395 list_display = ('backend_status_icon', 'name', 'id', )
396 list_display_links = ('backend_status_icon', 'name', 'id')
397 fieldsets = [ (None, {'fields': ['name', 'start_url', 'start_url_json_data', 'stop_url', 'monitoring_publisher'],
398 'classes':['suit-tab suit-tab-general']})]
399 form = InfraMonitoringAgentInfoForm
400
401 suit_form_tabs = (('general','Details'),)
402
403class MonitoringCollectorPluginInfoForm(forms.ModelForm):
404 class Meta:
405 model = MonitoringCollectorPluginInfo
406 #widgets = {
407 # 'plugin_notification_handlers_json': UploadTextareaWidget(attrs={'rows': 5, 'cols': 80, 'class': "input-xxlarge"}),
408 #}
409 fields = '__all__'
410
411class MonitoringCollectorPluginInfoAdmin(XOSBaseAdmin):
412 list_display = ('backend_status_icon', 'name', 'id', )
413 list_display_links = ('backend_status_icon', 'name', 'id')
414 fieldsets = [ (None, {'fields': ['name', 'plugin_folder_path', 'plugin_rabbit_exchange', 'monitoring_publisher'],
415 'classes':['suit-tab suit-tab-general']})]
416 form = MonitoringCollectorPluginInfoForm
417
418 suit_form_tabs = (('general','Details'),)
419
Scott Baker31acc652016-06-23 15:47:56 -0700420admin.site.register(CeilometerService, CeilometerServiceAdmin)
421admin.site.register(SFlowService, SFlowServiceAdmin)
422admin.site.register(MonitoringChannel, MonitoringChannelAdmin)
423admin.site.register(SFlowTenant, SFlowTenantAdmin)
rdudyala996d70b2016-10-13 17:40:55 +0000424admin.site.register(OpenStackServiceMonitoringPublisher, OpenStackServiceMonitoringPublisherAdmin)
425admin.site.register(ONOSServiceMonitoringPublisher, ONOSServiceMonitoringPublisherAdmin)
426admin.site.register(UserServiceMonitoringPublisher, UserServiceMonitoringPublisherAdmin)
427admin.site.register(InfraMonitoringAgentInfo, InfraMonitoringAgentInfoAdmin)
428admin.site.register(MonitoringCollectorPluginInfo, MonitoringCollectorPluginInfoAdmin)
Scott Baker31acc652016-06-23 15:47:56 -0700429