blob: d2a9b53150dc505a41df1328c1da3d9c5ef42d1a [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 Bakercbfb6002014-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 Baker0a5633b2014-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 Bakerfbf06642014-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 Bakerfbf06642014-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 Bakerfbf06642014-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 Baker86c83ab2014-10-03 13:10:47 -070050class PermissionCheckingAdminMixin(object):
Scott Bakercbfb6002014-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 Bakercbfb6002014-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 Bakercbfb6002014-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 Baker86c83ab2014-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 Baker86c83ab2014-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 Baker86c83ab2014-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 Baker86c83ab2014-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 Bakercbfb6002014-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 Baker32481312014-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 Baker61b6aec2014-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 Mack2cbd3802014-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 Mack2cbd3802014-09-29 16:10:52 -0400727 def clean(self):
728 cleaned_data = super(SliceForm, self).clean()
729 name = cleaned_data.get('name')
Scott Baker6efad462014-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 Mack2cbd3802014-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 Baker93e80cd2014-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 Baker93e80cd2014-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 Baker93e80cd2014-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 Mack2bd5b412013-06-11 21:05:06 -0400802
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400803class SlicePrivilegeAdmin(PlanetStackBaseAdmin):
Tony Mack00d361f2013-04-28 10:28:42 -0400804 fieldsets = [
Scott Baker40c00762014-08-21 16:55:59 -0700805 (None, {'fields': ['backend_status_text', 'user', 'slice', 'role']})
Tony Mack00d361f2013-04-28 10:28:42 -0400806 ]
Scott Baker40c00762014-08-21 16:55:59 -0700807 readonly_fields = ('backend_status_text', )
Scott Baker63d1a552014-08-21 15:19:07 -0700808 list_display = ('backend_status_icon', 'user', 'slice', 'role')
809 list_display_links = list_display
Tony Mack00d361f2013-04-28 10:28:42 -0400810
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500811 user_readonly_fields = ['user', 'slice', 'role']
812 user_readonly_inlines = []
813
Tony Mackc2835a92013-05-28 09:18:49 -0400814 def formfield_for_foreignkey(self, db_field, request, **kwargs):
815 if db_field.name == 'slice':
Tony Mack5b061472014-02-04 07:57:10 -0500816 kwargs['queryset'] = Slice.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400817
818 if db_field.name == 'user':
Tony Mack5b061472014-02-04 07:57:10 -0500819 kwargs['queryset'] = User.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400820
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400821 return super(SlicePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
Tony Mackc2835a92013-05-28 09:18:49 -0400822
Tony Mack04062832013-05-10 08:22:44 -0400823 def queryset(self, request):
824 # admins can see all memberships. Users can only see memberships of
825 # slices where they have the admin role.
Tony Mack5b061472014-02-04 07:57:10 -0500826 return SlicePrivilege.select_by_user(request.user)
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400827
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400828 def save_model(self, request, obj, form, change):
Tony Mack951dab42013-05-02 19:51:45 -0400829 # update openstack connection to use this site/tenant
830 auth = request.session.get('auth', {})
Tony Mackf7f79a12014-08-11 11:21:42 -0400831 auth['tenant'] = obj.slice.slicename
Tony Mack951dab42013-05-02 19:51:45 -0400832 obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400833 obj.save()
834
835 def delete_model(self, request, obj):
Tony Mack951dab42013-05-02 19:51:45 -0400836 # update openstack connection to use this site/tenant
837 auth = request.session.get('auth', {})
Tony Mackf7f79a12014-08-11 11:21:42 -0400838 auth['tenant'] = obj.slice.slicename
Tony Mack951dab42013-05-02 19:51:45 -0400839 obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400840 obj.delete()
841
Siobhan Tully567e3e62013-06-21 18:03:16 -0400842
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400843class ImageAdmin(PlanetStackBaseAdmin):
844
Scott Baker36f50872014-08-21 13:01:25 -0700845 fieldsets = [('Image Details',
Scott Baker40c00762014-08-21 16:55:59 -0700846 {'fields': ['backend_status_text', 'name', 'disk_format', 'container_format'],
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400847 'classes': ['suit-tab suit-tab-general']})
848 ]
Scott Baker40c00762014-08-21 16:55:59 -0700849 readonly_fields = ('backend_status_text', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400850
Scott Baker2170b972014-06-03 12:14:07 -0700851 suit_form_tabs =(('general','Image Details'),('slivers','Slivers'),('imagedeployments','Deployments'))
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400852
Scott Baker2170b972014-06-03 12:14:07 -0700853 inlines = [SliverInline, ImageDeploymentsInline]
Scott Bakerb6f99242014-06-11 11:34:44 -0700854
Tony Mack32e1ce32014-05-07 13:29:41 -0400855 user_readonly_fields = ['name', 'disk_format', 'container_format']
Scott Bakerb27b62c2014-08-15 16:29:16 -0700856
Scott Baker63d1a552014-08-21 15:19:07 -0700857 list_display = ['backend_status_icon', 'name']
858 list_display_links = ('backend_status_icon', 'name', )
859
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400860class NodeForm(forms.ModelForm):
861 class Meta:
862 widgets = {
863 'site': LinkedSelect,
864 'deployment': LinkedSelect
865 }
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400866
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500867class NodeAdmin(PlanetStackBaseAdmin):
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400868 form = NodeForm
Scott Baker63d1a552014-08-21 15:19:07 -0700869 list_display = ('backend_status_icon', 'name', 'site', 'deployment')
870 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullybf1153a2013-05-27 20:53:48 -0400871 list_filter = ('deployment',)
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500872
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400873 inlines = [TagInline,SliverInline]
Scott Baker40c00762014-08-21 16:55:59 -0700874 fieldsets = [('Node Details', {'fields': ['backend_status_text', 'name','site','deployment'], 'classes':['suit-tab suit-tab-details']})]
875 readonly_fields = ('backend_status_text', )
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400876
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500877 user_readonly_fields = ['name','site','deployment']
878 user_readonly_inlines = [TagInline,SliverInline]
879
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400880 suit_form_tabs =(('details','Node Details'),('slivers','Slivers'),('tags','Tags'))
Siobhan Tully4bc09f22013-04-10 21:15:21 -0400881
Siobhan Tully567e3e62013-06-21 18:03:16 -0400882
Tony Mackd90cdbf2013-04-16 22:48:40 -0400883class SliverForm(forms.ModelForm):
884 class Meta:
Tony Mack1d6b85f2013-05-07 18:49:14 -0400885 model = Sliver
Tony Mackd90cdbf2013-04-16 22:48:40 -0400886 ip = forms.CharField(widget=PlainTextWidget)
Tony Mack18261812013-05-02 16:39:20 -0400887 instance_name = forms.CharField(widget=PlainTextWidget)
Tony Mackd90cdbf2013-04-16 22:48:40 -0400888 widgets = {
889 'ip': PlainTextWidget(),
Tony Mack18261812013-05-02 16:39:20 -0400890 'instance_name': PlainTextWidget(),
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400891 'slice': LinkedSelect,
892 'deploymentNetwork': LinkedSelect,
893 'node': LinkedSelect,
894 'image': LinkedSelect
Siobhan Tully53437282013-04-26 19:30:27 -0400895 }
Tony Mackd90cdbf2013-04-16 22:48:40 -0400896
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500897class TagAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -0700898 list_display = ['backend_status_icon', 'service', 'name', 'value', 'content_type', 'content_object',]
899 list_display_links = list_display
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500900 user_readonly_fields = ['service', 'name', 'value', 'content_type', 'content_object',]
901 user_readonly_inlines = []
Siobhan Tullyd3515752013-06-21 16:34:53 -0400902
Tony Mack9bcbe4f2013-04-29 08:13:27 -0400903class SliverAdmin(PlanetStackBaseAdmin):
Tony Mackd90cdbf2013-04-16 22:48:40 -0400904 form = SliverForm
Tony Mackcdec0902013-04-15 00:38:49 -0400905 fieldsets = [
Scott Baker7a61dc42014-09-02 17:08:20 -0700906 ('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 -0400907 ]
Scott Baker40c00762014-08-21 16:55:59 -0700908 readonly_fields = ('backend_status_text', )
Scott Baker7a61dc42014-09-02 17:08:20 -0700909 list_display = ['backend_status_icon', 'ip', 'instance_name', 'slice', 'flavor', 'image', 'node', 'deploymentNetwork']
Scott Baker63d1a552014-08-21 15:19:07 -0700910 list_display_links = ('backend_status_icon', 'ip',)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400911
912 suit_form_tabs =(('general', 'Sliver Details'),
913 ('tags','Tags'),
914 )
915
Siobhan Tullyde5450d2013-06-21 11:35:33 -0400916 inlines = [TagInline]
Tony Mack53106f32013-04-27 16:43:01 -0400917
Scott Baker7a61dc42014-09-02 17:08:20 -0700918 user_readonly_fields = ['slice', 'deploymentNetwork', 'node', 'ip', 'instance_name', 'flavor', 'image']
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500919
Tony Mackc2835a92013-05-28 09:18:49 -0400920 def formfield_for_foreignkey(self, db_field, request, **kwargs):
921 if db_field.name == 'slice':
Tony Mack5b061472014-02-04 07:57:10 -0500922 kwargs['queryset'] = Slice.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -0400923
924 return super(SliverAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
925
Tony Mack04062832013-05-10 08:22:44 -0400926 def queryset(self, request):
Scott Baker36f50872014-08-21 13:01:25 -0700927 # admins can see all slivers. Users can only see slivers of
Tony Mack04062832013-05-10 08:22:44 -0400928 # the slices they belong to.
Tony Mack5b061472014-02-04 07:57:10 -0500929 return Sliver.select_by_user(request.user)
930
Tony Mack04062832013-05-10 08:22:44 -0400931
Tony Mack1d6b85f2013-05-07 18:49:14 -0400932 def get_formsets(self, request, obj=None):
933 # make some fields read only if we are updating an existing record
934 if obj == None:
Scott Baker36f50872014-08-21 13:01:25 -0700935 #self.readonly_fields = ('ip', 'instance_name')
Scott Baker40c00762014-08-21 16:55:59 -0700936 self.readonly_fields = ('backend_status_text')
Tony Mack1d6b85f2013-05-07 18:49:14 -0400937 else:
Scott Baker40c00762014-08-21 16:55:59 -0700938 self.readonly_fields = ('backend_status_text')
Scott Baker36f50872014-08-21 13:01:25 -0700939 #self.readonly_fields = ('ip', 'instance_name', 'slice', 'image', 'key')
Tony Mack1d6b85f2013-05-07 18:49:14 -0400940
941 for inline in self.get_inline_instances(request, obj):
942 # hide MyInline in the add view
943 if obj is None:
944 continue
Scott Baker526b71e2014-05-13 13:18:01 -0700945 if isinstance(inline, SliverInline):
946 inline.model.caller = request.user
947 yield inline.get_formset(request, obj)
Tony Mack53106f32013-04-27 16:43:01 -0400948
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500949 #def save_model(self, request, obj, form, change):
950 # # update openstack connection to use this site/tenant
951 # auth = request.session.get('auth', {})
952 # auth['tenant'] = obj.slice.name
953 # obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
954 # obj.creator = request.user
955 # obj.save()
Tony Mack53106f32013-04-27 16:43:01 -0400956
Siobhan Tullycf04fb62014-01-11 11:25:57 -0500957 #def delete_model(self, request, obj):
958 # # update openstack connection to use this site/tenant
959 # auth = request.session.get('auth', {})
960 # auth['tenant'] = obj.slice.name
961 # obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
962 # obj.delete()
Tony Mackcdec0902013-04-15 00:38:49 -0400963
Siobhan Tully53437282013-04-26 19:30:27 -0400964class UserCreationForm(forms.ModelForm):
965 """A form for creating new users. Includes all the required
966 fields, plus a repeated password."""
967 password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
968 password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
969
970 class Meta:
Siobhan Tully30fd4292013-05-10 08:59:56 -0400971 model = User
Siobhan Tullybfd11dc2013-09-03 12:59:24 -0400972 fields = ('email', 'firstname', 'lastname', 'phone', 'public_key')
Siobhan Tully53437282013-04-26 19:30:27 -0400973
974 def clean_password2(self):
975 # Check that the two password entries match
976 password1 = self.cleaned_data.get("password1")
977 password2 = self.cleaned_data.get("password2")
978 if password1 and password2 and password1 != password2:
979 raise forms.ValidationError("Passwords don't match")
980 return password2
981
982 def save(self, commit=True):
983 # Save the provided password in hashed format
984 user = super(UserCreationForm, self).save(commit=False)
Tony Mackf9f4afb2013-05-01 21:02:12 -0400985 user.password = self.cleaned_data["password1"]
986 #user.set_password(self.cleaned_data["password1"])
Siobhan Tully53437282013-04-26 19:30:27 -0400987 if commit:
988 user.save()
989 return user
990
Siobhan Tully567e3e62013-06-21 18:03:16 -0400991
Siobhan Tully53437282013-04-26 19:30:27 -0400992class UserChangeForm(forms.ModelForm):
993 """A form for updating users. Includes all the fields on
994 the user, but replaces the password field with admin's
995 password hash display field.
996 """
Siobhan Tully63b7ba42014-01-12 10:35:11 -0500997 password = ReadOnlyPasswordHashField(label='Password',
998 help_text= '<a href=\"password/\">Change Password</a>.')
Siobhan Tully53437282013-04-26 19:30:27 -0400999
1000 class Meta:
Siobhan Tully30fd4292013-05-10 08:59:56 -04001001 model = User
Siobhan Tully53437282013-04-26 19:30:27 -04001002
1003 def clean_password(self):
1004 # Regardless of what the user provides, return the initial value.
1005 # This is done here, rather than on the field, because the
1006 # field does not have access to the initial value
1007 return self.initial["password"]
1008
Scott Baker2c3cb642014-05-19 17:55:56 -07001009class UserDashboardViewInline(PlStackTabularInline):
1010 model = UserDashboardView
1011 extra = 0
1012 suit_classes = 'suit-tab suit-tab-dashboards'
1013 fields = ['user', 'dashboardView', 'order']
1014
Scott Baker86c83ab2014-10-03 13:10:47 -07001015class UserAdmin(PermissionCheckingAdminMixin, UserAdmin):
1016 # Note: Make sure PermissionCheckingAdminMixin is listed before
1017 # admin.ModelAdmin in the class declaration.
1018
Siobhan Tully53437282013-04-26 19:30:27 -04001019 class Meta:
1020 app_label = "core"
1021
1022 # The forms to add and change user instances
1023 form = UserChangeForm
1024 add_form = UserCreationForm
1025
1026 # The fields to be used in displaying the User model.
1027 # These override the definitions on the base UserAdmin
1028 # that reference specific fields on auth.User.
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001029 list_display = ('email', 'firstname', 'lastname', 'site', 'last_login')
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001030 list_filter = ('site',)
Scott Baker2c3cb642014-05-19 17:55:56 -07001031 inlines = [SlicePrivilegeInline,SitePrivilegeInline,DeploymentPrivilegeInline,UserDashboardViewInline]
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001032
Scott Bakercbfb6002014-10-03 00:32:37 -07001033 fieldListLoginDetails = ['backend_status_text', 'email','site','password','is_active','is_readonly','is_admin','public_key']
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001034 fieldListContactInfo = ['firstname','lastname','phone','timezone']
1035
Siobhan Tully53437282013-04-26 19:30:27 -04001036 fieldsets = (
Scott Baker40c00762014-08-21 16:55:59 -07001037 ('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 -04001038 ('Contact Information', {'fields': ('firstname','lastname','phone', 'timezone'), 'classes':['suit-tab suit-tab-contact']}),
Scott Baker2c3cb642014-05-19 17:55:56 -07001039 #('Dashboard Views', {'fields': ('dashboards',), 'classes':['suit-tab suit-tab-dashboards']}),
Siobhan Tully53437282013-04-26 19:30:27 -04001040 #('Important dates', {'fields': ('last_login',)}),
1041 )
1042 add_fieldsets = (
1043 (None, {
1044 'classes': ('wide',),
Scott Baker0a5633b2014-10-06 17:51:20 -07001045 'fields': ('email', 'firstname', 'lastname', 'is_readonly', 'phone', 'public_key','password1', 'password2')},
Siobhan Tully53437282013-04-26 19:30:27 -04001046 ),
1047 )
Scott Baker40c00762014-08-21 16:55:59 -07001048 readonly_fields = ('backend_status_text', )
Siobhan Tully53437282013-04-26 19:30:27 -04001049 search_fields = ('email',)
1050 ordering = ('email',)
1051 filter_horizontal = ()
1052
Scott Baker3ca51f62014-05-23 12:05:11 -07001053 user_readonly_fields = fieldListLoginDetails + fieldListContactInfo
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001054
Scott Baker0a5633b2014-10-06 17:51:20 -07001055 def get_form(self, request, obj=None):
1056 # Save obj in thread-local storage, so suit_form_tabs can use it to
1057 # determine whether we're in edit or add mode.
1058 _thread_locals.request = request
1059 _thread_locals.obj = obj
1060 return super(UserAdmin, self).get_form(request, obj)
1061
1062 @property
1063 def suit_form_tabs(self):
1064 if getattr(_thread_locals, "obj", None) is None:
1065 return []
1066 else:
1067 return (('general','Login Details'),
1068 ('contact','Contact Information'),
1069 ('sliceprivileges','Slice Privileges'),
1070 ('siteprivileges','Site Privileges'),
1071 ('deploymentprivileges','Deployment Privileges'),
1072 ('dashboards','Dashboard Views'))
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001073
Tony Mackc2835a92013-05-28 09:18:49 -04001074 def formfield_for_foreignkey(self, db_field, request, **kwargs):
1075 if db_field.name == 'site':
Tony Mack5b061472014-02-04 07:57:10 -05001076 kwargs['queryset'] = Site.select_by_user(request.user)
Tony Mackc2835a92013-05-28 09:18:49 -04001077
1078 return super(UserAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
1079
Tony Mack5b061472014-02-04 07:57:10 -05001080 def queryset(self, request):
1081 return User.select_by_user(request.user)
1082
Scott Baker2c3cb642014-05-19 17:55:56 -07001083class DashboardViewAdmin(PlanetStackBaseAdmin):
1084 fieldsets = [('Dashboard View Details',
Scott Baker40c00762014-08-21 16:55:59 -07001085 {'fields': ['backend_status_text', 'name', 'url'],
Scott Baker2c3cb642014-05-19 17:55:56 -07001086 'classes': ['suit-tab suit-tab-general']})
1087 ]
Scott Baker40c00762014-08-21 16:55:59 -07001088 readonly_fields = ('backend_status_text', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001089
Scott Baker2c3cb642014-05-19 17:55:56 -07001090 suit_form_tabs =(('general','Dashboard View Details'),)
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001091
Scott Baker0165fac2014-01-13 11:49:26 -08001092class ServiceResourceInline(PlStackTabularInline):
Scott Baker3de3e372013-05-10 16:50:44 -07001093 model = ServiceResource
1094 extra = 0
1095
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001096class ServiceClassAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001097 list_display = ('backend_status_icon', 'name', 'commitment', 'membershipFee')
1098 list_display_links = ('backend_status_icon', 'name', )
Scott Baker3de3e372013-05-10 16:50:44 -07001099 inlines = [ServiceResourceInline]
1100
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001101 user_readonly_fields = ['name', 'commitment', 'membershipFee']
1102 user_readonly_inlines = []
1103
Scott Baker0165fac2014-01-13 11:49:26 -08001104class ReservedResourceInline(PlStackTabularInline):
Scott Baker133c9212013-05-17 09:09:11 -07001105 model = ReservedResource
1106 extra = 0
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001107 suit_classes = 'suit-tab suit-tab-reservedresources'
Scott Baker133c9212013-05-17 09:09:11 -07001108
1109 def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
1110 field = super(ReservedResourceInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
1111
1112 if db_field.name == 'resource':
1113 # restrict resources to those that the slice's service class allows
1114 if request._slice is not None:
1115 field.queryset = field.queryset.filter(serviceClass = request._slice.serviceClass, calendarReservable=True)
1116 if len(field.queryset) > 0:
1117 field.initial = field.queryset.all()[0]
1118 else:
1119 field.queryset = field.queryset.none()
1120 elif db_field.name == 'sliver':
1121 # restrict slivers to those that belong to the slice
1122 if request._slice is not None:
1123 field.queryset = field.queryset.filter(slice = request._slice)
1124 else:
1125 field.queryset = field.queryset.none()
1126
1127 return field
1128
Tony Mack5b061472014-02-04 07:57:10 -05001129 def queryset(self, request):
1130 return ReservedResource.select_by_user(request.user)
1131
Scott Baker133c9212013-05-17 09:09:11 -07001132class ReservationChangeForm(forms.ModelForm):
1133 class Meta:
1134 model = Reservation
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001135 widgets = {
1136 'slice' : LinkedSelect
1137 }
Scott Baker133c9212013-05-17 09:09:11 -07001138
1139class ReservationAddForm(forms.ModelForm):
1140 slice = forms.ModelChoiceField(queryset=Slice.objects.all(), widget=forms.Select(attrs={"onChange":"document.getElementById('id_refresh').value=1; submit()"}))
1141 refresh = forms.CharField(widget=forms.HiddenInput())
1142
1143 class Media:
1144 css = {'all': ('planetstack.css',)} # .field-refresh { display: none; }
1145
1146 def clean_slice(self):
1147 slice = self.cleaned_data.get("slice")
1148 x = ServiceResource.objects.filter(serviceClass = slice.serviceClass, calendarReservable=True)
1149 if len(x) == 0:
1150 raise forms.ValidationError("The slice you selected does not have a service class that allows reservations")
1151 return slice
1152
1153 class Meta:
1154 model = Reservation
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001155 widgets = {
1156 'slice' : LinkedSelect
1157 }
1158
Scott Baker133c9212013-05-17 09:09:11 -07001159
1160class ReservationAddRefreshForm(ReservationAddForm):
1161 """ This form is displayed when the Reservation Form receives an update
1162 from the Slice dropdown onChange handler. It doesn't validate the
1163 data and doesn't save the data. This will cause the form to be
1164 redrawn.
1165 """
1166
Scott Baker8737e5f2013-05-17 09:35:32 -07001167 """ don't validate anything other than slice """
1168 dont_validate_fields = ("startTime", "duration")
1169
Scott Baker133c9212013-05-17 09:09:11 -07001170 def full_clean(self):
1171 result = super(ReservationAddForm, self).full_clean()
Scott Baker8737e5f2013-05-17 09:35:32 -07001172
1173 for fieldname in self.dont_validate_fields:
1174 if fieldname in self._errors:
1175 del self._errors[fieldname]
1176
Scott Baker133c9212013-05-17 09:09:11 -07001177 return result
1178
1179 """ don't save anything """
1180 def is_valid(self):
1181 return False
1182
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001183class ReservationAdmin(PlanetStackBaseAdmin):
Scott Baker40c00762014-08-21 16:55:59 -07001184 fieldList = ['backend_status_text', 'slice', 'startTime', 'duration']
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001185 fieldsets = [('Reservation Details', {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
Scott Baker40c00762014-08-21 16:55:59 -07001186 readonly_fields = ('backend_status_text', )
Scott Baker133c9212013-05-17 09:09:11 -07001187 list_display = ('startTime', 'duration')
Scott Baker133c9212013-05-17 09:09:11 -07001188 form = ReservationAddForm
1189
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001190 suit_form_tabs = (('general','Reservation Details'), ('reservedresources','Reserved Resources'))
1191
1192 inlines = [ReservedResourceInline]
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001193 user_readonly_fields = fieldList
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001194
Scott Baker133c9212013-05-17 09:09:11 -07001195 def add_view(self, request, form_url='', extra_context=None):
Scott Bakeracd45142013-05-19 16:19:16 -07001196 timezone.activate(request.user.timezone)
Scott Baker133c9212013-05-17 09:09:11 -07001197 request._refresh = False
1198 request._slice = None
1199 if request.method == 'POST':
Scott Baker8737e5f2013-05-17 09:35:32 -07001200 # "refresh" will be set to "1" if the form was submitted due to
1201 # a change in the Slice dropdown.
Scott Baker133c9212013-05-17 09:09:11 -07001202 if request.POST.get("refresh","1") == "1":
1203 request._refresh = True
1204 request.POST["refresh"] = "0"
Scott Baker8737e5f2013-05-17 09:35:32 -07001205
1206 # Keep track of the slice that was selected, so the
1207 # reservedResource inline can filter items for the slice.
Scott Baker133c9212013-05-17 09:09:11 -07001208 request._slice = request.POST.get("slice",None)
1209 if (request._slice is not None):
1210 request._slice = Slice.objects.get(id=request._slice)
1211
1212 result = super(ReservationAdmin, self).add_view(request, form_url, extra_context)
1213 return result
1214
Scott Bakeracd45142013-05-19 16:19:16 -07001215 def changelist_view(self, request, extra_context = None):
1216 timezone.activate(request.user.timezone)
1217 return super(ReservationAdmin, self).changelist_view(request, extra_context)
1218
Scott Baker133c9212013-05-17 09:09:11 -07001219 def get_form(self, request, obj=None, **kwargs):
Siobhan Tullyd3515752013-06-21 16:34:53 -04001220 request._obj_ = obj
1221 if obj is not None:
1222 # For changes, set request._slice to the slice already set in the
1223 # object.
1224 request._slice = obj.slice
1225 self.form = ReservationChangeForm
1226 else:
1227 if getattr(request, "_refresh", False):
1228 self.form = ReservationAddRefreshForm
1229 else:
1230 self.form = ReservationAddForm
1231 return super(ReservationAdmin, self).get_form(request, obj, **kwargs)
1232
Scott Baker133c9212013-05-17 09:09:11 -07001233 def get_readonly_fields(self, request, obj=None):
Siobhan Tullyd3515752013-06-21 16:34:53 -04001234 if (obj is not None):
1235 # Prevent slice from being changed after the reservation has been
1236 # created.
1237 return ['slice']
1238 else:
Scott Baker133c9212013-05-17 09:09:11 -07001239 return []
Scott Baker3de3e372013-05-10 16:50:44 -07001240
Tony Mack5b061472014-02-04 07:57:10 -05001241 def queryset(self, request):
1242 return Reservation.select_by_user(request.user)
1243
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001244class NetworkParameterTypeAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001245 list_display = ("backend_status_icon", "name", )
1246 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001247 user_readonly_fields = ['name']
1248 user_readonly_inlines = []
Scott Baker74d8e622013-07-29 16:04:22 -07001249
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001250class RouterAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001251 list_display = ("backend_status_icon", "name", )
1252 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001253 user_readonly_fields = ['name']
1254 user_readonly_inlines = []
1255
Scott Baker0165fac2014-01-13 11:49:26 -08001256class RouterInline(PlStackTabularInline):
Scott Baker74d8e622013-07-29 16:04:22 -07001257 model = Router.networks.through
1258 extra = 0
1259 verbose_name_plural = "Routers"
1260 verbose_name = "Router"
Siobhan Tully2d95e482013-09-06 10:56:06 -04001261 suit_classes = 'suit-tab suit-tab-routers'
Scott Baker74d8e622013-07-29 16:04:22 -07001262
Scott Bakerb27b62c2014-08-15 16:29:16 -07001263class NetworkParameterInline(PlStackGenericTabularInline):
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001264 model = NetworkParameter
Scott Baker618e3792014-08-15 13:42:29 -07001265 extra = 0
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001266 verbose_name_plural = "Parameters"
1267 verbose_name = "Parameter"
1268 suit_classes = 'suit-tab suit-tab-netparams'
Scott Baker40c00762014-08-21 16:55:59 -07001269 fields = ['backend_status_icon', 'parameter', 'value']
1270 readonly_fields = ('backend_status_icon', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001271
Scott Baker0165fac2014-01-13 11:49:26 -08001272class NetworkSliversInline(PlStackTabularInline):
Scott Baker40c00762014-08-21 16:55:59 -07001273 fields = ['backend_status_icon', 'network','sliver','ip']
1274 readonly_fields = ("backend_status_icon", "ip", )
Scott Baker74d8e622013-07-29 16:04:22 -07001275 model = NetworkSliver
Scott Baker874936e2014-01-13 18:15:34 -08001276 selflink_fieldname = "sliver"
Scott Baker74d8e622013-07-29 16:04:22 -07001277 extra = 0
1278 verbose_name_plural = "Slivers"
1279 verbose_name = "Sliver"
Siobhan Tully2d95e482013-09-06 10:56:06 -04001280 suit_classes = 'suit-tab suit-tab-networkslivers'
Scott Baker74d8e622013-07-29 16:04:22 -07001281
Scott Baker0165fac2014-01-13 11:49:26 -08001282class NetworkSlicesInline(PlStackTabularInline):
Scott Bakerd7d2a392013-08-06 08:57:30 -07001283 model = NetworkSlice
Scott Baker874936e2014-01-13 18:15:34 -08001284 selflink_fieldname = "slice"
Scott Bakerd7d2a392013-08-06 08:57:30 -07001285 extra = 0
1286 verbose_name_plural = "Slices"
1287 verbose_name = "Slice"
Siobhan Tully2d95e482013-09-06 10:56:06 -04001288 suit_classes = 'suit-tab suit-tab-networkslices'
Scott Baker40c00762014-08-21 16:55:59 -07001289 fields = ['backend_status_icon', 'network','slice']
1290 readonly_fields = ('backend_status_icon', )
Scott Bakerd7d2a392013-08-06 08:57:30 -07001291
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001292class NetworkAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001293 list_display = ("backend_status_icon", "name", "subnet", "ports", "labels")
1294 list_display_links = ('backend_status_icon', 'name', )
Scott Baker74d8e622013-07-29 16:04:22 -07001295 readonly_fields = ("subnet", )
Siobhan Tully2d95e482013-09-06 10:56:06 -04001296
Scott Bakerd7d2a392013-08-06 08:57:30 -07001297 inlines = [NetworkParameterInline, NetworkSliversInline, NetworkSlicesInline, RouterInline]
Scott Baker74d8e622013-07-29 16:04:22 -07001298
Siobhan Tully2d95e482013-09-06 10:56:06 -04001299 fieldsets = [
Scott Baker40c00762014-08-21 16:55:59 -07001300 (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 -05001301
Scott Baker40c00762014-08-21 16:55:59 -07001302 readonly_fields = ('backend_status_text', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001303 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 -04001304
1305 suit_form_tabs =(
1306 ('general','Network Details'),
1307 ('netparams', 'Parameters'),
1308 ('networkslivers','Slivers'),
1309 ('networkslices','Slices'),
1310 ('routers','Routers'),
1311 )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001312class NetworkTemplateAdmin(PlanetStackBaseAdmin):
Scott Baker63d1a552014-08-21 15:19:07 -07001313 list_display = ("backend_status_icon", "name", "guaranteedBandwidth", "visibility")
1314 list_display_links = ('backend_status_icon', 'name', )
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001315 user_readonly_fields = ["name", "guaranteedBandwidth", "visibility"]
1316 user_readonly_inlines = []
Scott Baker74d8e622013-07-29 16:04:22 -07001317
Scott Baker37b47902014-09-02 14:37:41 -07001318class FlavorAdmin(PlanetStackBaseAdmin):
1319 list_display = ("backend_status_icon", "name", "flavor", "order", "default")
1320 list_display_links = ("backend_status_icon", "name")
1321 user_readonly_fields = ("name", "flavor")
1322 fields = ("name", "description", "flavor", "order", "default")
1323
Tony Mack31c2b8f2013-04-26 20:01:42 -04001324# register a signal that caches the user's credentials when they log in
1325def cache_credentials(sender, user, request, **kwds):
1326 auth = {'username': request.POST['username'],
1327 'password': request.POST['password']}
1328 request.session['auth'] = auth
1329user_logged_in.connect(cache_credentials)
1330
Scott Baker15cddfa2013-12-09 13:45:19 -08001331def dollar_field(fieldName, short_description):
1332 def newFunc(self, obj):
1333 try:
1334 x= "$ %0.2f" % float(getattr(obj, fieldName, 0.0))
1335 except:
1336 x=getattr(obj, fieldName, 0.0)
1337 return x
1338 newFunc.short_description = short_description
1339 return newFunc
1340
1341def right_dollar_field(fieldName, short_description):
1342 def newFunc(self, obj):
1343 try:
1344 #x= '<div align=right style="width:6em">$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0))
1345 x= '<div align=right>$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0))
1346 except:
1347 x=getattr(obj, fieldName, 0.0)
1348 return x
1349 newFunc.short_description = short_description
1350 newFunc.allow_tags = True
1351 return newFunc
Scott Baker43105042013-12-06 23:23:36 -08001352
Scott Baker0165fac2014-01-13 11:49:26 -08001353class InvoiceChargeInline(PlStackTabularInline):
Scott Baker43105042013-12-06 23:23:36 -08001354 model = Charge
Scott Baker15cddfa2013-12-09 13:45:19 -08001355 extra = 0
Scott Baker43105042013-12-06 23:23:36 -08001356 verbose_name_plural = "Charges"
1357 verbose_name = "Charge"
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001358 exclude = ['account']
Scott Baker9cb88a22013-12-09 18:56:00 -08001359 fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
1360 readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
1361 can_delete = False
1362 max_num = 0
1363
1364 dollar_amount = right_dollar_field("amount", "Amount")
Scott Baker43105042013-12-06 23:23:36 -08001365
1366class InvoiceAdmin(admin.ModelAdmin):
1367 list_display = ("date", "account")
1368
1369 inlines = [InvoiceChargeInline]
1370
Scott Baker9cb88a22013-12-09 18:56:00 -08001371 fields = ["date", "account", "dollar_amount"]
1372 readonly_fields = ["date", "account", "dollar_amount"]
1373
1374 dollar_amount = dollar_field("amount", "Amount")
Scott Baker43105042013-12-06 23:23:36 -08001375
Scott Baker0165fac2014-01-13 11:49:26 -08001376class InvoiceInline(PlStackTabularInline):
Scott Baker15cddfa2013-12-09 13:45:19 -08001377 model = Invoice
1378 extra = 0
1379 verbose_name_plural = "Invoices"
1380 verbose_name = "Invoice"
Scott Baker0165fac2014-01-13 11:49:26 -08001381 fields = ["date", "dollar_amount"]
1382 readonly_fields = ["date", "dollar_amount"]
Scott Baker15cddfa2013-12-09 13:45:19 -08001383 suit_classes = 'suit-tab suit-tab-accountinvoice'
1384 can_delete=False
1385 max_num=0
1386
1387 dollar_amount = right_dollar_field("amount", "Amount")
1388
Scott Baker0165fac2014-01-13 11:49:26 -08001389class PendingChargeInline(PlStackTabularInline):
Scott Baker43105042013-12-06 23:23:36 -08001390 model = Charge
Scott Baker15cddfa2013-12-09 13:45:19 -08001391 extra = 0
Scott Baker43105042013-12-06 23:23:36 -08001392 verbose_name_plural = "Charges"
1393 verbose_name = "Charge"
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001394 exclude = ["invoice"]
Scott Baker15cddfa2013-12-09 13:45:19 -08001395 fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
1396 readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"]
Scott Baker43105042013-12-06 23:23:36 -08001397 suit_classes = 'suit-tab suit-tab-accountpendingcharges'
Scott Baker15cddfa2013-12-09 13:45:19 -08001398 can_delete=False
1399 max_num=0
Scott Baker43105042013-12-06 23:23:36 -08001400
1401 def queryset(self, request):
1402 qs = super(PendingChargeInline, self).queryset(request)
1403 qs = qs.filter(state="pending")
1404 return qs
1405
Scott Baker15cddfa2013-12-09 13:45:19 -08001406 dollar_amount = right_dollar_field("amount", "Amount")
1407
Scott Baker0165fac2014-01-13 11:49:26 -08001408class PaymentInline(PlStackTabularInline):
Scott Baker43105042013-12-06 23:23:36 -08001409 model=Payment
1410 extra = 1
1411 verbose_name_plural = "Payments"
1412 verbose_name = "Payment"
Scott Baker15cddfa2013-12-09 13:45:19 -08001413 fields = ["date", "dollar_amount"]
1414 readonly_fields = ["date", "dollar_amount"]
Scott Baker43105042013-12-06 23:23:36 -08001415 suit_classes = 'suit-tab suit-tab-accountpayments'
Scott Baker15cddfa2013-12-09 13:45:19 -08001416 can_delete=False
1417 max_num=0
1418
1419 dollar_amount = right_dollar_field("amount", "Amount")
1420
Scott Baker43105042013-12-06 23:23:36 -08001421class AccountAdmin(admin.ModelAdmin):
1422 list_display = ("site", "balance_due")
1423
1424 inlines = [InvoiceInline, PaymentInline, PendingChargeInline]
1425
1426 fieldsets = [
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001427 (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 -08001428
Scott Baker15cddfa2013-12-09 13:45:19 -08001429 readonly_fields = ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments']
Scott Baker43105042013-12-06 23:23:36 -08001430
1431 suit_form_tabs =(
1432 ('general','Account Details'),
1433 ('accountinvoice', 'Invoices'),
1434 ('accountpayments', 'Payments'),
1435 ('accountpendingcharges','Pending Charges'),
1436 )
1437
Scott Baker15cddfa2013-12-09 13:45:19 -08001438 dollar_balance_due = dollar_field("balance_due", "Balance Due")
1439 dollar_total_invoices = dollar_field("total_invoices", "Total Invoices")
1440 dollar_total_payments = dollar_field("total_payments", "Total Payments")
1441
Siobhan Tully53437282013-04-26 19:30:27 -04001442# Now register the new UserAdmin...
Siobhan Tully30fd4292013-05-10 08:59:56 -04001443admin.site.register(User, UserAdmin)
Siobhan Tully53437282013-04-26 19:30:27 -04001444# ... and, since we're not using Django's builtin permissions,
1445# unregister the Group model from admin.
Siobhan Tullyce652d02013-10-08 21:52:35 -04001446#admin.site.unregister(Group)
Siobhan Tully53437282013-04-26 19:30:27 -04001447
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001448#Do not show django evolution in the admin interface
1449from django_evolution.models import Version, Evolution
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001450#admin.site.unregister(Version)
1451#admin.site.unregister(Evolution)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001452
1453
1454# When debugging it is often easier to see all the classes, but for regular use
1455# only the top-levels should be displayed
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001456showAll = False
Scott Baker43105042013-12-06 23:23:36 -08001457
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001458admin.site.register(Deployment, DeploymentAdmin)
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001459admin.site.register(Site, SiteAdmin)
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001460admin.site.register(Slice, SliceAdmin)
Siobhan Tullyce652d02013-10-08 21:52:35 -04001461admin.site.register(Service, ServiceAdmin)
smbakera3cf70c2013-06-27 02:01:41 -07001462admin.site.register(Reservation, ReservationAdmin)
Scott Baker74d8e622013-07-29 16:04:22 -07001463admin.site.register(Network, NetworkAdmin)
1464admin.site.register(Router, RouterAdmin)
Scott Baker74d8e622013-07-29 16:04:22 -07001465admin.site.register(NetworkTemplate, NetworkTemplateAdmin)
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001466admin.site.register(Account, AccountAdmin)
1467admin.site.register(Invoice, InvoiceAdmin)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001468
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001469if True:
1470 admin.site.register(NetworkParameterType, NetworkParameterTypeAdmin)
1471 admin.site.register(ServiceClass, ServiceClassAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001472 #admin.site.register(PlanetStack)
Siobhan Tullyd3515752013-06-21 16:34:53 -04001473 admin.site.register(Tag, TagAdmin)
Siobhan Tullyce652d02013-10-08 21:52:35 -04001474 admin.site.register(DeploymentRole)
1475 admin.site.register(SiteRole)
1476 admin.site.register(SliceRole)
1477 admin.site.register(PlanetStackRole)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001478 admin.site.register(Node, NodeAdmin)
Siobhan Tullybfd11dc2013-09-03 12:59:24 -04001479 #admin.site.register(SlicePrivilege, SlicePrivilegeAdmin)
1480 #admin.site.register(SitePrivilege, SitePrivilegeAdmin)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001481 admin.site.register(Sliver, SliverAdmin)
Siobhan Tullybf1153a2013-05-27 20:53:48 -04001482 admin.site.register(Image, ImageAdmin)
Scott Baker2c3cb642014-05-19 17:55:56 -07001483 admin.site.register(DashboardView, DashboardViewAdmin)
Scott Baker37b47902014-09-02 14:37:41 -07001484 admin.site.register(Flavor, FlavorAdmin)
Tony Mack7130ac32013-03-22 21:58:00 -04001485