blob: b2a9242f3c9d2834058a0e7c0530320ba07379a6 [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
13from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline, TenantAttrAsTabInline
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
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")
23
24 def __init__(self,*args,**kwargs):
25 super (CeilometerServiceForm,self ).__init__(*args,**kwargs)
26 if self.instance:
27 # fields for the attributes
28 self.fields['ceilometer_pub_sub_url'].initial = self.instance.ceilometer_pub_sub_url
29
30 def save(self, commit=True):
31 self.instance.ceilometer_pub_sub_url = self.cleaned_data.get("ceilometer_pub_sub_url")
32 return super(CeilometerServiceForm, self).save(commit=commit)
33
34 class Meta:
35 model = CeilometerService
Zack Williams1861b522016-06-27 08:25:33 -070036 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -070037
38class CeilometerServiceAdmin(ReadOnlyAwareAdmin):
39 model = CeilometerService
40 verbose_name = "Ceilometer Service"
41 verbose_name_plural = "Ceilometer Service"
42 list_display = ("backend_status_icon", "name", "enabled")
43 list_display_links = ('backend_status_icon', 'name', )
44 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description','ceilometer_pub_sub_url', "view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
45 readonly_fields = ('backend_status_text', )
46 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
47 form = CeilometerServiceForm
48
49 extracontext_registered_admins = True
50
51 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
52
53 suit_form_tabs =(('general', 'Ceilometer Service Details'),
54 ('administration', 'Administration'),
55 ('slices','Slices'),
56 ('serviceattrs','Additional Attributes'),
57 ('serviceprivileges','Privileges'),
58 )
59
60 suit_form_includes = (('ceilometeradmin.html', 'top', 'administration'),
61 )
62
Zack Williams031e1b62016-06-27 13:19:50 -070063 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -070064 return CeilometerService.get_service_objects_by_user(request.user)
65
66class MonitoringChannelForm(forms.ModelForm):
67 creator = forms.ModelChoiceField(queryset=User.objects.all())
68
69 def __init__(self,*args,**kwargs):
70 super (MonitoringChannelForm,self ).__init__(*args,**kwargs)
71 self.fields['kind'].widget.attrs['readonly'] = True
72 self.fields['provider_service'].queryset = CeilometerService.get_service_objects().all()
73 if self.instance:
74 # fields for the attributes
75 self.fields['creator'].initial = self.instance.creator
76 if (not self.instance) or (not self.instance.pk):
77 # default fields for an 'add' form
78 self.fields['kind'].initial = CEILOMETER_KIND
79 self.fields['creator'].initial = get_request().user
80 if CeilometerService.get_service_objects().exists():
81 self.fields["provider_service"].initial = CeilometerService.get_service_objects().all()[0]
82
83
84 def save(self, commit=True):
85 self.instance.creator = self.cleaned_data.get("creator")
86 return super(MonitoringChannelForm, self).save(commit=commit)
87
88 class Meta:
89 model = MonitoringChannel
Zack Williams1861b522016-06-27 08:25:33 -070090 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -070091
92class MonitoringChannelAdmin(ReadOnlyAwareAdmin):
93 list_display = ('backend_status_icon', 'id', )
94 list_display_links = ('backend_status_icon', 'id')
95 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'service_specific_attribute',
96 'ceilometer_url', 'tenant_list_str',
97 'instance', 'creator'],
98 'classes':['suit-tab suit-tab-general']})]
99 readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute', 'ceilometer_url', 'tenant_list_str')
100 form = MonitoringChannelForm
101
102 suit_form_tabs = (('general','Details'),)
103 actions=['delete_selected_objects']
104
105 def get_actions(self, request):
106 actions = super(MonitoringChannelAdmin, self).get_actions(request)
107 if 'delete_selected' in actions:
108 del actions['delete_selected']
109 return actions
110
111 def delete_selected_objects(self, request, queryset):
112 for obj in queryset:
113 obj.delete()
114 delete_selected_objects.short_description = "Delete Selected MonitoringChannel Objects"
115
Zack Williams031e1b62016-06-27 13:19:50 -0700116 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -0700117 return MonitoringChannel.get_tenant_objects_by_user(request.user)
118
119class SFlowServiceForm(forms.ModelForm):
120 sflow_port = forms.IntegerField(required=False)
121 sflow_api_port = forms.IntegerField(required=False)
122
123 def __init__(self,*args,**kwargs):
124 super (SFlowServiceForm,self ).__init__(*args,**kwargs)
125 if self.instance:
126 # fields for the attributes
127 self.fields['sflow_port'].initial = self.instance.sflow_port
128 self.fields['sflow_api_port'].initial = self.instance.sflow_api_port
129 if (not self.instance) or (not self.instance.pk):
130 # default fields for an 'add' form
131 self.fields['sflow_port'].initial = SFLOW_PORT
132 self.fields['sflow_api_port'].initial = SFLOW_API_PORT
133
134 def save(self, commit=True):
135 self.instance.sflow_port = self.cleaned_data.get("sflow_port")
136 self.instance.sflow_api_port = self.cleaned_data.get("sflow_api_port")
137 return super(SFlowServiceForm, self).save(commit=commit)
138
139 class Meta:
140 model = SFlowService
Zack Williams1861b522016-06-27 08:25:33 -0700141 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -0700142
143class SFlowServiceAdmin(ReadOnlyAwareAdmin):
144 model = SFlowService
145 verbose_name = "SFlow Service"
146 verbose_name_plural = "SFlow Service"
147 list_display = ("backend_status_icon", "name", "enabled")
148 list_display_links = ('backend_status_icon', 'name', )
149 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']})]
150 readonly_fields = ('backend_status_text', )
151 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
152 form = SFlowServiceForm
153
154 extracontext_registered_admins = True
155
156 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
157
158 suit_form_tabs =(('general', 'SFlow Service Details'),
159 ('administration', 'Administration'),
160 ('slices','Slices'),
161 ('serviceattrs','Additional Attributes'),
162 ('serviceprivileges','Privileges'),
163 )
164
165 suit_form_includes = (('sflowadmin.html', 'top', 'administration'),
166 )
167
Zack Williams031e1b62016-06-27 13:19:50 -0700168 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -0700169 return SFlowService.get_service_objects_by_user(request.user)
170
171class SFlowTenantForm(forms.ModelForm):
172 creator = forms.ModelChoiceField(queryset=User.objects.all())
173 listening_endpoint = forms.CharField(max_length=1024, help_text="sFlow listening endpoint in udp://IP:port format")
174
175 def __init__(self,*args,**kwargs):
176 super (SFlowTenantForm,self ).__init__(*args,**kwargs)
177 self.fields['kind'].widget.attrs['readonly'] = True
178 self.fields['provider_service'].queryset = SFlowService.get_service_objects().all()
179 if self.instance:
180 # fields for the attributes
181 self.fields['creator'].initial = self.instance.creator
182 self.fields['listening_endpoint'].initial = self.instance.listening_endpoint
183 if (not self.instance) or (not self.instance.pk):
184 # default fields for an 'add' form
185 self.fields['kind'].initial = SFLOW_KIND
186 self.fields['creator'].initial = get_request().user
187 if SFlowService.get_service_objects().exists():
188 self.fields["provider_service"].initial = SFlowService.get_service_objects().all()[0]
189
190 def save(self, commit=True):
191 self.instance.creator = self.cleaned_data.get("creator")
192 self.instance.listening_endpoint = self.cleaned_data.get("listening_endpoint")
193 return super(SFlowTenantForm, self).save(commit=commit)
194
195 class Meta:
196 model = SFlowTenant
Zack Williams1861b522016-06-27 08:25:33 -0700197 fields = '__all__'
Scott Baker31acc652016-06-23 15:47:56 -0700198
199class SFlowTenantAdmin(ReadOnlyAwareAdmin):
200 list_display = ('backend_status_icon', 'creator', 'listening_endpoint' )
201 list_display_links = ('backend_status_icon', 'listening_endpoint')
202 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_service', 'service_specific_attribute', 'listening_endpoint',
203 'creator'],
204 'classes':['suit-tab suit-tab-general']})]
205 readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute')
206 inlines = [TenantAttrAsTabInline]
207 form = SFlowTenantForm
208
209 suit_form_tabs = (('general','Details'), ('tenantattrs', 'Attributes'))
210
Zack Williams031e1b62016-06-27 13:19:50 -0700211 def get_queryset(self, request):
Scott Baker31acc652016-06-23 15:47:56 -0700212 return SFlowTenant.get_tenant_objects_by_user(request.user)
213
214admin.site.register(CeilometerService, CeilometerServiceAdmin)
215admin.site.register(SFlowService, SFlowServiceAdmin)
216admin.site.register(MonitoringChannel, MonitoringChannelAdmin)
217admin.site.register(SFlowTenant, SFlowTenantAdmin)
218