blob: 0ec0f301b5a9a9410ea31a3d989aeae0fe36a9a0 [file] [log] [blame]
Scott Baker761e1062016-06-20 17:18:17 -07001from django.contrib import admin
2
3from services.vsg.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
Scott Baker761e1062016-06-20 17:18:17 -070021class VSGServiceAdmin(ReadOnlyAwareAdmin):
22 model = VSGService
23 verbose_name = "vSG Service"
24 verbose_name_plural = "vSG Service"
25 list_display = ("backend_status_icon", "name", "enabled")
26 list_display_links = ('backend_status_icon', 'name', )
27 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description', "view_url", "icon_url", "service_specific_attribute", "node_label"],
28 'classes':['suit-tab suit-tab-general']}),
Scott Bakercc9b98d2017-03-20 09:42:37 -070029 ("backend config", {'fields': [ "url_filter_kind" ],
Scott Baker761e1062016-06-20 17:18:17 -070030 'classes':['suit-tab suit-tab-backend']}),
Scott Baker8e66d662016-10-13 13:22:49 -070031 ("vSG config", {'fields': ["dns_servers", "docker_image_name", "docker_insecure_registry"],
Scott Baker761e1062016-06-20 17:18:17 -070032 'classes':['suit-tab suit-tab-vsg']}) ]
33 readonly_fields = ('backend_status_text', "service_specific_attribute")
34 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
Scott Baker761e1062016-06-20 17:18:17 -070035
36 extracontext_registered_admins = True
37
38 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
39
40 suit_form_tabs =(('general', 'Service Details'),
41 ('backend', 'Backend Config'),
42 ('vsg', 'vSG Config'),
43 ('administration', 'Administration'),
44 #('tools', 'Tools'),
45 ('slices','Slices'),
46 ('serviceattrs','Additional Attributes'),
47 ('serviceprivileges','Privileges') ,
48 )
49
50 suit_form_includes = (('vcpeadmin.html', 'top', 'administration'),
51 ) #('hpctools.html', 'top', 'tools') )
52
Zack Williams0e6714d2016-06-27 13:11:08 -070053 def get_queryset(self, request):
Scott Baker761e1062016-06-20 17:18:17 -070054 return VSGService.get_service_objects_by_user(request.user)
55
56class VSGTenantForm(forms.ModelForm):
Scott Baker761e1062016-06-20 17:18:17 -070057 last_ansible_hash = forms.CharField(required=False)
58 wan_container_ip = forms.CharField(required=False)
59 wan_container_mac = forms.CharField(required=False)
60
61 def __init__(self,*args,**kwargs):
62 super (VSGTenantForm,self ).__init__(*args,**kwargs)
63 self.fields['kind'].widget.attrs['readonly'] = True
Scott Bakercc9b98d2017-03-20 09:42:37 -070064 self.fields['provider_service'].queryset = VSGService.objects.all()
Scott Baker761e1062016-06-20 17:18:17 -070065 if self.instance:
66 # fields for the attributes
Scott Baker761e1062016-06-20 17:18:17 -070067 self.fields['last_ansible_hash'].initial = self.instance.last_ansible_hash
68 self.fields['wan_container_ip'].initial = self.instance.wan_container_ip
69 self.fields['wan_container_mac'].initial = self.instance.wan_container_mac
70 if (not self.instance) or (not self.instance.pk):
71 # default fields for an 'add' form
72 self.fields['kind'].initial = VCPE_KIND
73 self.fields['creator'].initial = get_request().user
Scott Bakercc9b98d2017-03-20 09:42:37 -070074 if VSGService.objects.exists():
75 self.fields["provider_service"].initial = VSGService.objects.all()[0]
Scott Baker761e1062016-06-20 17:18:17 -070076
77 def save(self, commit=True):
78 self.instance.creator = self.cleaned_data.get("creator")
79 self.instance.instance = self.cleaned_data.get("instance")
80 self.instance.last_ansible_hash = self.cleaned_data.get("last_ansible_hash")
81 return super(VSGTenantForm, self).save(commit=commit)
82
83 class Meta:
84 model = VSGTenant
Zack Williamsd7ca08f2016-06-27 08:32:50 -070085 fields = '__all__'
Scott Baker761e1062016-06-20 17:18:17 -070086
87class VSGTenantAdmin(ReadOnlyAwareAdmin):
88 list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
89 list_display_links = ('backend_status_icon', 'id')
Scott Bakercc9b98d2017-03-20 09:42:37 -070090 fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id',
91 'wan_container_ip', 'wan_container_mac', 'creator', 'instance', 'last_ansible_hash'],
Scott Baker761e1062016-06-20 17:18:17 -070092 'classes':['suit-tab suit-tab-general']})]
Scott Bakercc9b98d2017-03-20 09:42:37 -070093 readonly_fields = ('backend_status_text', 'service_specific_attribute', 'wan_container_ip', 'wan_container_mac')
Scott Baker761e1062016-06-20 17:18:17 -070094 form = VSGTenantForm
95
96 suit_form_tabs = (('general','Details'),)
97
Zack Williams0e6714d2016-06-27 13:11:08 -070098 def get_queryset(self, request):
Scott Baker761e1062016-06-20 17:18:17 -070099 return VSGTenant.get_tenant_objects_by_user(request.user)
100
101
102admin.site.register(VSGService, VSGServiceAdmin)
103admin.site.register(VSGTenant, VSGTenantAdmin)
104