blob: 03ff5cd322edd4d1c33c31993e50934a075a819a [file] [log] [blame]
Scott Baker90378fa2016-04-20 16:58:44 -07001from django.contrib import admin
2
3from services.cord.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 services.vtn.models import *
17from services.cord.models import CordSubscriberRoot
18
19from functools import update_wrapper
20from django.contrib.admin.views.main import ChangeList
21from django.core.urlresolvers import reverse
22from django.contrib.admin.utils import quote
23
24class VTNServiceForm(forms.ModelForm):
25 privateGatewayMac = forms.CharField(required=False)
26 localManagementIp = forms.CharField(required=False)
27 ovsdbPort = forms.CharField(required=False)
28 sshPort = forms.CharField(required=False)
29 sshUser = forms.CharField(required=False)
30 sshKeyFile = forms.CharField(required=False)
31 mgmtSubnetBits = forms.CharField(required=False)
Andy Bavier8a71f802016-04-26 16:29:06 -040032 xosEndpoint = forms.CharField(required=False)
33 xosUser = forms.CharField(required=False)
34 xosPassword = forms.CharField(required=False)
Scott Baker90378fa2016-04-20 16:58:44 -070035
36 def __init__(self,*args,**kwargs):
37 super (VTNServiceForm,self ).__init__(*args,**kwargs)
38 if self.instance:
39 self.fields['privateGatewayMac'].initial = self.instance.privateGatewayMac
40 self.fields['localManagementIp'].initial = self.instance.localManagementIp
41 self.fields['ovsdbPort'].initial = self.instance.ovsdbPort
42 self.fields['sshPort'].initial = self.instance.sshPort
43 self.fields['sshUser'].initial = self.instance.sshUser
44 self.fields['sshKeyFile'].initial = self.instance.sshKeyFile
45 self.fields['mgmtSubnetBits'].initial = self.instance.mgmtSubnetBits
Andy Bavier8a71f802016-04-26 16:29:06 -040046 self.fields['xosEndpoint'].initial = self.instance.xosEndpoint
47 self.fields['xosUser'].initial = self.instance.xosUser
48 self.fields['xosPassword'].initial = self.instance.xosPassword
Scott Baker90378fa2016-04-20 16:58:44 -070049
50 def save(self, commit=True):
51 self.instance.privateGatewayMac = self.cleaned_data.get("privateGatewayMac")
52 self.instance.localManagementIp = self.cleaned_data.get("localManagementIp")
53 self.instance.ovsdbPort = self.cleaned_data.get("ovsdbPort")
54 self.instance.sshPort = self.cleaned_data.get("sshPort")
55 self.instance.sshUser = self.cleaned_data.get("sshUser")
56 self.instance.sshKeyFile = self.cleaned_data.get("sshKeyFile")
57 self.instance.mgmtSubnetBits = self.cleaned_data.get("mgmtSubnetBits")
Andy Bavier39259492016-04-27 14:30:03 -040058 self.instance.xosEndpoint = self.cleaned_data.get("xosEndpoint")
59 self.instance.xosUser = self.cleaned_data.get("xosUser")
60 self.instance.xosPassword = self.cleaned_data.get("xosPassword")
Scott Baker90378fa2016-04-20 16:58:44 -070061 return super(VTNServiceForm, self).save(commit=commit)
62
63 class Meta:
64 model = VTNService
65
66class VTNServiceAdmin(ReadOnlyAwareAdmin):
67 model = VTNService
68 form = VTNServiceForm
69 verbose_name = "VTN Service"
70 verbose_name_plural = "VTN Service"
71 list_display = ("backend_status_icon", "name", "enabled")
72 list_display_links = ('backend_status_icon', 'name', )
73 fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber','description',"view_url","icon_url",
Andy Bavier8a71f802016-04-26 16:29:06 -040074 'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile', 'mgmtSubnetBits', 'xosEndpoint', 'xosUser', 'xosPassword' ], 'classes':['suit-tab suit-tab-general']})]
Scott Baker90378fa2016-04-20 16:58:44 -070075 readonly_fields = ('backend_status_text', )
76 inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
77
78 extracontext_registered_admins = True
79
80 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
81
82 suit_form_tabs =(('general', 'VTN Service Details'),
83# ('administration', 'Administration'),
84 ('slices','Slices'),
85 ('serviceattrs','Additional Attributes'),
86 ('serviceprivileges','Privileges'),
87 )
88
89 suit_form_includes = ( # ('vtnadmin.html', 'top', 'administration'),
90 ) #('hpctools.html', 'top', 'tools') )
91
92 def queryset(self, request):
93 return VTNService.get_service_objects_by_user(request.user)
94
95admin.site.register(VTNService, VTNServiceAdmin)