Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
Srikanth Vavilapalli | d84b7b7 | 2016-06-28 00:19:07 +0000 | [diff] [blame] | 3 | from services.monitoring.models import * |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -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 |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 13 | from core.admin import XOSBaseAdmin,ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline, TenantAttrAsTabInline, UploadTextareaWidget |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 14 | from core.middleware import get_request |
| 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 | |
| 21 | class 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 Vavilapalli | 71aa28d | 2017-01-31 00:43:13 +0000 | [diff] [blame] | 23 | ceilometer_enable_pub_sub = forms.BooleanField() |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 24 | |
| 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 Vavilapalli | 71aa28d | 2017-01-31 00:43:13 +0000 | [diff] [blame] | 30 | self.fields['ceilometer_enable_pub_sub'].initial = self.instance.ceilometer_enable_pub_sub |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 31 | |
| 32 | def save(self, commit=True): |
| 33 | self.instance.ceilometer_pub_sub_url = self.cleaned_data.get("ceilometer_pub_sub_url") |
Srikanth Vavilapalli | 71aa28d | 2017-01-31 00:43:13 +0000 | [diff] [blame] | 34 | self.instance.ceilometer_enable_pub_sub = self.cleaned_data.get("ceilometer_enable_pub_sub") |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 35 | return super(CeilometerServiceForm, self).save(commit=commit) |
| 36 | |
| 37 | class Meta: |
| 38 | model = CeilometerService |
Zack Williams | 1861b52 | 2016-06-27 08:25:33 -0700 | [diff] [blame] | 39 | fields = '__all__' |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 40 | |
| 41 | class 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 Vavilapalli | 71aa28d | 2017-01-31 00:43:13 +0000 | [diff] [blame] | 47 | 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 Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 49 | 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 | ) |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 65 | #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 Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 77 | |
Zack Williams | 031e1b6 | 2016-06-27 13:19:50 -0700 | [diff] [blame] | 78 | def get_queryset(self, request): |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 79 | return CeilometerService.get_service_objects_by_user(request.user) |
| 80 | |
| 81 | class 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 Williams | 1861b52 | 2016-06-27 08:25:33 -0700 | [diff] [blame] | 105 | fields = '__all__' |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 106 | |
| 107 | class 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 Vavilapalli | 71aa28d | 2017-01-31 00:43:13 +0000 | [diff] [blame] | 111 | 'ceilometer_url', 'ceilometer_ssh_proxy_url', 'kafka_url', 'tenant_list_str', |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 112 | 'instance', 'creator'], |
| 113 | 'classes':['suit-tab suit-tab-general']})] |
Srikanth Vavilapalli | 71aa28d | 2017-01-31 00:43:13 +0000 | [diff] [blame] | 114 | readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute', 'ceilometer_url', 'ceilometer_ssh_proxy_url', 'kafka_url', 'tenant_list_str') |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 115 | form = MonitoringChannelForm |
| 116 | |
| 117 | suit_form_tabs = (('general','Details'),) |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 118 | #actions=['delete_selected_objects'] |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 119 | |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 120 | #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 Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 125 | |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 126 | #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 Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 130 | |
Zack Williams | 031e1b6 | 2016-06-27 13:19:50 -0700 | [diff] [blame] | 131 | def get_queryset(self, request): |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 132 | return MonitoringChannel.get_tenant_objects_by_user(request.user) |
| 133 | |
| 134 | class 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 Williams | 1861b52 | 2016-06-27 08:25:33 -0700 | [diff] [blame] | 156 | fields = '__all__' |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 157 | |
| 158 | class 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 Williams | 031e1b6 | 2016-06-27 13:19:50 -0700 | [diff] [blame] | 183 | def get_queryset(self, request): |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 184 | return SFlowService.get_service_objects_by_user(request.user) |
| 185 | |
| 186 | class 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 Williams | 1861b52 | 2016-06-27 08:25:33 -0700 | [diff] [blame] | 212 | fields = '__all__' |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 213 | |
| 214 | class 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 Williams | 031e1b6 | 2016-06-27 13:19:50 -0700 | [diff] [blame] | 226 | def get_queryset(self, request): |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 227 | return SFlowTenant.get_tenant_objects_by_user(request.user) |
| 228 | |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 229 | class 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 | |
| 254 | class 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 | |
| 279 | class 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 | |
| 307 | class 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 | |
| 332 | class 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 | |
| 361 | class 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 | |
| 386 | class 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 | |
| 394 | class 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 | |
| 403 | class 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 | |
| 411 | class 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 Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 420 | admin.site.register(CeilometerService, CeilometerServiceAdmin) |
| 421 | admin.site.register(SFlowService, SFlowServiceAdmin) |
| 422 | admin.site.register(MonitoringChannel, MonitoringChannelAdmin) |
| 423 | admin.site.register(SFlowTenant, SFlowTenantAdmin) |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 424 | admin.site.register(OpenStackServiceMonitoringPublisher, OpenStackServiceMonitoringPublisherAdmin) |
| 425 | admin.site.register(ONOSServiceMonitoringPublisher, ONOSServiceMonitoringPublisherAdmin) |
| 426 | admin.site.register(UserServiceMonitoringPublisher, UserServiceMonitoringPublisherAdmin) |
| 427 | admin.site.register(InfraMonitoringAgentInfo, InfraMonitoringAgentInfoAdmin) |
| 428 | admin.site.register(MonitoringCollectorPluginInfo, MonitoringCollectorPluginInfoAdmin) |
Scott Baker | 31acc65 | 2016-06-23 15:47:56 -0700 | [diff] [blame] | 429 | |