blob: 464f1973ed7501f5617c0586224286c3a7666972 [file] [log] [blame]
Scott Bakerc3ce3e72016-06-20 17:35:19 -07001from django.contrib import admin
2
3from django import forms
4from django.utils.safestring import mark_safe
5from django.contrib.auth.admin import UserAdmin
6from django.contrib.admin.widgets import FilteredSelectMultiple
7from django.contrib.auth.forms import ReadOnlyPasswordHashField
8from django.contrib.auth.signals import user_logged_in
9from django.utils import timezone
10from django.contrib.contenttypes import generic
11from suit.widgets import LinkedSelect
12from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
13from core.middleware import get_request
14
15from services.vtn.models import *
16
17from functools import update_wrapper
18from django.contrib.admin.views.main import ChangeList
19from django.core.urlresolvers import reverse
20from django.contrib.admin.utils import quote
21
22class VTNServiceForm(forms.ModelForm):
23 privateGatewayMac = forms.CharField(required=False)
24 localManagementIp = forms.CharField(required=False)
25 ovsdbPort = forms.CharField(required=False)
26 sshPort = forms.CharField(required=False)
27 sshUser = forms.CharField(required=False)
28 sshKeyFile = forms.CharField(required=False)
29 mgmtSubnetBits = forms.CharField(required=False)
30 xosEndpoint = forms.CharField(required=False)
31 xosUser = forms.CharField(required=False)
32 xosPassword = forms.CharField(required=False)
33
34 def __init__(self,*args,**kwargs):
35 super (VTNServiceForm,self ).__init__(*args,**kwargs)
36 if self.instance:
37 self.fields['privateGatewayMac'].initial = self.instance.privateGatewayMac
38 self.fields['localManagementIp'].initial = self.instance.localManagementIp
39 self.fields['ovsdbPort'].initial = self.instance.ovsdbPort
40 self.fields['sshPort'].initial = self.instance.sshPort
41 self.fields['sshUser'].initial = self.instance.sshUser
42 self.fields['sshKeyFile'].initial = self.instance.sshKeyFile
43 self.fields['mgmtSubnetBits'].initial = self.instance.mgmtSubnetBits
44 self.fields['xosEndpoint'].initial = self.instance.xosEndpoint
45 self.fields['xosUser'].initial = self.instance.xosUser
46 self.fields['xosPassword'].initial = self.instance.xosPassword
47
48 def save(self, commit=True):
49 self.instance.privateGatewayMac = self.cleaned_data.get("privateGatewayMac")
50 self.instance.localManagementIp = self.cleaned_data.get("localManagementIp")
51 self.instance.ovsdbPort = self.cleaned_data.get("ovsdbPort")
52 self.instance.sshPort = self.cleaned_data.get("sshPort")
53 self.instance.sshUser = self.cleaned_data.get("sshUser")
54 self.instance.sshKeyFile = self.cleaned_data.get("sshKeyFile")
55 self.instance.mgmtSubnetBits = self.cleaned_data.get("mgmtSubnetBits")
56 self.instance.xosEndpoint = self.cleaned_data.get("xosEndpoint")
57 self.instance.xosUser = self.cleaned_data.get("xosUser")
58 self.instance.xosPassword = self.cleaned_data.get("xosPassword")
59 return super(VTNServiceForm, self).save(commit=commit)
60
61 class Meta:
62 model = VTNService
63
64class VTNServiceAdmin(ReadOnlyAwareAdmin):
65 model = VTNService
66 form = VTNServiceForm
67 verbose_name = "VTN Service"
68 verbose_name_plural = "VTN Service"
69 list_display = ("backend_status_icon", "name", "enabled")
70 list_display_links = ('backend_status_icon', 'name', )
71 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber','description',"view_url","icon_url",
72 'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile', 'mgmtSubnetBits', 'xosEndpoint', 'xosUser', 'xosPassword' ], 'classes':['suit-tab suit-tab-general']})]
73 readonly_fields = ('backend_status_text', )
74 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
75
76 extracontext_registered_admins = True
77
78 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
79
80 suit_form_tabs =(('general', 'VTN Service Details'),
81# ('administration', 'Administration'),
82 ('slices','Slices'),
83 ('serviceattrs','Additional Attributes'),
84 ('serviceprivileges','Privileges'),
85 )
86
87 suit_form_includes = ( # ('vtnadmin.html', 'top', 'administration'),
88 ) #('hpctools.html', 'top', 'tools') )
89
90 def queryset(self, request):
91 return VTNService.get_service_objects_by_user(request.user)
92
93admin.site.register(VTNService, VTNServiceAdmin)