Scott Baker | c3ce3e7 | 2016-06-20 17:35:19 -0700 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
| 3 | from django import forms |
| 4 | from django.utils.safestring import mark_safe |
| 5 | from django.contrib.auth.admin import UserAdmin |
| 6 | from django.contrib.admin.widgets import FilteredSelectMultiple |
| 7 | from django.contrib.auth.forms import ReadOnlyPasswordHashField |
| 8 | from django.contrib.auth.signals import user_logged_in |
| 9 | from django.utils import timezone |
| 10 | from django.contrib.contenttypes import generic |
| 11 | from suit.widgets import LinkedSelect |
| 12 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline |
| 13 | from core.middleware import get_request |
| 14 | |
| 15 | from services.vtn.models import * |
| 16 | |
| 17 | from functools import update_wrapper |
| 18 | from django.contrib.admin.views.main import ChangeList |
| 19 | from django.core.urlresolvers import reverse |
| 20 | from django.contrib.admin.utils import quote |
| 21 | |
| 22 | class 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) |
Scott Baker | b3a80de | 2016-09-06 16:51:27 -0700 | [diff] [blame] | 33 | vtnAPIVersion = forms.IntegerField(required=False) |
Scott Baker | ff01668 | 2016-11-28 09:53:13 -0800 | [diff] [blame] | 34 | controllerPort = forms.CharField(required=False) |
Scott Baker | c3ce3e7 | 2016-06-20 17:35:19 -0700 | [diff] [blame] | 35 | |
| 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 |
| 46 | self.fields['xosEndpoint'].initial = self.instance.xosEndpoint |
| 47 | self.fields['xosUser'].initial = self.instance.xosUser |
| 48 | self.fields['xosPassword'].initial = self.instance.xosPassword |
Scott Baker | b3a80de | 2016-09-06 16:51:27 -0700 | [diff] [blame] | 49 | self.fields['vtnAPIVersion'].initial = self.instance.vtnAPIVersion |
Scott Baker | ff01668 | 2016-11-28 09:53:13 -0800 | [diff] [blame] | 50 | self.fields['controllerPort'].initial = self.instance.controllerPort |
Scott Baker | c3ce3e7 | 2016-06-20 17:35:19 -0700 | [diff] [blame] | 51 | |
| 52 | def save(self, commit=True): |
| 53 | self.instance.privateGatewayMac = self.cleaned_data.get("privateGatewayMac") |
| 54 | self.instance.localManagementIp = self.cleaned_data.get("localManagementIp") |
| 55 | self.instance.ovsdbPort = self.cleaned_data.get("ovsdbPort") |
| 56 | self.instance.sshPort = self.cleaned_data.get("sshPort") |
| 57 | self.instance.sshUser = self.cleaned_data.get("sshUser") |
| 58 | self.instance.sshKeyFile = self.cleaned_data.get("sshKeyFile") |
| 59 | self.instance.mgmtSubnetBits = self.cleaned_data.get("mgmtSubnetBits") |
| 60 | self.instance.xosEndpoint = self.cleaned_data.get("xosEndpoint") |
| 61 | self.instance.xosUser = self.cleaned_data.get("xosUser") |
| 62 | self.instance.xosPassword = self.cleaned_data.get("xosPassword") |
Scott Baker | b3a80de | 2016-09-06 16:51:27 -0700 | [diff] [blame] | 63 | self.instance.vtnAPIVersion = self.cleaned_data.get("vtnAPIVersion") |
Scott Baker | ff01668 | 2016-11-28 09:53:13 -0800 | [diff] [blame] | 64 | self.instance.controllerPort = self.cleaned_data.get("controllerPort") |
Scott Baker | c3ce3e7 | 2016-06-20 17:35:19 -0700 | [diff] [blame] | 65 | return super(VTNServiceForm, self).save(commit=commit) |
| 66 | |
| 67 | class Meta: |
| 68 | model = VTNService |
Zack Williams | 13df267 | 2016-06-27 08:34:01 -0700 | [diff] [blame] | 69 | fields = '__all__' |
Scott Baker | c3ce3e7 | 2016-06-20 17:35:19 -0700 | [diff] [blame] | 70 | |
| 71 | class VTNServiceAdmin(ReadOnlyAwareAdmin): |
| 72 | model = VTNService |
| 73 | form = VTNServiceForm |
| 74 | verbose_name = "VTN Service" |
| 75 | verbose_name_plural = "VTN Service" |
| 76 | list_display = ("backend_status_icon", "name", "enabled") |
| 77 | list_display_links = ('backend_status_icon', 'name', ) |
| 78 | fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber','description',"view_url","icon_url", |
Scott Baker | ff01668 | 2016-11-28 09:53:13 -0800 | [diff] [blame] | 79 | 'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile', 'mgmtSubnetBits', 'xosEndpoint', 'xosUser', 'xosPassword', 'vtnAPIVersion', 'controllerPort' ], 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | c3ce3e7 | 2016-06-20 17:35:19 -0700 | [diff] [blame] | 80 | readonly_fields = ('backend_status_text', ) |
| 81 | inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline] |
| 82 | |
| 83 | extracontext_registered_admins = True |
| 84 | |
| 85 | user_readonly_fields = ["name", "enabled", "versionNumber", "description"] |
| 86 | |
| 87 | suit_form_tabs =(('general', 'VTN Service Details'), |
| 88 | # ('administration', 'Administration'), |
| 89 | ('slices','Slices'), |
| 90 | ('serviceattrs','Additional Attributes'), |
| 91 | ('serviceprivileges','Privileges'), |
| 92 | ) |
| 93 | |
| 94 | suit_form_includes = ( # ('vtnadmin.html', 'top', 'administration'), |
| 95 | ) #('hpctools.html', 'top', 'tools') ) |
| 96 | |
Zack Williams | abe24da | 2016-06-27 13:09:00 -0700 | [diff] [blame] | 97 | def get_queryset(self, request): |
Scott Baker | c3ce3e7 | 2016-06-20 17:35:19 -0700 | [diff] [blame] | 98 | return VTNService.get_service_objects_by_user(request.user) |
| 99 | |
| 100 | admin.site.register(VTNService, VTNServiceAdmin) |