blob: 1ccc1d6501df1d2ecc3142b02a5e3a96ac02d734 [file] [log] [blame]
Siobhan Tully30fd4292013-05-10 08:59:56 -04001from core.models import Site
2from core.models import *
3from openstack.manager import OpenStackManager
Tony Macke59a7c82013-04-27 11:08:10 -04004
Tony Mack7130ac32013-03-22 21:58:00 -04005from django.contrib import admin
Siobhan Tully53437282013-04-26 19:30:27 -04006from django.contrib.auth.models import Group
Siobhan Tully4bc09f22013-04-10 21:15:21 -04007from django import forms
Tony Mackd90cdbf2013-04-16 22:48:40 -04008from django.utils.safestring import mark_safe
Tony Mack7130ac32013-03-22 21:58:00 -04009from django.contrib.auth.admin import UserAdmin
Siobhan Tully4bc09f22013-04-10 21:15:21 -040010from django.contrib.admin.widgets import FilteredSelectMultiple
Scott Baker1a6a3902014-10-03 00:32:37 -070011from django.contrib.auth.forms import ReadOnlyPasswordHashField, AdminPasswordChangeForm
Scott Bakeracd45142013-05-19 16:19:16 -070012from django.contrib.auth.signals import user_logged_in
13from django.utils import timezone
Siobhan Tullyde5450d2013-06-21 11:35:33 -040014from django.contrib.contenttypes import generic
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040015from suit.widgets import LinkedSelect
Siobhan Tullycf04fb62014-01-11 11:25:57 -050016from django.core.exceptions import PermissionDenied
Scott Bakere2bbf7e2014-01-13 12:09:31 -080017from django.core.urlresolvers import reverse, NoReverseMatch
Tony Mack7130ac32013-03-22 21:58:00 -040018
Scott Baker36f50872014-08-21 13:01:25 -070019import django_evolution
Scott Baker6a995352014-10-06 17:51:20 -070020import threading
21
22# thread locals necessary to work around a django-suit issue
23_thread_locals = threading.local()
Scott Baker36f50872014-08-21 13:01:25 -070024
Scott Baker40c00762014-08-21 16:55:59 -070025def backend_icon(obj): # backend_status, enacted, updated):
26 #return "%s %s %s" % (str(obj.updated), str(obj.enacted), str(obj.backend_status))
27 if (obj.enacted is not None) and obj.enacted >= obj.updated:
Scott Bakerb171e522014-09-09 10:38:15 -070028 return '<span style="min-width:16px;"><img src="/static/admin/img/icon_success.gif"></span>'
Scott Baker40c00762014-08-21 16:55:59 -070029 else:
30 if obj.backend_status == "Provisioning in progress" or obj.backend_status=="":
Scott Bakerb171e522014-09-09 10:38:15 -070031 return '<span style="min-width:16px;" title="%s"><img src="/static/admin/img/icon_clock.gif"></span>' % obj.backend_status
Scott Baker63d1a552014-08-21 15:19:07 -070032 else:
Scott Bakerb171e522014-09-09 10:38:15 -070033 return '<span style="min-width:16px;" title="%s"><img src="/static/admin/img/icon_error.gif"></span>' % obj.backend_status
Scott Baker40c00762014-08-21 16:55:59 -070034
35def backend_text(obj):
36 icon = backend_icon(obj)
37 if (obj.enacted is not None) and obj.enacted >= obj.updated:
38 return "%s %s" % (icon, "successfully enacted") # enacted on %s" % str(obj.enacted))
39 else:
40 return "%s %s" % (icon, obj.backend_status)
Scott Baker63d1a552014-08-21 15:19:07 -070041
Scott Baker36f50872014-08-21 13:01:25 -070042class PlainTextWidget(forms.HiddenInput):
43 input_type = 'hidden'
44
45 def render(self, name, value, attrs=None):
46 if value is None:
47 value = ''
48 return mark_safe(str(value) + super(PlainTextWidget, self).render(name, value, attrs))
49
Scott Bakerf4aeedc2014-10-03 13:10:47 -070050class PermissionCheckingAdminMixin(object):
Scott Baker1a6a3902014-10-03 00:32:37 -070051 # call save_by_user and delete_by_user instead of save and delete
Siobhan Tullycf04fb62014-01-11 11:25:57 -050052
53 def has_add_permission(self, request, obj=None):
54 return (not self.__user_is_readonly(request))
Scott Baker36f50872014-08-21 13:01:25 -070055
Siobhan Tullycf04fb62014-01-11 11:25:57 -050056 def has_delete_permission(self, request, obj=None):
57 return (not self.__user_is_readonly(request))
58
59 def save_model(self, request, obj, form, change):
60 if self.__user_is_readonly(request):
Scott Baker1a6a3902014-10-03 00:32:37 -070061 # this 'if' might be redundant if save_by_user is implemented right
Siobhan Tullycf04fb62014-01-11 11:25:57 -050062 raise PermissionDenied
Scott Baker1a6a3902014-10-03 00:32:37 -070063
64 obj.caller = request.user
65 # update openstack connection to use this site/tenant
66 obj.save_by_user(request.user)
67
68 def delete_model(self, request, obj):
69 obj.delete_by_user(request.user)
70
71 def save_formset(self, request, form, formset, change):
72 instances = formset.save(commit=False)
73 for instance in instances:
74 instance.save_by_user(request.user)
75
76 # BUG in django 1.7? Objects are not deleted by formset.save if
77 # commit is False. So let's delete them ourselves.
78 #
79 # code from forms/models.py save_existing_objects()
80 try:
81 forms_to_delete = formset.deleted_forms
82 except AttributeError:
83 forms_to_delete = []
84 if formset.initial_forms:
85 for form in formset.initial_forms:
86 obj = form.instance
87 if form in forms_to_delete:
88 if obj.pk is None:
89 continue
90 formset.deleted_objects.append(obj)
91 obj.delete()
92
93 formset.save_m2m()
Siobhan Tullycf04fb62014-01-11 11:25:57 -050094
95 def get_actions(self,request):
Scott Bakerf4aeedc2014-10-03 13:10:47 -070096 actions = super(PermissionCheckingAdminMixin,self).get_actions(request)
Siobhan Tullycf04fb62014-01-11 11:25:57 -050097
98 if self.__user_is_readonly(request):
99 if 'delete_selected' in actions:
100 del actions['delete_selected']
101
102 return actions
103
104 def change_view(self,request,object_id, extra_context=None):
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500105 if self.__user_is_readonly(request):
Scott Bakeraf73e102014-04-22 22:40:07 -0700106 if not hasattr(self, "readonly_save"):
107 # save the original readonly fields
108 self.readonly_save = self.readonly_fields
109 self.inlines_save = self.inlines
Scott Bakere8859f92014-05-23 12:42:40 -0700110 if hasattr(self, "user_readonly_fields"):
111 self.readonly_fields=self.user_readonly_fields
112 if hasattr(self, "user_readonly_inlines"):
113 self.inlines = self.user_readonly_inlines
Scott Bakeraf73e102014-04-22 22:40:07 -0700114 else:
115 if hasattr(self, "readonly_save"):
116 # restore the original readonly fields
117 self.readonly_fields = self.readonly_save
Scott Bakere8859f92014-05-23 12:42:40 -0700118 if hasattr(self, "inlines_save"):
Scott Bakeraf73e102014-04-22 22:40:07 -0700119 self.inlines = self.inlines_save
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500120
121 try:
Scott Bakerf4aeedc2014-10-03 13:10:47 -0700122 return super(PermissionCheckingAdminMixin, self).change_view(request, object_id, extra_context=extra_context)
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500123 except PermissionDenied:
124 pass
125 if request.method == 'POST':
126 raise PermissionDenied
127 request.readonly = True
Scott Bakerf4aeedc2014-10-03 13:10:47 -0700128 return super(PermissionCheckingAdminMixin, self).change_view(request, object_id, extra_context=extra_context)
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500129
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500130 def __user_is_readonly(self, request):
131 return request.user.isReadOnlyUser()
132
Scott Baker40c00762014-08-21 16:55:59 -0700133 def backend_status_text(self, obj):
134 return mark_safe(backend_text(obj))
Scott Baker36f50872014-08-21 13:01:25 -0700135
Scott Baker63d1a552014-08-21 15:19:07 -0700136 def backend_status_icon(self, obj):
Scott Baker40c00762014-08-21 16:55:59 -0700137 return mark_safe(backend_icon(obj))
Scott Baker63d1a552014-08-21 15:19:07 -0700138 backend_status_icon.short_description = ""
139
Scott Bakerf4aeedc2014-10-03 13:10:47 -0700140class ReadOnlyAwareAdmin(PermissionCheckingAdminMixin, admin.ModelAdmin):
141 # Note: Make sure PermissionCheckingAdminMixin is listed before
142 # admin.ModelAdmin in the class declaration.
143
Scott Baker1a6a3902014-10-03 00:32:37 -0700144 pass
145
146class PlanetStackBaseAdmin(ReadOnlyAwareAdmin):
147 save_on_top = False
Scott Baker36f50872014-08-21 13:01:25 -0700148
Scott Bakere8859f92014-05-23 12:42:40 -0700149class SingletonAdmin (ReadOnlyAwareAdmin):
Siobhan Tullyce652d02013-10-08 21:52:35 -0400150 def has_add_permission(self, request):
Scott Bakere8859f92014-05-23 12:42:40 -0700151 if not super(SingletonAdmin, self).has_add_permission(request):
152 return False
153
Siobhan Tullyce652d02013-10-08 21:52:35 -0400154 num_objects = self.model.objects.count()
155 if num_objects >= 1:
156 return False
157 else:
158 return True
159
Siobhan Tullyd3515752013-06-21 16:34:53 -0400160class PlStackTabularInline(admin.TabularInline):
Scott Baker86568322014-01-12 16:53:31 -0800161 def __init__(self, *args, **kwargs):
162 super(PlStackTabularInline, self).__init__(*args, **kwargs)
163
164 # InlineModelAdmin as no get_fields() method, so in order to add
165 # the selflink field, we override __init__ to modify self.fields and
166 # self.readonly_fields.
167
Scott Bakere2bbf7e2014-01-13 12:09:31 -0800168 self.setup_selflink()
169
Scott Baker874936e2014-01-13 18:15:34 -0800170 def get_change_url(self, model, id):
171 """ Get the URL to a change form in the admin for this model """
172 reverse_path = "admin:%s_change" % (model._meta.db_table)
Scott Bakere2bbf7e2014-01-13 12:09:31 -0800173 try:
Scott Baker874936e2014-01-13 18:15:34 -0800174 url = reverse(reverse_path, args=(id,))
Scott Bakere2bbf7e2014-01-13 12:09:31 -0800175 except NoReverseMatch:
Scott Baker874936e2014-01-13 18:15:34 -0800176 return None
177
178 return url
179
180 def setup_selflink(self):
181 if hasattr(self, "selflink_fieldname"):
182 """ self.selflink_model can be defined to punch through a relation
183 to its target object. For example, in SliceNetworkInline, set
184 selflink_model = "network", and the URL will lead to the Network
185 object instead of trying to bring up a change view of the
186 SliceNetwork object.
187 """
188 self.selflink_model = getattr(self.model,self.selflink_fieldname).field.rel.to
189 else:
190 self.selflink_model = self.model
191
192 url = self.get_change_url(self.selflink_model, 0)
193
194 # We don't have an admin for this object, so don't create the
195 # selflink.
196 if (url == None):
Scott Bakere2bbf7e2014-01-13 12:09:31 -0800197 return
198
Scott Baker874936e2014-01-13 18:15:34 -0800199 # Since we need to add "selflink" to the field list, we need to create
200 # self.fields if it is None.
Scott Baker0165fac2014-01-13 11:49:26 -0800201 if (self.fields is None):
202 self.fields = []
203 for f in self.model._meta.fields:
204 if f.editable and f.name != "id":
205 self.fields.append(f.name)
Scott Baker86568322014-01-12 16:53:31 -0800206
Scott Baker874936e2014-01-13 18:15:34 -0800207 self.fields = tuple(self.fields) + ("selflink", )
Scott Baker86568322014-01-12 16:53:31 -0800208
Scott Baker874936e2014-01-13 18:15:34 -0800209 if self.readonly_fields is None:
210 self.readonly_fields = ()
Scott Baker86568322014-01-12 16:53:31 -0800211
Scott Baker874936e2014-01-13 18:15:34 -0800212 self.readonly_fields = tuple(self.readonly_fields) + ("selflink", )
Scott Baker86568322014-01-12 16:53:31 -0800213
214 def selflink(self, obj):
Scott Baker874936e2014-01-13 18:15:34 -0800215 if hasattr(self, "selflink_fieldname"):
216 obj = getattr(obj, self.selflink_fieldname)
217
Scott Baker86568322014-01-12 16:53:31 -0800218 if obj.id:
Scott Baker874936e2014-01-13 18:15:34 -0800219 url = self.get_change_url(self.selflink_model, obj.id)
220 return "<a href='%s'>Details</a>" % str(url)
Scott Baker86568322014-01-12 16:53:31 -0800221 else:
Scott Bakere2bbf7e2014-01-13 12:09:31 -0800222 return "Not present"
Scott Baker86568322014-01-12 16:53:31 -0800223
224 selflink.allow_tags = True
225 selflink.short_description = "Details"
Siobhan Tullyd3515752013-06-21 16:34:53 -0400226
Scott Bakerb27b62c2014-08-15 16:29:16 -0700227 def has_add_permission(self, request):
228 return not request.user.isReadOnlyUser()
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500229
230 def get_readonly_fields(self, request, obj=None):
Scott Bakerb27b62c2014-08-15 16:29:16 -0700231 readonly_fields = list(self.readonly_fields)[:]
232 if request.user.isReadOnlyUser():
233 for field in self.fields:
234 if not field in readonly_fields:
235 readonly_fields.append(field)
236 return readonly_fields
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500237
Scott Baker40c00762014-08-21 16:55:59 -0700238 def backend_status_icon(self, obj):
239 return mark_safe(backend_icon(obj))
240 backend_status_icon.short_description = ""
Scott Baker36f50872014-08-21 13:01:25 -0700241
Scott Bakerb27b62c2014-08-15 16:29:16 -0700242class PlStackGenericTabularInline(generic.GenericTabularInline):
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500243 def has_add_permission(self, request):
Scott Bakerb27b62c2014-08-15 16:29:16 -0700244 return not request.user.isReadOnlyUser()
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500245
Scott Bakerb27b62c2014-08-15 16:29:16 -0700246 def get_readonly_fields(self, request, obj=None):
247 readonly_fields = list(self.readonly_fields)[:]
248 if request.user.isReadOnlyUser():
249 for field in self.fields:
250 if not field in readonly_fields:
251 readonly_fields.append(field)
252 return readonly_fields
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500253
Scott Baker40c00762014-08-21 16:55:59 -0700254 def backend_status_icon(self, obj):
255 return mark_safe(backend_icon(obj))
256 backend_status_icon.short_description = ""
257
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400258class ReservationInline(PlStackTabularInline):
259 model = Reservation
260 extra = 0
261 suit_classes = 'suit-tab suit-tab-reservations'
Scott Baker36f50872014-08-21 13:01:25 -0700262
Tony Mack5b061472014-02-04 07:57:10 -0500263 def queryset(self, request):
264 return Reservation.select_by_user(request.user)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400265
Scott Bakerb27b62c2014-08-15 16:29:16 -0700266class TagInline(PlStackGenericTabularInline):
Siobhan Tullyde5450d2013-06-21 11:35:33 -0400267 model = Tag
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400268 extra = 0
269 suit_classes = 'suit-tab suit-tab-tags'
Tony Mack5b061472014-02-04 07:57:10 -0500270 fields = ['service', 'name', 'value']
271
272 def queryset(self, request):
273 return Tag.select_by_user(request.user)
Siobhan Tullyde5450d2013-06-21 11:35:33 -0400274
Scott Baker74d8e622013-07-29 16:04:22 -0700275class NetworkLookerUpper:
Siobhan Tully2c780ad2013-09-06 11:22:40 -0400276 """ This is a callable that looks up a network name in a sliver and returns
277 the ip address for that network.
278 """
279
Scott Baker434ca7e2014-08-15 12:29:20 -0700280 byNetworkName = {} # class variable
281
Siobhan Tully2c780ad2013-09-06 11:22:40 -0400282 def __init__(self, name):
283 self.short_description = name
284 self.__name__ = name
285 self.network_name = name
286
287 def __call__(self, obj):
288 if obj is not None:
289 for nbs in obj.networksliver_set.all():
290 if (nbs.network.name == self.network_name):
291 return nbs.ip
Scott Baker74d8e622013-07-29 16:04:22 -0700292 return ""
293
294 def __str__(self):
295 return self.network_name
296
Scott Baker434ca7e2014-08-15 12:29:20 -0700297 @staticmethod
298 def get(network_name):
299 """ We want to make sure we alwars return the same NetworkLookerUpper
300 because sometimes django will cause them to be instantiated multiple
301 times (and we don't want different ones in form.fields vs
302 SliverInline.readonly_fields).
303 """
304 if network_name not in NetworkLookerUpper.byNetworkName:
305 NetworkLookerUpper.byNetworkName[network_name] = NetworkLookerUpper(network_name)
306 return NetworkLookerUpper.byNetworkName[network_name]
307
Siobhan Tullyd3515752013-06-21 16:34:53 -0400308class SliverInline(PlStackTabularInline):
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400309 model = Sliver
Scott Baker7a61dc42014-09-02 17:08:20 -0700310 fields = ['backend_status_icon', 'all_ips_string', 'instance_name', 'slice', 'deploymentNetwork', 'flavor', 'image', 'node']
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400311 extra = 0
Scott Baker40c00762014-08-21 16:55:59 -0700312 readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_name']
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400313 suit_classes = 'suit-tab suit-tab-slivers'
Scott Baker74d8e622013-07-29 16:04:22 -0700314
Tony Mack5b061472014-02-04 07:57:10 -0500315 def queryset(self, request):
316 return Sliver.select_by_user(request.user)
317
Scott Bakerb24cc932014-06-09 10:51:16 -0700318 def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
Scott Bakerb24cc932014-06-09 10:51:16 -0700319 if db_field.name == 'deploymentNetwork':
Scott Baker3b678742014-06-09 13:11:54 -0700320 kwargs['queryset'] = Deployment.select_by_acl(request.user)
Scott Baker7a61dc42014-09-02 17:08:20 -0700321 kwargs['widget'] = forms.Select(attrs={'onChange': "sliver_deployment_changed(this);"})
Scott Baker4b6d9442014-09-08 12:14:14 -0700322 elif db_field.name == 'flavor':
323 kwargs['widget'] = forms.Select(attrs={'onChange': "sliver_flavor_changed(this);"})
Scott Baker3b678742014-06-09 13:11:54 -0700324
325 field = super(SliverInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
Scott Bakerb24cc932014-06-09 10:51:16 -0700326
327 return field
328
Siobhan Tullyd3515752013-06-21 16:34:53 -0400329class SiteInline(PlStackTabularInline):
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400330 model = Site
331 extra = 0
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400332 suit_classes = 'suit-tab suit-tab-sites'
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400333
Tony Mack5b061472014-02-04 07:57:10 -0500334 def queryset(self, request):
335 return Site.select_by_user(request.user)
336
Siobhan Tullyd3515752013-06-21 16:34:53 -0400337class UserInline(PlStackTabularInline):
Siobhan Tully30fd4292013-05-10 08:59:56 -0400338 model = User
Scott Baker40c00762014-08-21 16:55:59 -0700339 fields = ['backend_status_icon', 'email', 'firstname', 'lastname']
340 readonly_fields = ('backend_status_icon', )
Siobhan Tully30fd4292013-05-10 08:59:56 -0400341 extra = 0
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400342 suit_classes = 'suit-tab suit-tab-users'
Siobhan Tully30fd4292013-05-10 08:59:56 -0400343
Tony Mack5b061472014-02-04 07:57:10 -0500344 def queryset(self, request):
345 return User.select_by_user(request.user)
346
Siobhan Tullyd3515752013-06-21 16:34:53 -0400347class SliceInline(PlStackTabularInline):
Tony Mack00d361f2013-04-28 10:28:42 -0400348 model = Slice
Scott Baker40c00762014-08-21 16:55:59 -0700349 fields = ['backend_status_icon', 'name', 'site', 'serviceClass', 'service']
350 readonly_fields = ('backend_status_icon', )
Tony Mack00d361f2013-04-28 10:28:42 -0400351 extra = 0
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400352 suit_classes = 'suit-tab suit-tab-slices'
353
Tony Mack5b061472014-02-04 07:57:10 -0500354 def queryset(self, request):
355 return Slice.select_by_user(request.user)
356
Siobhan Tullyd3515752013-06-21 16:34:53 -0400357class NodeInline(PlStackTabularInline):
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400358 model = Node
359 extra = 0
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400360 suit_classes = 'suit-tab suit-tab-nodes'
Scott Baker40c00762014-08-21 16:55:59 -0700361 fields = ['backend_status_icon', 'name','deployment','site']
362 readonly_fields = ('backend_status_icon', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400363
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400364class DeploymentPrivilegeInline(PlStackTabularInline):
365 model = DeploymentPrivilege
366 extra = 0
367 suit_classes = 'suit-tab suit-tab-deploymentprivileges'
Scott Baker40c00762014-08-21 16:55:59 -0700368 fields = ['backend_status_icon', 'user','role','deployment']
369 readonly_fields = ('backend_status_icon', )
Tony Mack5b061472014-02-04 07:57:10 -0500370
371 def queryset(self, request):
372 return DeploymentPrivilege.select_by_user(request.user)
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400373
Siobhan Tullyd3515752013-06-21 16:34:53 -0400374class SitePrivilegeInline(PlStackTabularInline):
Siobhan Tullyaa1bcd52013-05-10 12:43:09 -0400375 model = SitePrivilege
376 extra = 0
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400377 suit_classes = 'suit-tab suit-tab-siteprivileges'
Scott Baker40c00762014-08-21 16:55:59 -0700378 fields = ['backend_status_icon', 'user','site', 'role']
379 readonly_fields = ('backend_status_icon', )
Siobhan Tullyaa1bcd52013-05-10 12:43:09 -0400380
Tony Mackc2835a92013-05-28 09:18:49 -0400381 def formfield_for_foreignkey(self, db_field, request, **kwargs):
382 if db_field.name == 'site':
Tony Mack5b061472014-02-04 07:57:10 -0500383 kwargs['queryset'] = Site.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400384
385 if db_field.name == 'user':
Tony Mack5b061472014-02-04 07:57:10 -0500386 kwargs['queryset'] = User.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400387 return super(SitePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
388
Tony Mack5b061472014-02-04 07:57:10 -0500389 def queryset(self, request):
390 return SitePrivilege.select_by_user(request.user)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400391
Tony Macke4be32f2014-03-11 20:45:25 -0400392class SiteDeploymentInline(PlStackTabularInline):
393 model = SiteDeployments
Tony Macke4be32f2014-03-11 20:45:25 -0400394 extra = 0
395 suit_classes = 'suit-tab suit-tab-deployments'
Scott Baker40c00762014-08-21 16:55:59 -0700396 fields = ['backend_status_icon', 'deployment','site']
397 readonly_fields = ('backend_status_icon', )
Tony Macke4be32f2014-03-11 20:45:25 -0400398
399 def formfield_for_foreignkey(self, db_field, request, **kwargs):
400 if db_field.name == 'site':
401 kwargs['queryset'] = Site.select_by_user(request.user)
402
403 if db_field.name == 'deployment':
404 kwargs['queryset'] = Deployment.select_by_user(request.user)
405 return super(SiteDeploymentInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
406
407 def queryset(self, request):
408 return SiteDeployments.select_by_user(request.user)
409
410
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400411class SlicePrivilegeInline(PlStackTabularInline):
412 model = SlicePrivilege
413 suit_classes = 'suit-tab suit-tab-sliceprivileges'
414 extra = 0
Scott Baker40c00762014-08-21 16:55:59 -0700415 fields = ('backend_status_icon', 'user', 'slice', 'role')
416 readonly_fields = ('backend_status_icon', )
Siobhan Tullyaa1bcd52013-05-10 12:43:09 -0400417
Tony Mackc2835a92013-05-28 09:18:49 -0400418 def formfield_for_foreignkey(self, db_field, request, **kwargs):
419 if db_field.name == 'slice':
Scott Baker36f50872014-08-21 13:01:25 -0700420 kwargs['queryset'] = Slice.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400421 if db_field.name == 'user':
Scott Baker36f50872014-08-21 13:01:25 -0700422 kwargs['queryset'] = User.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400423
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400424 return super(SlicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
Tony Mackc2835a92013-05-28 09:18:49 -0400425
Tony Mack5b061472014-02-04 07:57:10 -0500426 def queryset(self, request):
427 return SlicePrivilege.select_by_user(request.user)
428
Scott Bakera0015eb2013-08-14 17:28:14 -0700429class SliceNetworkInline(PlStackTabularInline):
Scott Baker74d8e622013-07-29 16:04:22 -0700430 model = Network.slices.through
Scott Baker874936e2014-01-13 18:15:34 -0800431 selflink_fieldname = "network"
Scott Baker74d8e622013-07-29 16:04:22 -0700432 extra = 0
433 verbose_name = "Network Connection"
434 verbose_name_plural = "Network Connections"
Siobhan Tully2d95e482013-09-06 10:56:06 -0400435 suit_classes = 'suit-tab suit-tab-slicenetworks'
Scott Baker40c00762014-08-21 16:55:59 -0700436 fields = ['backend_status_icon', 'network']
437 readonly_fields = ('backend_status_icon', )
Scott Baker2170b972014-06-03 12:14:07 -0700438
439class ImageDeploymentsInline(PlStackTabularInline):
440 model = ImageDeployments
441 extra = 0
442 verbose_name = "Image Deployments"
443 verbose_name_plural = "Image Deployments"
444 suit_classes = 'suit-tab suit-tab-imagedeployments'
Scott Baker40c00762014-08-21 16:55:59 -0700445 fields = ['backend_status_icon', 'image', 'deployment', 'glance_image_id']
446 readonly_fields = ['backend_status_icon', 'glance_image_id']
Scott Baker74d8e622013-07-29 16:04:22 -0700447
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400448class SliceRoleAdmin(PlanetStackBaseAdmin):
449 model = SliceRole
450 pass
451
452class SiteRoleAdmin(PlanetStackBaseAdmin):
453 model = SiteRole
454 pass
455
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400456class DeploymentAdminForm(forms.ModelForm):
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400457 sites = forms.ModelMultipleChoiceField(
458 queryset=Site.objects.all(),
459 required=False,
Scott Baker70983182014-06-09 22:10:00 -0700460 help_text="Select which sites are allowed to host nodes in this deployment",
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400461 widget=FilteredSelectMultiple(
462 verbose_name=('Sites'), is_stacked=False
463 )
464 )
Scott Bakerde0f4412014-06-11 15:40:26 -0700465 images = forms.ModelMultipleChoiceField(
466 queryset=Image.objects.all(),
467 required=False,
468 help_text="Select which images should be deployed on this deployment",
469 widget=FilteredSelectMultiple(
470 verbose_name=('Images'), is_stacked=False
471 )
472 )
Scott Baker37b47902014-09-02 14:37:41 -0700473 flavors = forms.ModelMultipleChoiceField(
474 queryset=Flavor.objects.all(),
475 required=False,
476 help_text="Select which flavors should be usable on this deployment",
477 widget=FilteredSelectMultiple(
478 verbose_name=('Flavors'), is_stacked=False
479 )
480 )
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400481 class Meta:
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400482 model = Deployment
Scott Baker37b47902014-09-02 14:37:41 -0700483 many_to_many = ["flavors",]
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400484
Siobhan Tully320b4622014-01-17 15:11:14 -0500485 def __init__(self, *args, **kwargs):
Scott Baker5380c522014-06-06 14:49:43 -0700486 request = kwargs.pop('request', None)
Siobhan Tully320b4622014-01-17 15:11:14 -0500487 super(DeploymentAdminForm, self).__init__(*args, **kwargs)
488
Scott Baker5380c522014-06-06 14:49:43 -0700489 self.fields['accessControl'].initial = "allow site " + request.user.site.name
490
Siobhan Tully320b4622014-01-17 15:11:14 -0500491 if self.instance and self.instance.pk:
Scott Bakerc9b14f72014-05-22 13:44:20 -0700492 self.fields['sites'].initial = [x.site for x in self.instance.sitedeployments_set.all()]
Scott Bakerde0f4412014-06-11 15:40:26 -0700493 self.fields['images'].initial = [x.image for x in self.instance.imagedeployments_set.all()]
Scott Baker37b47902014-09-02 14:37:41 -0700494 self.fields['flavors'].initial = self.instance.flavors.all()
Scott Bakerde0f4412014-06-11 15:40:26 -0700495
496 def manipulate_m2m_objs(self, this_obj, selected_objs, all_relations, relation_class, local_attrname, foreign_attrname):
497 """ helper function for handling m2m relations from the MultipleChoiceField
498
499 this_obj: the source object we want to link from
500
501 selected_objs: a list of destination objects we want to link to
502
503 all_relations: the full set of relations involving this_obj, including ones we don't want
504
505 relation_class: the class that implements the relation from source to dest
506
507 local_attrname: field name representing this_obj in relation_class
508
509 foreign_attrname: field name representing selected_objs in relation_class
510
511 This function will remove all newobjclass relations from this_obj
512 that are not contained in selected_objs, and add any relations that
513 are in selected_objs but don't exist in the data model yet.
514 """
515
516 existing_dest_objs = []
517 for relation in list(all_relations):
518 if getattr(relation, foreign_attrname) not in selected_objs:
519 #print "deleting site", sdp.site
520 relation.delete()
521 else:
522 existing_dest_objs.append(getattr(relation, foreign_attrname))
523
524 for dest_obj in selected_objs:
525 if dest_obj not in existing_dest_objs:
526 #print "adding site", site
527 kwargs = {foreign_attrname: dest_obj, local_attrname: this_obj}
528 relation = relation_class(**kwargs)
529 relation.save()
Siobhan Tully320b4622014-01-17 15:11:14 -0500530
531 def save(self, commit=True):
532 deployment = super(DeploymentAdminForm, self).save(commit=False)
533
534 if commit:
535 deployment.save()
Scott Baker0057d052014-10-06 17:17:40 -0700536 # this has to be done after save() if/when a deployment is first created
537 deployment.flavors = self.cleaned_data['flavors']
Siobhan Tully320b4622014-01-17 15:11:14 -0500538
539 if deployment.pk:
Scott Bakerc9b14f72014-05-22 13:44:20 -0700540 # save_m2m() doesn't seem to work with 'through' relations. So we
541 # create/destroy the through models ourselves. There has to be
542 # a better way...
543
Scott Bakerde0f4412014-06-11 15:40:26 -0700544 self.manipulate_m2m_objs(deployment, self.cleaned_data['sites'], deployment.sitedeployments_set.all(), SiteDeployments, "deployment", "site")
545 self.manipulate_m2m_objs(deployment, self.cleaned_data['images'], deployment.imagedeployments_set.all(), ImageDeployments, "deployment", "image")
Scott Bakerc9b14f72014-05-22 13:44:20 -0700546
Scott Baker37b47902014-09-02 14:37:41 -0700547 self.save_m2m()
Siobhan Tully320b4622014-01-17 15:11:14 -0500548
549 return deployment
550
Scott Bakerff5e0f32014-05-22 14:40:27 -0700551class DeploymentAdminROForm(DeploymentAdminForm):
552 def save(self, commit=True):
553 raise PermissionDenied
554
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500555class SiteAssocInline(PlStackTabularInline):
556 model = Site.deployments.through
557 extra = 0
558 suit_classes = 'suit-tab suit-tab-sites'
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400559
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400560class DeploymentAdmin(PlanetStackBaseAdmin):
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500561 model = Deployment
Tony Macke75841e2014-09-29 16:10:52 -0400562 fieldList = ['backend_status_text', 'name', 'availability_zone', 'sites', 'images', 'flavors', 'accessControl']
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500563 fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-sites']})]
Scott Bakerde0f4412014-06-11 15:40:26 -0700564 inlines = [DeploymentPrivilegeInline,NodeInline,TagInline] # ,ImageDeploymentsInline]
Scott Baker63d1a552014-08-21 15:19:07 -0700565 list_display = ['backend_status_icon', 'name']
566 list_display_links = ('backend_status_icon', 'name', )
Scott Baker40c00762014-08-21 16:55:59 -0700567 readonly_fields = ('backend_status_text', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500568
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500569 user_readonly_fields = ['name']
570
Scott Bakerde0f4412014-06-11 15:40:26 -0700571 suit_form_tabs =(('sites','Deployment Details'),('nodes','Nodes'),('deploymentprivileges','Privileges'),('tags','Tags')) # ,('imagedeployments','Images'))
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500572
Scott Bakerff5e0f32014-05-22 14:40:27 -0700573 def get_form(self, request, obj=None, **kwargs):
574 if request.user.isReadOnlyUser():
575 kwargs["form"] = DeploymentAdminROForm
576 else:
577 kwargs["form"] = DeploymentAdminForm
Scott Baker5380c522014-06-06 14:49:43 -0700578 adminForm = super(DeploymentAdmin,self).get_form(request, obj, **kwargs)
579
580 # from stackexchange: pass the request object into the form
581
582 class AdminFormMetaClass(adminForm):
583 def __new__(cls, *args, **kwargs):
584 kwargs['request'] = request
585 return adminForm(*args, **kwargs)
586
587 return AdminFormMetaClass
588
Siobhan Tullyce652d02013-10-08 21:52:35 -0400589class ServiceAttrAsTabInline(PlStackTabularInline):
590 model = ServiceAttribute
591 fields = ['name','value']
592 extra = 0
593 suit_classes = 'suit-tab suit-tab-serviceattrs'
594
Siobhan Tullyce652d02013-10-08 21:52:35 -0400595class ServiceAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -0700596 list_display = ("backend_status_icon","name","description","versionNumber","enabled","published")
597 list_display_links = ('backend_status_icon', 'name', )
Scott Baker40c00762014-08-21 16:55:59 -0700598 fieldList = ["backend_status_text","name","description","versionNumber","enabled","published"]
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500599 fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})]
600 inlines = [ServiceAttrAsTabInline,SliceInline]
Scott Baker40c00762014-08-21 16:55:59 -0700601 readonly_fields = ('backend_status_text', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500602
603 user_readonly_fields = fieldList
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500604
605 suit_form_tabs =(('general', 'Service Details'),
606 ('slices','Slices'),
607 ('serviceattrs','Additional Attributes'),
608 )
Siobhan Tullyce652d02013-10-08 21:52:35 -0400609
Tony Mack0553f282013-06-10 22:54:50 -0400610class SiteAdmin(PlanetStackBaseAdmin):
Scott Baker40c00762014-08-21 16:55:59 -0700611 fieldList = ['backend_status_text', 'name', 'site_url', 'enabled', 'is_public', 'login_base', 'accountLink','location']
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400612 fieldsets = [
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500613 (None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),
Tony Macke4be32f2014-03-11 20:45:25 -0400614 #('Deployment Networks', {'fields': ['deployments'], 'classes':['suit-tab suit-tab-deployments']}),
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400615 ]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400616 suit_form_tabs =(('general', 'Site Details'),
617 ('users','Users'),
Siobhan Tully2d95e482013-09-06 10:56:06 -0400618 ('siteprivileges','Privileges'),
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400619 ('deployments','Deployments'),
620 ('slices','Slices'),
Scott Baker36f50872014-08-21 13:01:25 -0700621 ('nodes','Nodes'),
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400622 ('tags','Tags'),
623 )
Scott Baker40c00762014-08-21 16:55:59 -0700624 readonly_fields = ['backend_status_text', 'accountLink']
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500625
626 user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'accountLink']
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500627
Scott Baker63d1a552014-08-21 15:19:07 -0700628 list_display = ('backend_status_icon', 'name', 'login_base','site_url', 'enabled')
629 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400630 filter_horizontal = ('deployments',)
Tony Macke4be32f2014-03-11 20:45:25 -0400631 inlines = [SliceInline,UserInline,TagInline, NodeInline, SitePrivilegeInline, SiteDeploymentInline]
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400632 search_fields = ['name']
633
Tony Mack04062832013-05-10 08:22:44 -0400634 def queryset(self, request):
Tony Mack5b061472014-02-04 07:57:10 -0500635 return Site.select_by_user(request.user)
Tony Mack04062832013-05-10 08:22:44 -0400636
Tony Mack5cd13202013-05-01 21:48:38 -0400637 def get_formsets(self, request, obj=None):
638 for inline in self.get_inline_instances(request, obj):
639 # hide MyInline in the add view
640 if obj is None:
641 continue
Tony Mack2bd5b412013-06-11 21:05:06 -0400642 if isinstance(inline, SliceInline):
643 inline.model.caller = request.user
644 yield inline.get_formset(request, obj)
645
646 def get_formsets(self, request, obj=None):
647 for inline in self.get_inline_instances(request, obj):
648 # hide MyInline in the add view
649 if obj is None:
650 continue
651 if isinstance(inline, SliverInline):
652 inline.model.caller = request.user
Tony Mack5cd13202013-05-01 21:48:38 -0400653 yield inline.get_formset(request, obj)
654
Scott Baker545db2a2013-12-09 18:44:43 -0800655 def accountLink(self, obj):
656 link_obj = obj.accounts.all()
657 if link_obj:
658 reverse_path = "admin:core_account_change"
659 url = reverse(reverse_path, args =(link_obj[0].id,))
660 return "<a href='%s'>%s</a>" % (url, "view billing details")
661 else:
662 return "no billing data for this site"
663 accountLink.allow_tags = True
664 accountLink.short_description = "Billing"
665
Tony Mack332ee1d2014-02-04 15:33:45 -0500666 def save_model(self, request, obj, form, change):
667 # update openstack connection to use this site/tenant
668 obj.save_by_user(request.user)
669
670 def delete_model(self, request, obj):
671 obj.delete_by_user(request.user)
672
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500673
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400674class SitePrivilegeAdmin(PlanetStackBaseAdmin):
Scott Baker40c00762014-08-21 16:55:59 -0700675 fieldList = ['backend_status_text', 'user', 'site', 'role']
Tony Mack00d361f2013-04-28 10:28:42 -0400676 fieldsets = [
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500677 (None, {'fields': fieldList, 'classes':['collapse']})
Tony Mack00d361f2013-04-28 10:28:42 -0400678 ]
Scott Baker40c00762014-08-21 16:55:59 -0700679 readonly_fields = ('backend_status_text', )
Scott Baker63d1a552014-08-21 15:19:07 -0700680 list_display = ('backend_status_icon', 'user', 'site', 'role')
681 list_display_links = list_display
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500682 user_readonly_fields = fieldList
683 user_readonly_inlines = []
Tony Mack00d361f2013-04-28 10:28:42 -0400684
Tony Mackc2835a92013-05-28 09:18:49 -0400685 def formfield_for_foreignkey(self, db_field, request, **kwargs):
686 if db_field.name == 'site':
687 if not request.user.is_admin:
688 # only show sites where user is an admin or pi
689 sites = set()
690 for site_privilege in SitePrivilege.objects.filer(user=request.user):
691 if site_privilege.role.role_type in ['admin', 'pi']:
692 sites.add(site_privilege.site)
693 kwargs['queryset'] = Site.objects.filter(site__in=list(sites))
694
695 if db_field.name == 'user':
696 if not request.user.is_admin:
697 # only show users from sites where caller has admin or pi role
698 roles = Role.objects.filter(role_type__in=['admin', 'pi'])
699 site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles)
700 sites = [site_privilege.site for site_privilege in site_privileges]
701 site_privileges = SitePrivilege.objects.filter(site__in=sites)
702 emails = [site_privilege.user.email for site_privilege in site_privileges]
703 users = User.objects.filter(email__in=emails)
704 kwargs['queryset'] = users
705
706 return super(SitePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
707
Tony Mack04062832013-05-10 08:22:44 -0400708 def queryset(self, request):
709 # admins can see all privileges. Users can only see privileges at sites
Tony Mackc2835a92013-05-28 09:18:49 -0400710 # where they have the admin role or pi role.
Tony Mack04062832013-05-10 08:22:44 -0400711 qs = super(SitePrivilegeAdmin, self).queryset(request)
Tony Mack5b061472014-02-04 07:57:10 -0500712 #if not request.user.is_admin:
713 # roles = Role.objects.filter(role_type__in=['admin', 'pi'])
714 # site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles)
715 # login_bases = [site_privilege.site.login_base for site_privilege in site_privileges]
716 # sites = Site.objects.filter(login_base__in=login_bases)
717 # qs = qs.filter(site__in=sites)
Tony Mack04062832013-05-10 08:22:44 -0400718 return qs
719
Siobhan Tullyce652d02013-10-08 21:52:35 -0400720class SliceForm(forms.ModelForm):
721 class Meta:
722 model = Slice
723 widgets = {
Scott Baker36f50872014-08-21 13:01:25 -0700724 'service': LinkedSelect
Siobhan Tullyce652d02013-10-08 21:52:35 -0400725 }
726
Tony Macke75841e2014-09-29 16:10:52 -0400727 def clean(self):
728 cleaned_data = super(SliceForm, self).clean()
729 name = cleaned_data.get('name')
Scott Baker3cb382c2014-10-06 23:09:59 -0700730 site = cleaned_data.get('site')
731 if (not isinstance(site,Site)):
732 # previous code indicates 'site' could be a site_id and not a site?
733 site = Slice.objects.get(id=site.id)
Tony Macke75841e2014-09-29 16:10:52 -0400734 if not name.startswith(site.login_base):
735 raise forms.ValidationError('slice name must begin with %s' % site.login_base)
736 return cleaned_data
737
Tony Mack2bd5b412013-06-11 21:05:06 -0400738class SliceAdmin(PlanetStackBaseAdmin):
Siobhan Tullyce652d02013-10-08 21:52:35 -0400739 form = SliceForm
Tony Mackfbb26fc2014-09-02 07:03:27 -0400740 fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_slivers']
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500741 fieldsets = [('Slice Details', {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),]
Scott Baker40c00762014-08-21 16:55:59 -0700742 readonly_fields = ('backend_status_text', )
Tony Mack7d459902014-09-03 13:18:57 -0400743 list_display = ('backend_status_icon', 'name', 'site','serviceClass', 'slice_url', 'max_slivers')
744 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tully2d95e482013-09-06 10:56:06 -0400745 inlines = [SlicePrivilegeInline,SliverInline, TagInline, ReservationInline,SliceNetworkInline]
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400746
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500747 user_readonly_fields = fieldList
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400748
749 suit_form_tabs =(('general', 'Slice Details'),
Siobhan Tully2d95e482013-09-06 10:56:06 -0400750 ('slicenetworks','Networks'),
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400751 ('sliceprivileges','Privileges'),
752 ('slivers','Slivers'),
753 ('tags','Tags'),
754 ('reservations','Reservations'),
755 )
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400756
Scott Baker510fdbb2014-08-05 17:19:24 -0700757 def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
Scott Baker510fdbb2014-08-05 17:19:24 -0700758 deployment_nodes = []
759 for node in Node.objects.all():
760 deployment_nodes.append( (node.deployment.id, node.id, node.name) )
761
Scott Baker7a61dc42014-09-02 17:08:20 -0700762 deployment_flavors = []
763 for flavor in Flavor.objects.all():
764 for deployment in flavor.deployments.all():
765 deployment_flavors.append( (deployment.id, flavor.id, flavor.name) )
766
Scott Bakeraf36c4d2014-09-09 09:58:49 -0700767 deployment_images = []
768 for image in Image.objects.all():
769 for imageDeployment in image.imagedeployments_set.all():
770 deployment_images.append( (imageDeployment.deployment.id, image.id, image.name) )
771
Tony Mackec23b992014-09-02 21:18:45 -0400772 site_login_bases = []
773 for site in Site.objects.all():
Scott Bakeraf36c4d2014-09-09 09:58:49 -0700774 site_login_bases.append((site.id, site.login_base))
775
Scott Baker510fdbb2014-08-05 17:19:24 -0700776 context["deployment_nodes"] = deployment_nodes
Scott Baker7a61dc42014-09-02 17:08:20 -0700777 context["deployment_flavors"] = deployment_flavors
Scott Bakeraf36c4d2014-09-09 09:58:49 -0700778 context["deployment_images"] = deployment_images
Tony Mackec23b992014-09-02 21:18:45 -0400779 context["site_login_bases"] = site_login_bases
Scott Baker510fdbb2014-08-05 17:19:24 -0700780 return super(SliceAdmin, self).render_change_form(request, context, add, change, form_url, obj)
781
Tony Mackc2835a92013-05-28 09:18:49 -0400782 def formfield_for_foreignkey(self, db_field, request, **kwargs):
783 if db_field.name == 'site':
Tony Mack5b061472014-02-04 07:57:10 -0500784 kwargs['queryset'] = Site.select_by_user(request.user)
Tony Mackec23b992014-09-02 21:18:45 -0400785 kwargs['widget'] = forms.Select(attrs={'onChange': "update_slice_prefix(this, $($(this).closest('fieldset')[0]).find('.field-name input')[0].id)"})
Scott Baker40c00762014-08-21 16:55:59 -0700786
Tony Mackc2835a92013-05-28 09:18:49 -0400787 return super(SliceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
788
Tony Mack04062832013-05-10 08:22:44 -0400789 def queryset(self, request):
790 # admins can see all keys. Users can only see slices they belong to.
Tony Mack5b061472014-02-04 07:57:10 -0500791 return Slice.select_by_user(request.user)
Tony Mack04062832013-05-10 08:22:44 -0400792
Tony Mack79748612013-05-01 14:52:03 -0400793 def get_formsets(self, request, obj=None):
794 for inline in self.get_inline_instances(request, obj):
795 # hide MyInline in the add view
796 if obj is None:
797 continue
Tony Mack2bd5b412013-06-11 21:05:06 -0400798 if isinstance(inline, SliverInline):
799 inline.model.caller = request.user
Tony Mack79748612013-05-01 14:52:03 -0400800 yield inline.get_formset(request, obj)
801
Tony Mack192277c2014-10-07 17:20:30 -0400802 def save_model(self, request, obj, form, change):
803 obj.save()
804 # create default public slice networks
805 public_net = Network(
806 name = obj.name+'-public',
807 template = NetworkTemplate.objects.get(name='Public dedicated IPv4'),
808 owner = obj
809 )
810 public_net.save()
811 public_slice_net = NetworkSlice(network=public_net, slice=obj)
812 public_slice_net.save()
813 # create default private slice networks
814 private_net = Network(
815 name = obj.name+'-private',
816 template = NetworkTemplate.objects.get(name='Private'),
817 owner = obj
818 )
819 private_net.save()
820 private_slice_net = NetworkSlice(network=private_net, slice=obj)
821 private_slice_net.save()
822
823
Tony Mack2bd5b412013-06-11 21:05:06 -0400824
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400825class SlicePrivilegeAdmin(PlanetStackBaseAdmin):
Tony Mack00d361f2013-04-28 10:28:42 -0400826 fieldsets = [
Scott Baker40c00762014-08-21 16:55:59 -0700827 (None, {'fields': ['backend_status_text', 'user', 'slice', 'role']})
Tony Mack00d361f2013-04-28 10:28:42 -0400828 ]
Scott Baker40c00762014-08-21 16:55:59 -0700829 readonly_fields = ('backend_status_text', )
Scott Baker63d1a552014-08-21 15:19:07 -0700830 list_display = ('backend_status_icon', 'user', 'slice', 'role')
831 list_display_links = list_display
Tony Mack00d361f2013-04-28 10:28:42 -0400832
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500833 user_readonly_fields = ['user', 'slice', 'role']
834 user_readonly_inlines = []
835
Tony Mackc2835a92013-05-28 09:18:49 -0400836 def formfield_for_foreignkey(self, db_field, request, **kwargs):
837 if db_field.name == 'slice':
Tony Mack5b061472014-02-04 07:57:10 -0500838 kwargs['queryset'] = Slice.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400839
840 if db_field.name == 'user':
Tony Mack5b061472014-02-04 07:57:10 -0500841 kwargs['queryset'] = User.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400842
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400843 return super(SlicePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
Tony Mackc2835a92013-05-28 09:18:49 -0400844
Tony Mack04062832013-05-10 08:22:44 -0400845 def queryset(self, request):
846 # admins can see all memberships. Users can only see memberships of
847 # slices where they have the admin role.
Tony Mack5b061472014-02-04 07:57:10 -0500848 return SlicePrivilege.select_by_user(request.user)
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400849
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400850 def save_model(self, request, obj, form, change):
Tony Mack951dab42013-05-02 19:51:45 -0400851 # update openstack connection to use this site/tenant
852 auth = request.session.get('auth', {})
Tony Mackf7f79a12014-08-11 11:21:42 -0400853 auth['tenant'] = obj.slice.slicename
Tony Mack951dab42013-05-02 19:51:45 -0400854 obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400855 obj.save()
856
857 def delete_model(self, request, obj):
Tony Mack951dab42013-05-02 19:51:45 -0400858 # update openstack connection to use this site/tenant
859 auth = request.session.get('auth', {})
Tony Mackf7f79a12014-08-11 11:21:42 -0400860 auth['tenant'] = obj.slice.slicename
Tony Mack951dab42013-05-02 19:51:45 -0400861 obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400862 obj.delete()
863
Siobhan Tully567e3e62013-06-21 18:03:16 -0400864
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400865class ImageAdmin(PlanetStackBaseAdmin):
866
Scott Baker36f50872014-08-21 13:01:25 -0700867 fieldsets = [('Image Details',
Scott Baker40c00762014-08-21 16:55:59 -0700868 {'fields': ['backend_status_text', 'name', 'disk_format', 'container_format'],
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400869 'classes': ['suit-tab suit-tab-general']})
870 ]
Scott Baker40c00762014-08-21 16:55:59 -0700871 readonly_fields = ('backend_status_text', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400872
Scott Baker2170b972014-06-03 12:14:07 -0700873 suit_form_tabs =(('general','Image Details'),('slivers','Slivers'),('imagedeployments','Deployments'))
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400874
Scott Baker2170b972014-06-03 12:14:07 -0700875 inlines = [SliverInline, ImageDeploymentsInline]
Scott Bakerb6f99242014-06-11 11:34:44 -0700876
Tony Mack32e1ce32014-05-07 13:29:41 -0400877 user_readonly_fields = ['name', 'disk_format', 'container_format']
Scott Bakerb27b62c2014-08-15 16:29:16 -0700878
Scott Baker63d1a552014-08-21 15:19:07 -0700879 list_display = ['backend_status_icon', 'name']
880 list_display_links = ('backend_status_icon', 'name', )
881
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400882class NodeForm(forms.ModelForm):
883 class Meta:
884 widgets = {
885 'site': LinkedSelect,
886 'deployment': LinkedSelect
887 }
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400888
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500889class NodeAdmin(PlanetStackBaseAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400890 form = NodeForm
Scott Baker63d1a552014-08-21 15:19:07 -0700891 list_display = ('backend_status_icon', 'name', 'site', 'deployment')
892 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400893 list_filter = ('deployment',)
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500894
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400895 inlines = [TagInline,SliverInline]
Scott Baker40c00762014-08-21 16:55:59 -0700896 fieldsets = [('Node Details', {'fields': ['backend_status_text', 'name','site','deployment'], 'classes':['suit-tab suit-tab-details']})]
897 readonly_fields = ('backend_status_text', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400898
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500899 user_readonly_fields = ['name','site','deployment']
900 user_readonly_inlines = [TagInline,SliverInline]
901
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400902 suit_form_tabs =(('details','Node Details'),('slivers','Slivers'),('tags','Tags'))
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400903
Siobhan Tully567e3e62013-06-21 18:03:16 -0400904
Tony Mackd90cdbf2013-04-16 22:48:40 -0400905class SliverForm(forms.ModelForm):
906 class Meta:
Tony Mack1d6b85f2013-05-07 18:49:14 -0400907 model = Sliver
Tony Mackd90cdbf2013-04-16 22:48:40 -0400908 ip = forms.CharField(widget=PlainTextWidget)
Tony Mack18261812013-05-02 16:39:20 -0400909 instance_name = forms.CharField(widget=PlainTextWidget)
Tony Mackd90cdbf2013-04-16 22:48:40 -0400910 widgets = {
911 'ip': PlainTextWidget(),
Tony Mack18261812013-05-02 16:39:20 -0400912 'instance_name': PlainTextWidget(),
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400913 'slice': LinkedSelect,
914 'deploymentNetwork': LinkedSelect,
915 'node': LinkedSelect,
916 'image': LinkedSelect
Siobhan Tully53437282013-04-26 19:30:27 -0400917 }
Tony Mackd90cdbf2013-04-16 22:48:40 -0400918
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500919class TagAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -0700920 list_display = ['backend_status_icon', 'service', 'name', 'value', 'content_type', 'content_object',]
921 list_display_links = list_display
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500922 user_readonly_fields = ['service', 'name', 'value', 'content_type', 'content_object',]
923 user_readonly_inlines = []
Siobhan Tullyd3515752013-06-21 16:34:53 -0400924
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400925class SliverAdmin(PlanetStackBaseAdmin):
Tony Mackd90cdbf2013-04-16 22:48:40 -0400926 form = SliverForm
Tony Mackcdec0902013-04-15 00:38:49 -0400927 fieldsets = [
Scott Baker7a61dc42014-09-02 17:08:20 -0700928 ('Sliver Details', {'fields': ['backend_status_text', 'slice', 'deploymentNetwork', 'node', 'ip', 'instance_name', 'flavor', 'image', ], 'classes': ['suit-tab suit-tab-general'], })
Tony Mackcdec0902013-04-15 00:38:49 -0400929 ]
Scott Baker40c00762014-08-21 16:55:59 -0700930 readonly_fields = ('backend_status_text', )
Scott Baker7a61dc42014-09-02 17:08:20 -0700931 list_display = ['backend_status_icon', 'ip', 'instance_name', 'slice', 'flavor', 'image', 'node', 'deploymentNetwork']
Scott Baker63d1a552014-08-21 15:19:07 -0700932 list_display_links = ('backend_status_icon', 'ip',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400933
934 suit_form_tabs =(('general', 'Sliver Details'),
935 ('tags','Tags'),
936 )
937
Siobhan Tullyde5450d2013-06-21 11:35:33 -0400938 inlines = [TagInline]
Tony Mack53106f32013-04-27 16:43:01 -0400939
Scott Baker7a61dc42014-09-02 17:08:20 -0700940 user_readonly_fields = ['slice', 'deploymentNetwork', 'node', 'ip', 'instance_name', 'flavor', 'image']
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500941
Tony Mackc2835a92013-05-28 09:18:49 -0400942 def formfield_for_foreignkey(self, db_field, request, **kwargs):
943 if db_field.name == 'slice':
Tony Mack5b061472014-02-04 07:57:10 -0500944 kwargs['queryset'] = Slice.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400945
946 return super(SliverAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
947
Tony Mack04062832013-05-10 08:22:44 -0400948 def queryset(self, request):
Scott Baker36f50872014-08-21 13:01:25 -0700949 # admins can see all slivers. Users can only see slivers of
Tony Mack04062832013-05-10 08:22:44 -0400950 # the slices they belong to.
Tony Mack5b061472014-02-04 07:57:10 -0500951 return Sliver.select_by_user(request.user)
952
Tony Mack04062832013-05-10 08:22:44 -0400953
Tony Mack1d6b85f2013-05-07 18:49:14 -0400954 def get_formsets(self, request, obj=None):
955 # make some fields read only if we are updating an existing record
956 if obj == None:
Scott Baker36f50872014-08-21 13:01:25 -0700957 #self.readonly_fields = ('ip', 'instance_name')
Scott Baker40c00762014-08-21 16:55:59 -0700958 self.readonly_fields = ('backend_status_text')
Tony Mack1d6b85f2013-05-07 18:49:14 -0400959 else:
Scott Baker40c00762014-08-21 16:55:59 -0700960 self.readonly_fields = ('backend_status_text')
Scott Baker36f50872014-08-21 13:01:25 -0700961 #self.readonly_fields = ('ip', 'instance_name', 'slice', 'image', 'key')
Tony Mack1d6b85f2013-05-07 18:49:14 -0400962
963 for inline in self.get_inline_instances(request, obj):
964 # hide MyInline in the add view
965 if obj is None:
966 continue
Scott Baker526b71e2014-05-13 13:18:01 -0700967 if isinstance(inline, SliverInline):
968 inline.model.caller = request.user
969 yield inline.get_formset(request, obj)
Tony Mack53106f32013-04-27 16:43:01 -0400970
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500971 #def save_model(self, request, obj, form, change):
972 # # update openstack connection to use this site/tenant
973 # auth = request.session.get('auth', {})
974 # auth['tenant'] = obj.slice.name
975 # obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
976 # obj.creator = request.user
977 # obj.save()
Tony Mack53106f32013-04-27 16:43:01 -0400978
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500979 #def delete_model(self, request, obj):
980 # # update openstack connection to use this site/tenant
981 # auth = request.session.get('auth', {})
982 # auth['tenant'] = obj.slice.name
983 # obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
984 # obj.delete()
Tony Mackcdec0902013-04-15 00:38:49 -0400985
Siobhan Tully53437282013-04-26 19:30:27 -0400986class UserCreationForm(forms.ModelForm):
987 """A form for creating new users. Includes all the required
988 fields, plus a repeated password."""
989 password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
990 password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
991
992 class Meta:
Siobhan Tully30fd4292013-05-10 08:59:56 -0400993 model = User
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400994 fields = ('email', 'firstname', 'lastname', 'phone', 'public_key')
Siobhan Tully53437282013-04-26 19:30:27 -0400995
996 def clean_password2(self):
997 # Check that the two password entries match
998 password1 = self.cleaned_data.get("password1")
999 password2 = self.cleaned_data.get("password2")
1000 if password1 and password2 and password1 != password2:
1001 raise forms.ValidationError("Passwords don't match")
1002 return password2
1003
1004 def save(self, commit=True):
1005 # Save the provided password in hashed format
1006 user = super(UserCreationForm, self).save(commit=False)
Tony Mackf9f4afb2013-05-01 21:02:12 -04001007 user.password = self.cleaned_data["password1"]
1008 #user.set_password(self.cleaned_data["password1"])
Siobhan Tully53437282013-04-26 19:30:27 -04001009 if commit:
1010 user.save()
1011 return user
1012
Siobhan Tully567e3e62013-06-21 18:03:16 -04001013
Siobhan Tully53437282013-04-26 19:30:27 -04001014class UserChangeForm(forms.ModelForm):
1015 """A form for updating users. Includes all the fields on
1016 the user, but replaces the password field with admin's
1017 password hash display field.
1018 """
Siobhan Tully63b7ba42014-01-12 10:35:11 -05001019 password = ReadOnlyPasswordHashField(label='Password',
1020 help_text= '<a href=\"password/\">Change Password</a>.')
Siobhan Tully53437282013-04-26 19:30:27 -04001021
1022 class Meta:
Siobhan Tully30fd4292013-05-10 08:59:56 -04001023 model = User
Siobhan Tully53437282013-04-26 19:30:27 -04001024
1025 def clean_password(self):
1026 # Regardless of what the user provides, return the initial value.
1027 # This is done here, rather than on the field, because the
1028 # field does not have access to the initial value
1029 return self.initial["password"]
1030
Scott Baker2c3cb642014-05-19 17:55:56 -07001031class UserDashboardViewInline(PlStackTabularInline):
1032 model = UserDashboardView
1033 extra = 0
1034 suit_classes = 'suit-tab suit-tab-dashboards'
1035 fields = ['user', 'dashboardView', 'order']
1036
Scott Bakerf4aeedc2014-10-03 13:10:47 -07001037class UserAdmin(PermissionCheckingAdminMixin, UserAdmin):
1038 # Note: Make sure PermissionCheckingAdminMixin is listed before
1039 # admin.ModelAdmin in the class declaration.
1040
Siobhan Tully53437282013-04-26 19:30:27 -04001041 class Meta:
1042 app_label = "core"
1043
1044 # The forms to add and change user instances
1045 form = UserChangeForm
1046 add_form = UserCreationForm
1047
1048 # The fields to be used in displaying the User model.
1049 # These override the definitions on the base UserAdmin
1050 # that reference specific fields on auth.User.
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001051 list_display = ('email', 'firstname', 'lastname', 'site', 'last_login')
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001052 list_filter = ('site',)
Scott Baker2c3cb642014-05-19 17:55:56 -07001053 inlines = [SlicePrivilegeInline,SitePrivilegeInline,DeploymentPrivilegeInline,UserDashboardViewInline]
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001054
Scott Baker1a6a3902014-10-03 00:32:37 -07001055 fieldListLoginDetails = ['backend_status_text', 'email','site','password','is_active','is_readonly','is_admin','public_key']
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001056 fieldListContactInfo = ['firstname','lastname','phone','timezone']
1057
Siobhan Tully53437282013-04-26 19:30:27 -04001058 fieldsets = (
Scott Baker40c00762014-08-21 16:55:59 -07001059 ('Login Details', {'fields': ['backend_status_text', 'email', 'site','password', 'is_active', 'is_readonly', 'is_admin', 'public_key'], 'classes':['suit-tab suit-tab-general']}),
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001060 ('Contact Information', {'fields': ('firstname','lastname','phone', 'timezone'), 'classes':['suit-tab suit-tab-contact']}),
Scott Baker2c3cb642014-05-19 17:55:56 -07001061 #('Dashboard Views', {'fields': ('dashboards',), 'classes':['suit-tab suit-tab-dashboards']}),
Siobhan Tully53437282013-04-26 19:30:27 -04001062 #('Important dates', {'fields': ('last_login',)}),
1063 )
1064 add_fieldsets = (
1065 (None, {
1066 'classes': ('wide',),
Scott Baker6a995352014-10-06 17:51:20 -07001067 'fields': ('email', 'firstname', 'lastname', 'is_readonly', 'phone', 'public_key','password1', 'password2')},
Siobhan Tully53437282013-04-26 19:30:27 -04001068 ),
1069 )
Scott Baker40c00762014-08-21 16:55:59 -07001070 readonly_fields = ('backend_status_text', )
Siobhan Tully53437282013-04-26 19:30:27 -04001071 search_fields = ('email',)
1072 ordering = ('email',)
1073 filter_horizontal = ()
1074
Scott Baker3ca51f62014-05-23 12:05:11 -07001075 user_readonly_fields = fieldListLoginDetails + fieldListContactInfo
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001076
Scott Baker6a995352014-10-06 17:51:20 -07001077 def get_form(self, request, obj=None):
1078 # Save obj in thread-local storage, so suit_form_tabs can use it to
1079 # determine whether we're in edit or add mode.
1080 _thread_locals.request = request
1081 _thread_locals.obj = obj
1082 return super(UserAdmin, self).get_form(request, obj)
1083
1084 @property
1085 def suit_form_tabs(self):
1086 if getattr(_thread_locals, "obj", None) is None:
1087 return []
1088 else:
1089 return (('general','Login Details'),
1090 ('contact','Contact Information'),
1091 ('sliceprivileges','Slice Privileges'),
1092 ('siteprivileges','Site Privileges'),
1093 ('deploymentprivileges','Deployment Privileges'),
1094 ('dashboards','Dashboard Views'))
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001095
Tony Mackc2835a92013-05-28 09:18:49 -04001096 def formfield_for_foreignkey(self, db_field, request, **kwargs):
1097 if db_field.name == 'site':
Tony Mack5b061472014-02-04 07:57:10 -05001098 kwargs['queryset'] = Site.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -04001099
1100 return super(UserAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
1101
Tony Mack5b061472014-02-04 07:57:10 -05001102 def queryset(self, request):
1103 return User.select_by_user(request.user)
1104
Scott Baker2c3cb642014-05-19 17:55:56 -07001105class DashboardViewAdmin(PlanetStackBaseAdmin):
1106 fieldsets = [('Dashboard View Details',
Scott Baker40c00762014-08-21 16:55:59 -07001107 {'fields': ['backend_status_text', 'name', 'url'],
Scott Baker2c3cb642014-05-19 17:55:56 -07001108 'classes': ['suit-tab suit-tab-general']})
1109 ]
Scott Baker40c00762014-08-21 16:55:59 -07001110 readonly_fields = ('backend_status_text', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001111
Scott Baker2c3cb642014-05-19 17:55:56 -07001112 suit_form_tabs =(('general','Dashboard View Details'),)
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001113
Scott Baker0165fac2014-01-13 11:49:26 -08001114class ServiceResourceInline(PlStackTabularInline):
Scott Baker3de3e372013-05-10 16:50:44 -07001115 model = ServiceResource
1116 extra = 0
1117
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001118class ServiceClassAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001119 list_display = ('backend_status_icon', 'name', 'commitment', 'membershipFee')
1120 list_display_links = ('backend_status_icon', 'name', )
Scott Baker3de3e372013-05-10 16:50:44 -07001121 inlines = [ServiceResourceInline]
1122
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001123 user_readonly_fields = ['name', 'commitment', 'membershipFee']
1124 user_readonly_inlines = []
1125
Scott Baker0165fac2014-01-13 11:49:26 -08001126class ReservedResourceInline(PlStackTabularInline):
Scott Baker133c9212013-05-17 09:09:11 -07001127 model = ReservedResource
1128 extra = 0
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001129 suit_classes = 'suit-tab suit-tab-reservedresources'
Scott Baker133c9212013-05-17 09:09:11 -07001130
1131 def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
1132 field = super(ReservedResourceInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
1133
1134 if db_field.name == 'resource':
1135 # restrict resources to those that the slice's service class allows
1136 if request._slice is not None:
1137 field.queryset = field.queryset.filter(serviceClass = request._slice.serviceClass, calendarReservable=True)
1138 if len(field.queryset) > 0:
1139 field.initial = field.queryset.all()[0]
1140 else:
1141 field.queryset = field.queryset.none()
1142 elif db_field.name == 'sliver':
1143 # restrict slivers to those that belong to the slice
1144 if request._slice is not None:
1145 field.queryset = field.queryset.filter(slice = request._slice)
1146 else:
1147 field.queryset = field.queryset.none()
1148
1149 return field
1150
Tony Mack5b061472014-02-04 07:57:10 -05001151 def queryset(self, request):
1152 return ReservedResource.select_by_user(request.user)
1153
Scott Baker133c9212013-05-17 09:09:11 -07001154class ReservationChangeForm(forms.ModelForm):
1155 class Meta:
1156 model = Reservation
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001157 widgets = {
1158 'slice' : LinkedSelect
1159 }
Scott Baker133c9212013-05-17 09:09:11 -07001160
1161class ReservationAddForm(forms.ModelForm):
1162 slice = forms.ModelChoiceField(queryset=Slice.objects.all(), widget=forms.Select(attrs={"onChange":"document.getElementById('id_refresh').value=1; submit()"}))
1163 refresh = forms.CharField(widget=forms.HiddenInput())
1164
1165 class Media:
1166 css = {'all': ('planetstack.css',)} # .field-refresh { display: none; }
1167
1168 def clean_slice(self):
1169 slice = self.cleaned_data.get("slice")
1170 x = ServiceResource.objects.filter(serviceClass = slice.serviceClass, calendarReservable=True)
1171 if len(x) == 0:
1172 raise forms.ValidationError("The slice you selected does not have a service class that allows reservations")
1173 return slice
1174
1175 class Meta:
1176 model = Reservation
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001177 widgets = {
1178 'slice' : LinkedSelect
1179 }
1180
Scott Baker133c9212013-05-17 09:09:11 -07001181
1182class ReservationAddRefreshForm(ReservationAddForm):
1183 """ This form is displayed when the Reservation Form receives an update
1184 from the Slice dropdown onChange handler. It doesn't validate the
1185 data and doesn't save the data. This will cause the form to be
1186 redrawn.
1187 """
1188
Scott Baker8737e5f2013-05-17 09:35:32 -07001189 """ don't validate anything other than slice """
1190 dont_validate_fields = ("startTime", "duration")
1191
Scott Baker133c9212013-05-17 09:09:11 -07001192 def full_clean(self):
1193 result = super(ReservationAddForm, self).full_clean()
Scott Baker8737e5f2013-05-17 09:35:32 -07001194
1195 for fieldname in self.dont_validate_fields:
1196 if fieldname in self._errors:
1197 del self._errors[fieldname]
1198
Scott Baker133c9212013-05-17 09:09:11 -07001199 return result
1200
1201 """ don't save anything """
1202 def is_valid(self):
1203 return False
1204
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001205class ReservationAdmin(PlanetStackBaseAdmin):
Scott Baker40c00762014-08-21 16:55:59 -07001206 fieldList = ['backend_status_text', 'slice', 'startTime', 'duration']
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001207 fieldsets = [('Reservation Details', {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
Scott Baker40c00762014-08-21 16:55:59 -07001208 readonly_fields = ('backend_status_text', )
Scott Baker133c9212013-05-17 09:09:11 -07001209 list_display = ('startTime', 'duration')
Scott Baker133c9212013-05-17 09:09:11 -07001210 form = ReservationAddForm
1211
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001212 suit_form_tabs = (('general','Reservation Details'), ('reservedresources','Reserved Resources'))
1213
1214 inlines = [ReservedResourceInline]
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001215 user_readonly_fields = fieldList
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001216
Scott Baker133c9212013-05-17 09:09:11 -07001217 def add_view(self, request, form_url='', extra_context=None):
Scott Bakeracd45142013-05-19 16:19:16 -07001218 timezone.activate(request.user.timezone)
Scott Baker133c9212013-05-17 09:09:11 -07001219 request._refresh = False
1220 request._slice = None
1221 if request.method == 'POST':
Scott Baker8737e5f2013-05-17 09:35:32 -07001222 # "refresh" will be set to "1" if the form was submitted due to
1223 # a change in the Slice dropdown.
Scott Baker133c9212013-05-17 09:09:11 -07001224 if request.POST.get("refresh","1") == "1":
1225 request._refresh = True
1226 request.POST["refresh"] = "0"
Scott Baker8737e5f2013-05-17 09:35:32 -07001227
1228 # Keep track of the slice that was selected, so the
1229 # reservedResource inline can filter items for the slice.
Scott Baker133c9212013-05-17 09:09:11 -07001230 request._slice = request.POST.get("slice",None)
1231 if (request._slice is not None):
1232 request._slice = Slice.objects.get(id=request._slice)
1233
1234 result = super(ReservationAdmin, self).add_view(request, form_url, extra_context)
1235 return result
1236
Scott Bakeracd45142013-05-19 16:19:16 -07001237 def changelist_view(self, request, extra_context = None):
1238 timezone.activate(request.user.timezone)
1239 return super(ReservationAdmin, self).changelist_view(request, extra_context)
1240
Scott Baker133c9212013-05-17 09:09:11 -07001241 def get_form(self, request, obj=None, **kwargs):
Siobhan Tullyd3515752013-06-21 16:34:53 -04001242 request._obj_ = obj
1243 if obj is not None:
1244 # For changes, set request._slice to the slice already set in the
1245 # object.
1246 request._slice = obj.slice
1247 self.form = ReservationChangeForm
1248 else:
1249 if getattr(request, "_refresh", False):
1250 self.form = ReservationAddRefreshForm
1251 else:
1252 self.form = ReservationAddForm
1253 return super(ReservationAdmin, self).get_form(request, obj, **kwargs)
1254
Scott Baker133c9212013-05-17 09:09:11 -07001255 def get_readonly_fields(self, request, obj=None):
Siobhan Tullyd3515752013-06-21 16:34:53 -04001256 if (obj is not None):
1257 # Prevent slice from being changed after the reservation has been
1258 # created.
1259 return ['slice']
1260 else:
Scott Baker133c9212013-05-17 09:09:11 -07001261 return []
Scott Baker3de3e372013-05-10 16:50:44 -07001262
Tony Mack5b061472014-02-04 07:57:10 -05001263 def queryset(self, request):
1264 return Reservation.select_by_user(request.user)
1265
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001266class NetworkParameterTypeAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001267 list_display = ("backend_status_icon", "name", )
1268 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001269 user_readonly_fields = ['name']
1270 user_readonly_inlines = []
Scott Baker74d8e622013-07-29 16:04:22 -07001271
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001272class RouterAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001273 list_display = ("backend_status_icon", "name", )
1274 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001275 user_readonly_fields = ['name']
1276 user_readonly_inlines = []
1277
Scott Baker0165fac2014-01-13 11:49:26 -08001278class RouterInline(PlStackTabularInline):
Scott Baker74d8e622013-07-29 16:04:22 -07001279 model = Router.networks.through
1280 extra = 0
1281 verbose_name_plural = "Routers"
1282 verbose_name = "Router"
Siobhan Tully2d95e482013-09-06 10:56:06 -04001283 suit_classes = 'suit-tab suit-tab-routers'
Scott Baker74d8e622013-07-29 16:04:22 -07001284
Scott Bakerb27b62c2014-08-15 16:29:16 -07001285class NetworkParameterInline(PlStackGenericTabularInline):
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001286 model = NetworkParameter
Scott Baker618e3792014-08-15 13:42:29 -07001287 extra = 0
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001288 verbose_name_plural = "Parameters"
1289 verbose_name = "Parameter"
1290 suit_classes = 'suit-tab suit-tab-netparams'
Scott Baker40c00762014-08-21 16:55:59 -07001291 fields = ['backend_status_icon', 'parameter', 'value']
1292 readonly_fields = ('backend_status_icon', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001293
Scott Baker0165fac2014-01-13 11:49:26 -08001294class NetworkSliversInline(PlStackTabularInline):
Scott Baker40c00762014-08-21 16:55:59 -07001295 fields = ['backend_status_icon', 'network','sliver','ip']
1296 readonly_fields = ("backend_status_icon", "ip", )
Scott Baker74d8e622013-07-29 16:04:22 -07001297 model = NetworkSliver
Scott Baker874936e2014-01-13 18:15:34 -08001298 selflink_fieldname = "sliver"
Scott Baker74d8e622013-07-29 16:04:22 -07001299 extra = 0
1300 verbose_name_plural = "Slivers"
1301 verbose_name = "Sliver"
Siobhan Tully2d95e482013-09-06 10:56:06 -04001302 suit_classes = 'suit-tab suit-tab-networkslivers'
Scott Baker74d8e622013-07-29 16:04:22 -07001303
Scott Baker0165fac2014-01-13 11:49:26 -08001304class NetworkSlicesInline(PlStackTabularInline):
Scott Bakerd7d2a392013-08-06 08:57:30 -07001305 model = NetworkSlice
Scott Baker874936e2014-01-13 18:15:34 -08001306 selflink_fieldname = "slice"
Scott Bakerd7d2a392013-08-06 08:57:30 -07001307 extra = 0
1308 verbose_name_plural = "Slices"
1309 verbose_name = "Slice"
Siobhan Tully2d95e482013-09-06 10:56:06 -04001310 suit_classes = 'suit-tab suit-tab-networkslices'
Scott Baker40c00762014-08-21 16:55:59 -07001311 fields = ['backend_status_icon', 'network','slice']
1312 readonly_fields = ('backend_status_icon', )
Scott Bakerd7d2a392013-08-06 08:57:30 -07001313
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001314class NetworkAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001315 list_display = ("backend_status_icon", "name", "subnet", "ports", "labels")
1316 list_display_links = ('backend_status_icon', 'name', )
Scott Baker74d8e622013-07-29 16:04:22 -07001317 readonly_fields = ("subnet", )
Siobhan Tully2d95e482013-09-06 10:56:06 -04001318
Scott Bakerd7d2a392013-08-06 08:57:30 -07001319 inlines = [NetworkParameterInline, NetworkSliversInline, NetworkSlicesInline, RouterInline]
Scott Baker74d8e622013-07-29 16:04:22 -07001320
Siobhan Tully2d95e482013-09-06 10:56:06 -04001321 fieldsets = [
Scott Baker40c00762014-08-21 16:55:59 -07001322 (None, {'fields': ['backend_status_text', 'name','template','ports','labels','owner','guaranteedBandwidth', 'permitAllSlices','permittedSlices','network_id','router_id','subnet_id','subnet'], 'classes':['suit-tab suit-tab-general']}),]
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001323
Scott Baker40c00762014-08-21 16:55:59 -07001324 readonly_fields = ('backend_status_text', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001325 user_readonly_fields = ['name','template','ports','labels','owner','guaranteedBandwidth', 'permitAllSlices','permittedSlices','network_id','router_id','subnet_id','subnet']
Siobhan Tully2d95e482013-09-06 10:56:06 -04001326
1327 suit_form_tabs =(
1328 ('general','Network Details'),
1329 ('netparams', 'Parameters'),
1330 ('networkslivers','Slivers'),
1331 ('networkslices','Slices'),
1332 ('routers','Routers'),
1333 )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001334class NetworkTemplateAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001335 list_display = ("backend_status_icon", "name", "guaranteedBandwidth", "visibility")
1336 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001337 user_readonly_fields = ["name", "guaranteedBandwidth", "visibility"]
1338 user_readonly_inlines = []
Scott Baker74d8e622013-07-29 16:04:22 -07001339
Scott Baker37b47902014-09-02 14:37:41 -07001340class FlavorAdmin(PlanetStackBaseAdmin):
1341 list_display = ("backend_status_icon", "name", "flavor", "order", "default")
1342 list_display_links = ("backend_status_icon", "name")
1343 user_readonly_fields = ("name", "flavor")
1344 fields = ("name", "description", "flavor", "order", "default")
1345
Tony Mack31c2b8f2013-04-26 20:01:42 -04001346# register a signal that caches the user's credentials when they log in
1347def cache_credentials(sender, user, request, **kwds):
1348 auth = {'username': request.POST['username'],
1349 'password': request.POST['password']}
1350 request.session['auth'] = auth
1351user_logged_in.connect(cache_credentials)
1352
Scott Baker15cddfa2013-12-09 13:45:19 -08001353def dollar_field(fieldName, short_description):
1354 def newFunc(self, obj):
1355 try:
1356 x= "$ %0.2f" % float(getattr(obj, fieldName, 0.0))
1357 except:
1358 x=getattr(obj, fieldName, 0.0)
1359 return x
1360 newFunc.short_description = short_description
1361 return newFunc
1362
1363def right_dollar_field(fieldName, short_description):
1364 def newFunc(self, obj):
1365 try:
1366 #x= '<div align=right style="width:6em">$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0))
1367 x= '<div align=right>$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0))
1368 except:
1369 x=getattr(obj, fieldName, 0.0)
1370 return x
1371 newFunc.short_description = short_description
1372 newFunc.allow_tags = True
1373 return newFunc
Scott Baker43105042013-12-06 23:23:36 -08001374
Scott Baker0165fac2014-01-13 11:49:26 -08001375class InvoiceChargeInline(PlStackTabularInline):
Scott Baker43105042013-12-06 23:23:36 -08001376 model = Charge
Scott Baker15cddfa2013-12-09 13:45:19 -08001377 extra = 0
Scott Baker43105042013-12-06 23:23:36 -08001378 verbose_name_plural = "Charges"
1379 verbose_name = "Charge"
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001380 exclude = ['account']
Scott Baker9cb88a22013-12-09 18:56:00 -08001381 fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
1382 readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
1383 can_delete = False
1384 max_num = 0
1385
1386 dollar_amount = right_dollar_field("amount", "Amount")
Scott Baker43105042013-12-06 23:23:36 -08001387
1388class InvoiceAdmin(admin.ModelAdmin):
1389 list_display = ("date", "account")
1390
1391 inlines = [InvoiceChargeInline]
1392
Scott Baker9cb88a22013-12-09 18:56:00 -08001393 fields = ["date", "account", "dollar_amount"]
1394 readonly_fields = ["date", "account", "dollar_amount"]
1395
1396 dollar_amount = dollar_field("amount", "Amount")
Scott Baker43105042013-12-06 23:23:36 -08001397
Scott Baker0165fac2014-01-13 11:49:26 -08001398class InvoiceInline(PlStackTabularInline):
Scott Baker15cddfa2013-12-09 13:45:19 -08001399 model = Invoice
1400 extra = 0
1401 verbose_name_plural = "Invoices"
1402 verbose_name = "Invoice"
Scott Baker0165fac2014-01-13 11:49:26 -08001403 fields = ["date", "dollar_amount"]
1404 readonly_fields = ["date", "dollar_amount"]
Scott Baker15cddfa2013-12-09 13:45:19 -08001405 suit_classes = 'suit-tab suit-tab-accountinvoice'
1406 can_delete=False
1407 max_num=0
1408
1409 dollar_amount = right_dollar_field("amount", "Amount")
1410
Scott Baker0165fac2014-01-13 11:49:26 -08001411class PendingChargeInline(PlStackTabularInline):
Scott Baker43105042013-12-06 23:23:36 -08001412 model = Charge
Scott Baker15cddfa2013-12-09 13:45:19 -08001413 extra = 0
Scott Baker43105042013-12-06 23:23:36 -08001414 verbose_name_plural = "Charges"
1415 verbose_name = "Charge"
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001416 exclude = ["invoice"]
Scott Baker15cddfa2013-12-09 13:45:19 -08001417 fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
1418 readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
Scott Baker43105042013-12-06 23:23:36 -08001419 suit_classes = 'suit-tab suit-tab-accountpendingcharges'
Scott Baker15cddfa2013-12-09 13:45:19 -08001420 can_delete=False
1421 max_num=0
Scott Baker43105042013-12-06 23:23:36 -08001422
1423 def queryset(self, request):
1424 qs = super(PendingChargeInline, self).queryset(request)
1425 qs = qs.filter(state="pending")
1426 return qs
1427
Scott Baker15cddfa2013-12-09 13:45:19 -08001428 dollar_amount = right_dollar_field("amount", "Amount")
1429
Scott Baker0165fac2014-01-13 11:49:26 -08001430class PaymentInline(PlStackTabularInline):
Scott Baker43105042013-12-06 23:23:36 -08001431 model=Payment
1432 extra = 1
1433 verbose_name_plural = "Payments"
1434 verbose_name = "Payment"
Scott Baker15cddfa2013-12-09 13:45:19 -08001435 fields = ["date", "dollar_amount"]
1436 readonly_fields = ["date", "dollar_amount"]
Scott Baker43105042013-12-06 23:23:36 -08001437 suit_classes = 'suit-tab suit-tab-accountpayments'
Scott Baker15cddfa2013-12-09 13:45:19 -08001438 can_delete=False
1439 max_num=0
1440
1441 dollar_amount = right_dollar_field("amount", "Amount")
1442
Scott Baker43105042013-12-06 23:23:36 -08001443class AccountAdmin(admin.ModelAdmin):
1444 list_display = ("site", "balance_due")
1445
1446 inlines = [InvoiceInline, PaymentInline, PendingChargeInline]
1447
1448 fieldsets = [
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001449 (None, {'fields': ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'],'classes':['suit-tab suit-tab-general']}),]
Scott Baker43105042013-12-06 23:23:36 -08001450
Scott Baker15cddfa2013-12-09 13:45:19 -08001451 readonly_fields = ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments']
Scott Baker43105042013-12-06 23:23:36 -08001452
1453 suit_form_tabs =(
1454 ('general','Account Details'),
1455 ('accountinvoice', 'Invoices'),
1456 ('accountpayments', 'Payments'),
1457 ('accountpendingcharges','Pending Charges'),
1458 )
1459
Scott Baker15cddfa2013-12-09 13:45:19 -08001460 dollar_balance_due = dollar_field("balance_due", "Balance Due")
1461 dollar_total_invoices = dollar_field("total_invoices", "Total Invoices")
1462 dollar_total_payments = dollar_field("total_payments", "Total Payments")
1463
Siobhan Tully53437282013-04-26 19:30:27 -04001464# Now register the new UserAdmin...
Siobhan Tully30fd4292013-05-10 08:59:56 -04001465admin.site.register(User, UserAdmin)
Siobhan Tully53437282013-04-26 19:30:27 -04001466# ... and, since we're not using Django's builtin permissions,
1467# unregister the Group model from admin.
Siobhan Tullyce652d02013-10-08 21:52:35 -04001468#admin.site.unregister(Group)
Siobhan Tully53437282013-04-26 19:30:27 -04001469
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001470#Do not show django evolution in the admin interface
1471from django_evolution.models import Version, Evolution
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001472#admin.site.unregister(Version)
1473#admin.site.unregister(Evolution)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001474
1475
1476# When debugging it is often easier to see all the classes, but for regular use
1477# only the top-levels should be displayed
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001478showAll = False
Scott Baker43105042013-12-06 23:23:36 -08001479
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001480admin.site.register(Deployment, DeploymentAdmin)
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001481admin.site.register(Site, SiteAdmin)
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001482admin.site.register(Slice, SliceAdmin)
Siobhan Tullyce652d02013-10-08 21:52:35 -04001483admin.site.register(Service, ServiceAdmin)
smbakera3cf70c2013-06-27 02:01:41 -07001484admin.site.register(Reservation, ReservationAdmin)
Scott Baker74d8e622013-07-29 16:04:22 -07001485admin.site.register(Network, NetworkAdmin)
1486admin.site.register(Router, RouterAdmin)
Scott Baker74d8e622013-07-29 16:04:22 -07001487admin.site.register(NetworkTemplate, NetworkTemplateAdmin)
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001488admin.site.register(Account, AccountAdmin)
1489admin.site.register(Invoice, InvoiceAdmin)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001490
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001491if True:
1492 admin.site.register(NetworkParameterType, NetworkParameterTypeAdmin)
1493 admin.site.register(ServiceClass, ServiceClassAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001494 #admin.site.register(PlanetStack)
Siobhan Tullyd3515752013-06-21 16:34:53 -04001495 admin.site.register(Tag, TagAdmin)
Siobhan Tullyce652d02013-10-08 21:52:35 -04001496 admin.site.register(DeploymentRole)
1497 admin.site.register(SiteRole)
1498 admin.site.register(SliceRole)
1499 admin.site.register(PlanetStackRole)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001500 admin.site.register(Node, NodeAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001501 #admin.site.register(SlicePrivilege, SlicePrivilegeAdmin)
1502 #admin.site.register(SitePrivilege, SitePrivilegeAdmin)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001503 admin.site.register(Sliver, SliverAdmin)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001504 admin.site.register(Image, ImageAdmin)
Scott Baker2c3cb642014-05-19 17:55:56 -07001505 admin.site.register(DashboardView, DashboardViewAdmin)
Scott Baker37b47902014-09-02 14:37:41 -07001506 admin.site.register(Flavor, FlavorAdmin)
Tony Mack7130ac32013-03-22 21:58:00 -04001507