blob: b77388377fdee5268c1d7b168ed7172cf335dca3 [file] [log] [blame]
Scott Baker87eb7402016-06-20 17:21:50 -07001from django.contrib import admin
2
3from services.vrouter.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.models import AddressPool
Scott Baker7c241cd2017-07-18 10:54:14 -070014from core.admin import ServiceAppAdmin, SliceInline, ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, AddressPoolInline, SubscriberLinkInline, ProviderLinkInline, ProviderDependencyInline,SubscriberDependencyInline
Scott Baker87eb7402016-06-20 17:21:50 -070015from core.middleware import get_request
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
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -070022
23class VRouterPortInline(XOSTabularInline):
24 model = VRouterPort
25 fields = ['openflow_id']
26 suit_classes = 'suit-tab suit-tab-vrouter_ports'
27 extra = 0
28
29
30class VRouterInterfaceInline(XOSTabularInline):
31 model = VRouterInterface
32 fields = ['name', 'mac', 'vlan']
33 suit_classes = 'suit-tab suit-tab-vrouter_interfaces'
34 extra = 0
35
36
37class VRouterIpInline(XOSTabularInline):
38 model = VRouterIp
39 fields = ['ip']
40 suit_classes = 'suit-tab suit-tab-vrouter_ips'
41 extra = 0
42
43
Scott Baker87eb7402016-06-20 17:21:50 -070044class VRouterServiceForm(forms.ModelForm):
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -070045 def __init__(self, *args, **kwargs):
46 super(VRouterServiceForm, self).__init__(*args, **kwargs)
Scott Baker87eb7402016-06-20 17:21:50 -070047
48 def save(self, commit=True):
49 return super(VRouterServiceForm, self).save(commit=commit)
50
51 class Meta:
52 model = VRouterService
Zack Williamsbde22ab2016-06-27 12:27:01 -070053 fields = '__all__'
Scott Baker87eb7402016-06-20 17:21:50 -070054
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -070055
Scott Baker87eb7402016-06-20 17:21:50 -070056class VRouterServiceAdmin(ReadOnlyAwareAdmin):
57 model = VRouterService
58 verbose_name = "vRouter Service"
59 verbose_name_plural = "vRouter Service"
60 list_display = ("backend_status_icon", "name", "enabled")
61 list_display_links = ('backend_status_icon', 'name', )
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -070062 fieldsets = [(None, {
63 'fields': [
64 'backend_status_text',
65 'name',
66 'enabled',
67 'versionNumber',
68 'description',
69 'view_url',
70 'icon_url',
71 'rest_hostname',
72 'rest_port',
73 'rest_user',
74 'rest_pass',
75 ],
76 'classes':['suit-tab suit-tab-general']})]
77
78 # NOTE make rest_* params editable
79 readonly_fields = (
80 'backend_status_text',
81 'rest_hostname',
82 'rest_port',
83 'rest_user',
84 'rest_pass'
85 )
Scott Baker7c241cd2017-07-18 10:54:14 -070086 inlines = [SliceInline, ServiceAttrAsTabInline, ServicePrivilegeInline, AddressPoolInline, ProviderDependencyInline,SubscriberDependencyInline]
Scott Baker87eb7402016-06-20 17:21:50 -070087 form = VRouterServiceForm
88
89 extracontext_registered_admins = True
90
91 user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
92
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -070093 suit_form_tabs = (
94 ('general', 'vRouter Service Details'),
Scott Baker87eb7402016-06-20 17:21:50 -070095 ('administration', 'Administration'),
96 ('addresspools', 'Addresses'),
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -070097 # ('tools', 'Tools'),
98 ('slices', 'Slices'),
99 ('serviceattrs', 'Additional Attributes'),
Scott Baker7c241cd2017-07-18 10:54:14 -0700100 ('servicetenants', 'Dependencies'),
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700101 ('serviceprivileges', 'Privileges'),
Scott Baker87eb7402016-06-20 17:21:50 -0700102 )
103
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700104 suit_form_includes = ('vrouteradmin.html', 'top', 'administration') # ('hpctools.html', 'top', 'tools') )
Scott Baker87eb7402016-06-20 17:21:50 -0700105
Zack Williamsbde22ab2016-06-27 12:27:01 -0700106 def get_queryset(self, request):
Scott Bakerb03e0a72017-05-25 09:38:12 -0700107 return VRouterService.select_by_user(request.user)
Scott Baker87eb7402016-06-20 17:21:50 -0700108
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700109
Scott Baker87eb7402016-06-20 17:21:50 -0700110class VRouterTenantForm(forms.ModelForm):
Scott Baker87eb7402016-06-20 17:21:50 -0700111 gateway_ip = forms.CharField(required=False)
112 gateway_mac = forms.CharField(required=False)
113 cidr = forms.CharField(required=False)
Scott Baker87eb7402016-06-20 17:21:50 -0700114
115 def __init__(self,*args,**kwargs):
116 super (VRouterTenantForm,self ).__init__(*args,**kwargs)
Scott Baker7c241cd2017-07-18 10:54:14 -0700117 self.fields['owner'].queryset = VRouterService.objects.all()
Scott Baker87eb7402016-06-20 17:21:50 -0700118 if self.instance:
119 # fields for the attributes
Scott Baker87eb7402016-06-20 17:21:50 -0700120 self.fields['gateway_ip'].initial = self.instance.gateway_ip
121 self.fields['gateway_mac'].initial = self.instance.gateway_mac
122 self.fields['cidr'].initial = self.instance.cidr
123 if (not self.instance) or (not self.instance.pk):
124 # default fields for an 'add' form
Scott Bakerd94cbfc2017-03-13 11:40:46 -0700125 if VRouterService.objects.exists():
Scott Baker7c241cd2017-07-18 10:54:14 -0700126 self.fields["owner"].initial = VRouterService.objects.first()
Scott Baker87eb7402016-06-20 17:21:50 -0700127
128 def save(self, commit=True):
Scott Baker87eb7402016-06-20 17:21:50 -0700129 return super(VRouterTenantForm, self).save(commit=commit)
130
131 class Meta:
132 model = VRouterTenant
Zack Williamsedbf95f2016-06-27 08:31:44 -0700133 fields = '__all__'
Scott Baker87eb7402016-06-20 17:21:50 -0700134
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700135
Scott Baker87eb7402016-06-20 17:21:50 -0700136class VRouterTenantAdmin(ReadOnlyAwareAdmin):
Scott Baker7c241cd2017-07-18 10:54:14 -0700137 list_display = ('backend_status_icon', 'id', 'public_ip')
Scott Baker87eb7402016-06-20 17:21:50 -0700138 list_display_links = ('backend_status_icon', 'id')
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700139 fieldsets = [(None, {
140 'fields': [
Scott Baker7c241cd2017-07-18 10:54:14 -0700141 'backend_status_text', 'owner',
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700142 'address_pool', 'public_ip', 'public_mac', 'gateway_ip', 'gateway_mac', 'cidr'],
143 'classes':['suit-tab suit-tab-general']
144 })]
Scott Baker87eb7402016-06-20 17:21:50 -0700145 readonly_fields = ('backend_status_text', 'service_specific_attribute', 'gateway_ip', 'gateway_mac', 'cidr')
Scott Baker7c241cd2017-07-18 10:54:14 -0700146 inlines = (ProviderLinkInline, SubscriberLinkInline)
Scott Baker87eb7402016-06-20 17:21:50 -0700147 form = VRouterTenantForm
148
Scott Baker7c241cd2017-07-18 10:54:14 -0700149 suit_form_tabs = (('general', 'Details'), ('servicelinks','Links'),)
Scott Baker87eb7402016-06-20 17:21:50 -0700150
Zack Williamsbde22ab2016-06-27 12:27:01 -0700151 def get_queryset(self, request):
Scott Bakerb03e0a72017-05-25 09:38:12 -0700152 return VRouterTenant.select_by_user(request.user)
Scott Baker87eb7402016-06-20 17:21:50 -0700153
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700154
155class VRouterDeviceAdmin(ReadOnlyAwareAdmin):
156 list_display = ('name', 'openflow_id', 'config_key', 'driver')
157 fieldsets = [(None, {
158 'fields': ['name', 'openflow_id', 'vrouter_service', 'config_key', 'driver'],
159 'classes':['suit-tab suit-tab-general']
160 })]
161 inlines = [VRouterPortInline]
162
163 suit_form_tabs = (
164 ('general', 'Device Details'),
165 ('vrouter_ports', 'Ports'),
166 )
167
168
169class VRouterPortAdmin(ReadOnlyAwareAdmin):
170 list_display = ('name', 'openflow_id', 'vrouter_device')
171 fieldsets = [(None, {
172 'fields': ['name', 'openflow_id', 'vrouter_service', 'vrouter_device'],
173 'classes':['suit-tab suit-tab-general']
174 })]
175 inlines = [VRouterInterfaceInline]
176
177 suit_form_tabs = (
178 ('general', 'Ports Details'),
179 ('vrouter_interfaces', 'Interfaces'),
180 )
181
182
183class VRouterInterfaceAdmin(ReadOnlyAwareAdmin):
184 list_display = ('name', 'mac', 'vlan')
185 fieldsets = [(None, {
186 'fields': ['name', 'vrouter_port', 'mac', 'vlan'],
187 'classes':['suit-tab suit-tab-general']
188 })]
189 inlines = [VRouterIpInline]
190
191 suit_form_tabs = (
192 ('general', 'Interfaces Details'),
193 ('vrouter_ips', 'Ips'),
194 )
195
196
197class VRouterIpAdmin(ReadOnlyAwareAdmin):
198 list_display = ('name', 'ip', 'vrouter_interface')
199 fieldsets = [(None, {'fields': ['name', 'ip', 'vrouter_interface']})]
200
201
202class VRouterAppAdmin(ReadOnlyAwareAdmin):
203 list_display = ('name', 'control_plane_connect_point', 'ospf_enabled')
204 fieldsets = [(None, {'fields': ['name', 'vrouter_service', 'control_plane_connect_point', 'ospf_enabled']})]
205
206
Scott Baker87eb7402016-06-20 17:21:50 -0700207admin.site.register(VRouterService, VRouterServiceAdmin)
208admin.site.register(VRouterTenant, VRouterTenantAdmin)
Matteo Scandoloa4e6e9a2016-08-23 12:04:45 -0700209admin.site.register(VRouterDevice, VRouterDeviceAdmin)
210admin.site.register(VRouterPort, VRouterPortAdmin)
211admin.site.register(VRouterInterface, VRouterInterfaceAdmin)
212admin.site.register(VRouterIp, VRouterIpAdmin)
213admin.site.register(VRouterApp, VRouterAppAdmin)
Scott Baker87eb7402016-06-20 17:21:50 -0700214