Scott Baker | 90378fa | 2016-04-20 16:58:44 -0700 | [diff] [blame] | 1 | from django.contrib import admin |
| 2 | |
| 3 | from services.cord.models import * |
| 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 |
| 13 | from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline |
| 14 | from core.middleware import get_request |
| 15 | |
| 16 | from services.vtn.models import * |
| 17 | from services.cord.models import CordSubscriberRoot |
| 18 | |
| 19 | from functools import update_wrapper |
| 20 | from django.contrib.admin.views.main import ChangeList |
| 21 | from django.core.urlresolvers import reverse |
| 22 | from django.contrib.admin.utils import quote |
| 23 | |
| 24 | class 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 Bavier | 8a71f80 | 2016-04-26 16:29:06 -0400 | [diff] [blame] | 32 | xosEndpoint = forms.CharField(required=False) |
| 33 | xosUser = forms.CharField(required=False) |
| 34 | xosPassword = forms.CharField(required=False) |
Scott Baker | 90378fa | 2016-04-20 16:58:44 -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 |
Andy Bavier | 8a71f80 | 2016-04-26 16:29:06 -0400 | [diff] [blame] | 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 | 90378fa | 2016-04-20 16:58:44 -0700 | [diff] [blame] | 49 | |
| 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 Bavier | 3925949 | 2016-04-27 14:30:03 -0400 | [diff] [blame] | 58 | 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 Baker | 90378fa | 2016-04-20 16:58:44 -0700 | [diff] [blame] | 61 | return super(VTNServiceForm, self).save(commit=commit) |
| 62 | |
| 63 | class Meta: |
| 64 | model = VTNService |
| 65 | |
| 66 | class 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 Bavier | 8a71f80 | 2016-04-26 16:29:06 -0400 | [diff] [blame] | 74 | 'privateGatewayMac', 'localManagementIp', 'ovsdbPort', 'sshPort', 'sshUser', 'sshKeyFile', 'mgmtSubnetBits', 'xosEndpoint', 'xosUser', 'xosPassword' ], 'classes':['suit-tab suit-tab-general']})] |
Scott Baker | 90378fa | 2016-04-20 16:58:44 -0700 | [diff] [blame] | 75 | 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 | |
| 95 | admin.site.register(VTNService, VTNServiceAdmin) |