Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1 | from core.models import Site |
| 2 | from core.models import * |
| 3 | from openstack.manager import OpenStackManager |
Tony Mack | e59a7c8 | 2013-04-27 11:08:10 -0400 | [diff] [blame] | 4 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 5 | from django.contrib import admin |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 6 | from django.contrib.auth.models import Group |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 7 | from django import forms |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 8 | from django.utils.safestring import mark_safe |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 9 | from django.contrib.auth.admin import UserAdmin |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 10 | from django.contrib.admin.widgets import FilteredSelectMultiple, AdminTextareaWidget |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 11 | from django.contrib.auth.forms import ReadOnlyPasswordHashField, AdminPasswordChangeForm |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 12 | from django.contrib.auth.signals import user_logged_in |
| 13 | from django.utils import timezone |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 14 | from django.contrib.contenttypes import generic |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 15 | from suit.widgets import LinkedSelect |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 16 | from django.core.exceptions import PermissionDenied |
Tony Mack | 7b6400d | 2015-02-16 19:54:24 -0500 | [diff] [blame] | 17 | from django.core.urlresolvers import reverse, resolve, NoReverseMatch |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 18 | from django.utils.encoding import force_text, python_2_unicode_compatible |
| 19 | from django.utils.html import conditional_escape, format_html |
Scott Baker | 7a056af | 2015-02-26 20:42:11 -0800 | [diff] [blame] | 20 | from django.utils.text import capfirst |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 21 | from django.forms.utils import flatatt, to_current_timezone |
Scott Baker | 2d281a9 | 2015-07-09 19:06:08 -0700 | [diff] [blame] | 22 | from django.core.exceptions import PermissionDenied, ValidationError |
Scott Baker | 3cde737 | 2014-10-21 21:03:08 -0700 | [diff] [blame] | 23 | from cgi import escape as html_escape |
Scott Baker | 2d281a9 | 2015-07-09 19:06:08 -0700 | [diff] [blame] | 24 | from django.contrib import messages |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 25 | |
Scott Baker | 0a5633b | 2014-10-06 17:51:20 -0700 | [diff] [blame] | 26 | import threading |
| 27 | |
| 28 | # thread locals necessary to work around a django-suit issue |
| 29 | _thread_locals = threading.local() |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 30 | |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 31 | ICON_URLS = {"success": "/static/admin/img/icon_success.gif", |
| 32 | "clock": "/static/admin/img/icon_clock.gif", |
| 33 | "error": "/static/admin/img/icon_error.gif"} |
| 34 | |
| 35 | def backend_icon(obj): |
| 36 | (icon, tooltip) = obj.get_backend_icon() |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 37 | |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 38 | icon_url = ICON_URLS.get(icon, "unknown") |
| 39 | |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 40 | (exponent,last_success,last_failure,failures) = obj.get_backend_details() |
| 41 | |
Sapan Bhatia | 0253cf2 | 2015-12-22 18:38:36 +0100 | [diff] [blame] | 42 | # FIXME: Need to clean this up by separating Javascript from Python |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 43 | if (obj.pk): |
| 44 | script = """ |
| 45 | <script type="text/javascript"> |
| 46 | $(document).ready(function () { |
| 47 | $("#show_details_%d").click(function () { |
| 48 | $("#status%d").dialog({modal: true, height: 200, width: 200 }); |
| 49 | }); |
| 50 | }); |
| 51 | </script> |
| 52 | """%(obj.pk,obj.pk) |
| 53 | |
| 54 | div = """ |
| 55 | <div style="display:none;" id="status%d" title="Details"> |
| 56 | <p>Backoff Exponent: %r</p> |
| 57 | <p>Last Success: %r</p> |
| 58 | <p>Failures: %r</p> |
| 59 | <p>Last Failure: %r</p> |
| 60 | </div> |
| 61 | """%(obj.pk,exponent,last_success,failures,last_failure) |
| 62 | a = '<a id="show_details_%d" href="#">'%obj.pk |
| 63 | astop = '</a>' |
| 64 | else: |
| 65 | div = '' |
| 66 | script = '' |
| 67 | a = '' |
| 68 | astop = '' |
| 69 | |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 70 | if tooltip: |
Sapan Bhatia | 5ebfe8c | 2015-12-22 18:37:47 +0100 | [diff] [blame] | 71 | return '%s %s <span style="min-width:16px;" title="%s">%s<img src="%s">%s</span>' % (script, div, tooltip, a, icon_url, astop) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 72 | else: |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 73 | return '<span style="min-width:16px;"><img src="%s"></span>' % icon_url |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 74 | |
| 75 | def backend_text(obj): |
Scott Baker | b6b474d | 2015-02-10 18:24:20 -0800 | [diff] [blame] | 76 | (icon, tooltip) = obj.get_backend_icon() |
| 77 | icon_url = ICON_URLS.get(icon, "unknown") |
| 78 | |
| 79 | return '<img src="%s"> %s' % (icon_url, tooltip) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 80 | |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 81 | class UploadTextareaWidget(AdminTextareaWidget): |
| 82 | def render(self, name, value, attrs=None): |
| 83 | if value is None: |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 84 | value = '' |
| 85 | final_attrs = self.build_attrs(attrs, name=name) |
| 86 | return format_html('<input type="file" style="width: 0; height: 0" id="btn_upload_%s" onChange="uploadTextarea(event,\'%s\');">' \ |
| 87 | '<button onClick="$(\'#btn_upload_%s\').click(); return false;">Upload</button>' \ |
| 88 | '<br><textarea{0}>\r\n{1}</textarea>' % (attrs["id"], attrs["id"], attrs["id"]), |
| 89 | flatatt(final_attrs), |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 90 | force_text(value)) |
| 91 | |
Scott Baker | b92b5c7 | 2015-05-11 16:36:58 -0700 | [diff] [blame] | 92 | class SliderWidget(forms.HiddenInput): |
| 93 | def render(self, name, value, attrs=None): |
| 94 | if value is None: |
| 95 | value = '0' |
| 96 | final_attrs = self.build_attrs(attrs, name=name) |
| 97 | attrs = attrs or attrs[:] |
| 98 | attrs["name"] = name |
| 99 | attrs["value"] = value |
| 100 | html = """<div style="width:640px"><span id="%(id)s_label">%(value)s</span><div id="%(id)s_slider" style="float:right;width:610px;margin-top:5px"></div></div> |
| 101 | <script> |
| 102 | $(function() { |
| 103 | $("#%(id)s_slider").slider({ |
| 104 | value: %(value)s, |
| 105 | slide: function(event, ui) { $("#%(id)s").val( ui.value ); $("#%(id)s_label").html(ui.value); }, |
| 106 | }); |
| 107 | }); |
| 108 | </script> |
| 109 | <input type="hidden" id="%(id)s" name="%(name)s" value="%(value)s"></input> |
| 110 | """ % attrs |
| 111 | html = html.replace("{","{{").replace("}","}}") |
| 112 | return format_html(html, |
| 113 | flatatt(final_attrs), |
| 114 | force_text(value)) |
| 115 | |
| 116 | |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 117 | class PlainTextWidget(forms.HiddenInput): |
| 118 | input_type = 'hidden' |
| 119 | |
| 120 | def render(self, name, value, attrs=None): |
| 121 | if value is None: |
| 122 | value = '' |
| 123 | return mark_safe(str(value) + super(PlainTextWidget, self).render(name, value, attrs)) |
| 124 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 125 | class XOSAdminMixin(object): |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 126 | # call save_by_user and delete_by_user instead of save and delete |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 127 | |
| 128 | def has_add_permission(self, request, obj=None): |
| 129 | return (not self.__user_is_readonly(request)) |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 130 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 131 | def has_delete_permission(self, request, obj=None): |
| 132 | return (not self.__user_is_readonly(request)) |
| 133 | |
| 134 | def save_model(self, request, obj, form, change): |
| 135 | if self.__user_is_readonly(request): |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 136 | # this 'if' might be redundant if save_by_user is implemented right |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 137 | raise PermissionDenied |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 138 | |
Scott Baker | bf08f2f | 2015-12-01 10:24:01 -0800 | [diff] [blame] | 139 | # reset exponential backoff |
| 140 | if hasattr(obj, "backend_register"): |
| 141 | obj.backend_register = "{}" |
| 142 | |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 143 | obj.caller = request.user |
| 144 | # update openstack connection to use this site/tenant |
| 145 | obj.save_by_user(request.user) |
| 146 | |
| 147 | def delete_model(self, request, obj): |
| 148 | obj.delete_by_user(request.user) |
| 149 | |
| 150 | def save_formset(self, request, form, formset, change): |
| 151 | instances = formset.save(commit=False) |
| 152 | for instance in instances: |
Scott Baker | cf9cbad | 2015-07-08 18:23:17 -0700 | [diff] [blame] | 153 | instance.caller = request.user |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 154 | instance.save_by_user(request.user) |
| 155 | |
| 156 | # BUG in django 1.7? Objects are not deleted by formset.save if |
| 157 | # commit is False. So let's delete them ourselves. |
| 158 | # |
| 159 | # code from forms/models.py save_existing_objects() |
| 160 | try: |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 161 | forms_to_delete = formset.deleted_forms |
| 162 | except AttributeError: |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 163 | forms_to_delete = [] |
| 164 | if formset.initial_forms: |
| 165 | for form in formset.initial_forms: |
| 166 | obj = form.instance |
| 167 | if form in forms_to_delete: |
| 168 | if obj.pk is None: |
| 169 | continue |
| 170 | formset.deleted_objects.append(obj) |
| 171 | obj.delete() |
| 172 | |
| 173 | formset.save_m2m() |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 174 | |
| 175 | def get_actions(self,request): |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 176 | actions = super(XOSAdminMixin,self).get_actions(request) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 177 | |
| 178 | if self.__user_is_readonly(request): |
| 179 | if 'delete_selected' in actions: |
| 180 | del actions['delete_selected'] |
| 181 | |
| 182 | return actions |
| 183 | |
Scott Baker | ff3c2d2 | 2015-04-03 17:44:31 -0700 | [diff] [blame] | 184 | def url_for_model_changelist(self, request, model): |
| 185 | # used in add_extra_context |
| 186 | return reverse('admin:%s_%s_changelist' % (model._meta.app_label, model._meta.model_name), current_app=model._meta.app_label) |
| 187 | |
Scott Baker | ba534e7 | 2015-04-02 22:32:40 -0700 | [diff] [blame] | 188 | def add_extra_context(self, request, extra_context): |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 189 | # allow custom application breadcrumb url and name |
| 190 | extra_context["custom_app_breadcrumb_url"] = getattr(self, "custom_app_breadcrumb_url", None) |
| 191 | extra_context["custom_app_breadcrumb_name"] = getattr(self, "custom_app_breadcrumb_name", None) |
Scott Baker | 0998bcc | 2015-04-02 22:07:18 -0700 | [diff] [blame] | 192 | extra_context["custom_changelist_breadcrumb_url"] = getattr(self, "custom_changelist_breadcrumb_url", None) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 193 | |
| 194 | # for Service admins to render their Administration page |
| 195 | if getattr(self, "extracontext_registered_admins", False): |
| 196 | admins=[] |
| 197 | for model, model_admin in admin.site._registry.items():
|
| 198 | if model == self.model:
|
| 199 | continue
|
| 200 | if model._meta.app_label == self.model._meta.app_label:
|
| 201 | info = {"app": model._meta.app_label,
|
| 202 | "model": model._meta.model_name,
|
| 203 | "name": capfirst(model._meta.verbose_name_plural),
|
Scott Baker | ff3c2d2 | 2015-04-03 17:44:31 -0700 | [diff] [blame] | 204 | "url": self.url_for_model_changelist(request,model) }
|
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 205 | admins.append(info)
|
| 206 | extra_context["registered_admins"] = admins |
| 207 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 208 | def change_view(self,request,object_id, extra_context=None): |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 209 | extra_context = extra_context or {} |
| 210 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 211 | if self.__user_is_readonly(request): |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 212 | if not hasattr(self, "readonly_save"): |
| 213 | # save the original readonly fields |
| 214 | self.readonly_save = self.readonly_fields |
| 215 | self.inlines_save = self.inlines |
| 216 | if hasattr(self, "user_readonly_fields"): |
| 217 | self.readonly_fields=self.user_readonly_fields |
| 218 | if hasattr(self, "user_readonly_inlines"): |
| 219 | self.inlines = self.user_readonly_inlines |
| 220 | else: |
| 221 | if hasattr(self, "readonly_save"): |
| 222 | # restore the original readonly fields |
| 223 | self.readonly_fields = self.readonly_save |
| 224 | if hasattr(self, "inlines_save"): |
Scott Baker | af73e10 | 2014-04-22 22:40:07 -0700 | [diff] [blame] | 225 | self.inlines = self.inlines_save |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 226 | |
Scott Baker | ba534e7 | 2015-04-02 22:32:40 -0700 | [diff] [blame] | 227 | self.add_extra_context(request, extra_context) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 228 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 229 | try: |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 230 | return super(XOSAdminMixin, self).change_view(request, object_id, extra_context=extra_context) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 231 | except PermissionDenied: |
| 232 | pass |
Scott Baker | 2d281a9 | 2015-07-09 19:06:08 -0700 | [diff] [blame] | 233 | except ValidationError as e: |
| 234 | if (e.params is None): |
| 235 | # Validation errors that don't reference a specific field will |
| 236 | # often throw a non-descriptive 500 page to the user. The code |
| 237 | # below will cause an error message to be printed and the |
| 238 | # page refreshed instead. |
| 239 | # As a side-effect it turns the request back into a 'GET' which |
| 240 | # may wipe anything the user had changed on the page. But, at |
| 241 | # least the user gets a real error message. |
| 242 | # TODO: revisit this and display some kind of error view |
| 243 | request.method = 'GET' |
| 244 | messages.error(request, e.message) |
| 245 | return super(XOSAdminMixin, self).change_view(request, object_id, extra_context=extra_context) |
| 246 | else: |
| 247 | raise |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 248 | if request.method == 'POST': |
| 249 | raise PermissionDenied |
| 250 | request.readonly = True |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 251 | return super(XOSAdminMixin, self).change_view(request, object_id, extra_context=extra_context) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 252 | |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 253 | def changelist_view(self, request, extra_context = None): |
| 254 | extra_context = extra_context or {} |
| 255 | |
Scott Baker | ba534e7 | 2015-04-02 22:32:40 -0700 | [diff] [blame] | 256 | self.add_extra_context(request, extra_context) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 257 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 258 | return super(XOSAdminMixin, self).changelist_view(request, extra_context=extra_context) |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 259 | |
Scott Baker | 2aea036 | 2015-04-14 17:01:18 -0700 | [diff] [blame] | 260 | def add_view(self, request, form_url='', extra_context = None): |
Scott Baker | ff3c2d2 | 2015-04-03 17:44:31 -0700 | [diff] [blame] | 261 | extra_context = extra_context or {} |
| 262 | |
| 263 | self.add_extra_context(request, extra_context) |
| 264 | |
Scott Baker | 2aea036 | 2015-04-14 17:01:18 -0700 | [diff] [blame] | 265 | return super(XOSAdminMixin, self).add_view(request, form_url, extra_context=extra_context) |
Scott Baker | ff3c2d2 | 2015-04-03 17:44:31 -0700 | [diff] [blame] | 266 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 267 | def __user_is_readonly(self, request): |
| 268 | return request.user.isReadOnlyUser() |
| 269 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 270 | def backend_status_text(self, obj): |
| 271 | return mark_safe(backend_text(obj)) |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 272 | |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 273 | def backend_status_icon(self, obj): |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 274 | return mark_safe(backend_icon(obj)) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 275 | backend_status_icon.short_description = "" |
| 276 | |
Scott Baker | 24ded6a | 2014-11-05 09:05:38 -0800 | [diff] [blame] | 277 | def get_form(self, request, obj=None, **kwargs): |
Scott Baker | 5c43269 | 2014-10-16 00:57:55 -0700 | [diff] [blame] | 278 | # Save obj and request in thread-local storage, so suit_form_tabs can |
| 279 | # use it to determine whether we're in edit or add mode, and can |
| 280 | # determine whether the user is an admin. |
| 281 | _thread_locals.request = request |
| 282 | _thread_locals.obj = obj |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 283 | return super(XOSAdminMixin, self).get_form(request, obj, **kwargs) |
Scott Baker | 5c43269 | 2014-10-16 00:57:55 -0700 | [diff] [blame] | 284 | |
| 285 | def get_inline_instances(self, request, obj=None): |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 286 | inlines = super(XOSAdminMixin, self).get_inline_instances(request, obj) |
Scott Baker | 5c43269 | 2014-10-16 00:57:55 -0700 | [diff] [blame] | 287 | |
| 288 | # inlines that should only be shown to an admin user |
| 289 | if request.user.is_admin: |
| 290 | for inline_class in getattr(self, "admin_inlines", []): |
| 291 | inlines.append(inline_class(self.model, self.admin_site)) |
| 292 | |
| 293 | return inlines |
| 294 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 295 | class ReadOnlyAwareAdmin(XOSAdminMixin, admin.ModelAdmin): |
| 296 | # Note: Make sure XOSAdminMixin is listed before |
Scott Baker | 86c83ab | 2014-10-03 13:10:47 -0700 | [diff] [blame] | 297 | # admin.ModelAdmin in the class declaration. |
| 298 | |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 299 | pass |
| 300 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 301 | class XOSBaseAdmin(ReadOnlyAwareAdmin): |
Scott Baker | cbfb600 | 2014-10-03 00:32:37 -0700 | [diff] [blame] | 302 | save_on_top = False |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 303 | |
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 304 | class SingletonAdmin (ReadOnlyAwareAdmin): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 305 | def has_add_permission(self, request): |
Scott Baker | e8859f9 | 2014-05-23 12:42:40 -0700 | [diff] [blame] | 306 | if not super(SingletonAdmin, self).has_add_permission(request): |
| 307 | return False |
| 308 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 309 | num_objects = self.model.objects.count() |
| 310 | if num_objects >= 1: |
| 311 | return False |
| 312 | else: |
| 313 | return True |
| 314 | |
Scott Baker | 7a056af | 2015-02-26 20:42:11 -0800 | [diff] [blame] | 315 | class ServiceAppAdmin (SingletonAdmin): |
Scott Baker | c481b32 | 2015-02-27 12:12:14 -0800 | [diff] [blame] | 316 | extracontext_registered_admins = True |
Scott Baker | 7a056af | 2015-02-26 20:42:11 -0800 | [diff] [blame] | 317 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 318 | class XOSTabularInline(admin.TabularInline): |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 319 | def __init__(self, *args, **kwargs): |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 320 | super(XOSTabularInline, self).__init__(*args, **kwargs) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 321 | |
| 322 | # InlineModelAdmin as no get_fields() method, so in order to add |
| 323 | # the selflink field, we override __init__ to modify self.fields and |
| 324 | # self.readonly_fields. |
| 325 | |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 326 | self.setup_selflink() |
| 327 | |
Scott Baker | d5df950 | 2015-07-24 09:32:14 -0700 | [diff] [blame] | 328 | @property |
| 329 | def selflink_model(self): |
| 330 | if hasattr(self, "selflink_fieldname"): |
| 331 | """ self.selflink_model can be defined to punch through a relation |
| 332 | to its target object. For example, in SliceNetworkInline, set |
| 333 | selflink_model = "network", and the URL will lead to the Network |
| 334 | object instead of trying to bring up a change view of the |
| 335 | SliceNetwork object. |
| 336 | """ |
| 337 | return getattr(self.model,self.selflink_fieldname).field.rel.to |
| 338 | else: |
| 339 | return self.model |
| 340 | |
| 341 | @property |
| 342 | def selflink_reverse_path(self): |
| 343 | return "admin:%s_change" % (self.selflink_model._meta.db_table) |
| 344 | |
| 345 | def get_change_url(self, id): |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 346 | """ Get the URL to a change form in the admin for this model """ |
Scott Baker | 2978678 | 2015-07-27 08:53:05 -0700 | [diff] [blame] | 347 | reverse_path = self.selflink_reverse_path # "admin:%s_change" % (self.selflink_model._meta.db_table) |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 348 | try: |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 349 | url = reverse(reverse_path, args=(id,)) |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 350 | except NoReverseMatch: |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 351 | return None |
| 352 | |
| 353 | return url |
| 354 | |
| 355 | def setup_selflink(self): |
Scott Baker | d5df950 | 2015-07-24 09:32:14 -0700 | [diff] [blame] | 356 | url = self.get_change_url(0) |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 357 | |
| 358 | # We don't have an admin for this object, so don't create the |
| 359 | # selflink. |
| 360 | if (url == None): |
Scott Baker | e2bbf7e | 2014-01-13 12:09:31 -0800 | [diff] [blame] | 361 | return |
| 362 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 363 | # Since we need to add "selflink" to the field list, we need to create |
| 364 | # self.fields if it is None. |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 365 | if (self.fields is None): |
| 366 | self.fields = [] |
| 367 | for f in self.model._meta.fields: |
| 368 | if f.editable and f.name != "id": |
| 369 | self.fields.append(f.name) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 370 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 371 | self.fields = tuple(self.fields) + ("selflink", ) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 372 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 373 | if self.readonly_fields is None: |
| 374 | self.readonly_fields = () |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 375 | |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 376 | self.readonly_fields = tuple(self.readonly_fields) + ("selflink", ) |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 377 | |
| 378 | def selflink(self, obj): |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 379 | if hasattr(self, "selflink_fieldname"): |
| 380 | obj = getattr(obj, self.selflink_fieldname) |
| 381 | |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 382 | if obj.id: |
Scott Baker | d5df950 | 2015-07-24 09:32:14 -0700 | [diff] [blame] | 383 | url = self.get_change_url(obj.id) |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 384 | return "<a href='%s'>Details</a>" % str(url) |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 385 | else: |
| 386 | return "Not present" |
Scott Baker | 8656832 | 2014-01-12 16:53:31 -0800 | [diff] [blame] | 387 | |
| 388 | selflink.allow_tags = True |
| 389 | selflink.short_description = "Details" |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 390 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 391 | def has_add_permission(self, request): |
| 392 | return not request.user.isReadOnlyUser() |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 393 | |
| 394 | def get_readonly_fields(self, request, obj=None): |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 395 | readonly_fields = list(self.readonly_fields)[:] |
| 396 | if request.user.isReadOnlyUser(): |
| 397 | for field in self.fields: |
| 398 | if not field in readonly_fields: |
| 399 | readonly_fields.append(field) |
| 400 | return readonly_fields |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 401 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 402 | def backend_status_icon(self, obj): |
| 403 | return mark_safe(backend_icon(obj)) |
| 404 | backend_status_icon.short_description = "" |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 405 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 406 | class PlStackGenericTabularInline(generic.GenericTabularInline): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 407 | def has_add_permission(self, request): |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 408 | return not request.user.isReadOnlyUser() |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 409 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 410 | def get_readonly_fields(self, request, obj=None): |
| 411 | readonly_fields = list(self.readonly_fields)[:] |
| 412 | if request.user.isReadOnlyUser(): |
| 413 | for field in self.fields: |
| 414 | if not field in readonly_fields: |
| 415 | readonly_fields.append(field) |
| 416 | return readonly_fields |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 417 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 418 | def backend_status_icon(self, obj): |
| 419 | return mark_safe(backend_icon(obj)) |
| 420 | backend_status_icon.short_description = "" |
| 421 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 422 | class ReservationInline(XOSTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 423 | model = Reservation |
| 424 | extra = 0 |
| 425 | suit_classes = 'suit-tab suit-tab-reservations' |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 426 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 427 | def queryset(self, request): |
| 428 | return Reservation.select_by_user(request.user) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 429 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 430 | class TagInline(PlStackGenericTabularInline): |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 431 | model = Tag |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 432 | extra = 0 |
| 433 | suit_classes = 'suit-tab suit-tab-tags' |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 434 | fields = ['service', 'name', 'value'] |
| 435 | |
| 436 | def queryset(self, request): |
| 437 | return Tag.select_by_user(request.user) |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 438 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 439 | class InstanceInline(XOSTabularInline): |
| 440 | model = Instance |
Scott Baker | 4103eb3 | 2015-09-21 14:52:15 -0700 | [diff] [blame] | 441 | fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 442 | extra = 0 |
Scott Baker | 4103eb3 | 2015-09-21 14:52:15 -0700 | [diff] [blame] | 443 | max_num = 0 |
Scott Baker | 0befcd7 | 2015-09-21 15:10:18 -0700 | [diff] [blame] | 444 | readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'deployment', 'flavor', 'image', 'node'] |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 445 | suit_classes = 'suit-tab suit-tab-instances' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 446 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 447 | def queryset(self, request): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 448 | return Instance.select_by_user(request.user) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 449 | |
Scott Baker | b24cc93 | 2014-06-09 10:51:16 -0700 | [diff] [blame] | 450 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 451 | if db_field.name == 'deployment': |
Tony Mack | bd908ae | 2015-02-24 15:41:49 -0500 | [diff] [blame] | 452 | kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct() |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 453 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"}) |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 454 | if db_field.name == 'flavor': |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 455 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"}) |
Scott Baker | 3b67874 | 2014-06-09 13:11:54 -0700 | [diff] [blame] | 456 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 457 | field = super(InstanceInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Scott Baker | b24cc93 | 2014-06-09 10:51:16 -0700 | [diff] [blame] | 458 | |
| 459 | return field |
| 460 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 461 | class CordInstanceInline(XOSTabularInline): |
| 462 | model = Instance |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 463 | fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'slice', 'flavor', 'image', 'node'] |
| 464 | extra = 0 |
| 465 | readonly_fields = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name'] |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 466 | suit_classes = 'suit-tab suit-tab-instances' |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 467 | |
| 468 | def queryset(self, request): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 469 | return Instance.select_by_user(request.user) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 470 | |
| 471 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
| 472 | if db_field.name == 'deployment': |
| 473 | |
| 474 | kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct() |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 475 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"}) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 476 | if db_field.name == 'flavor': |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 477 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"}) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 478 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 479 | field = super(CordInstanceInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 480 | |
| 481 | return field |
| 482 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 483 | class SiteInline(XOSTabularInline): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 484 | model = Site |
| 485 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 486 | suit_classes = 'suit-tab suit-tab-sites' |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 487 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 488 | def queryset(self, request): |
| 489 | return Site.select_by_user(request.user) |
| 490 | |
Tony Mack | 15136b5 | 2015-08-04 17:53:23 -0400 | [diff] [blame] | 491 | class SiteHostsNodesInline(SiteInline): |
| 492 | def queryset(self, request): |
| 493 | return Site.select_by_user(request.user).filter(hosts_nodes=True) |
| 494 | |
| 495 | class SiteHostsUsersInline(SiteInline): |
| 496 | def queryset(self, request): |
| 497 | return Site.select_by_user(request.user).filter(hosts_users=True) |
| 498 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 499 | class UserInline(XOSTabularInline): |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 500 | model = User |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 501 | fields = ['backend_status_icon', 'email', 'firstname', 'lastname'] |
| 502 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 503 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 504 | suit_classes = 'suit-tab suit-tab-users' |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 505 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 506 | def queryset(self, request): |
| 507 | return User.select_by_user(request.user) |
| 508 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 509 | class SliceInline(XOSTabularInline): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 510 | model = Slice |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 511 | fields = ['backend_status_icon', 'name', 'site', 'serviceClass', 'service'] |
| 512 | readonly_fields = ('backend_status_icon', ) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 513 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 514 | suit_classes = 'suit-tab suit-tab-slices' |
| 515 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 516 | def queryset(self, request): |
| 517 | return Slice.select_by_user(request.user) |
| 518 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 519 | class NodeInline(XOSTabularInline): |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 520 | model = Node |
| 521 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 522 | suit_classes = 'suit-tab suit-tab-nodes' |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 523 | fields = ['backend_status_icon', 'name', 'site_deployment'] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 524 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 525 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 526 | class DeploymentPrivilegeInline(XOSTabularInline): |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 527 | model = DeploymentPrivilege |
| 528 | extra = 0 |
Tony Mack | 4ce14c4 | 2015-02-09 21:41:57 -0500 | [diff] [blame] | 529 | suit_classes = 'suit-tab suit-tab-deploymentprivileges' |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 530 | fields = ['backend_status_icon', 'user','role','deployment'] |
| 531 | readonly_fields = ('backend_status_icon', ) |
| 532 | |
| 533 | def queryset(self, request): |
| 534 | return DeploymentPrivilege.select_by_user(request.user) |
| 535 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 536 | class ControllerSiteInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 537 | model = ControllerSite |
| 538 | extra = 0 |
| 539 | suit_classes = 'suit-tab suit-tab-admin-only' |
Tony Mack | 8f30ebe | 2015-01-06 15:08:20 -0500 | [diff] [blame] | 540 | fields = ['controller', 'site', 'tenant_id'] |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 541 | |
| 542 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 543 | class SitePrivilegeInline(XOSTabularInline): |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 544 | model = SitePrivilege |
| 545 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 546 | suit_classes = 'suit-tab suit-tab-siteprivileges' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 547 | fields = ['backend_status_icon', 'user','site', 'role'] |
| 548 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 549 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 550 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 551 | if db_field.name == 'site': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 552 | kwargs['queryset'] = Site.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 553 | |
| 554 | if db_field.name == 'user': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 555 | kwargs['queryset'] = User.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 556 | return super(SitePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 557 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 558 | def queryset(self, request): |
| 559 | return SitePrivilege.select_by_user(request.user) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 560 | |
Tony Mack | 8d108e2 | 2015-05-11 20:39:32 -0400 | [diff] [blame] | 561 | |
| 562 | class ServicePrivilegeInline(XOSTabularInline): |
| 563 | model = ServicePrivilege |
| 564 | extra = 0 |
| 565 | suit_classes = 'suit-tab suit-tab-serviceprivileges' |
| 566 | fields = ['backend_status_icon', 'user','service', 'role'] |
| 567 | readonly_fields = ('backend_status_icon', ) |
| 568 | |
| 569 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 570 | if db_field.name == 'service': |
| 571 | kwargs['queryset'] = Service.select_by_user(request.user) |
Tony Mack | cf88f8c | 2015-05-15 06:33:45 -0400 | [diff] [blame] | 572 | if db_field.name == 'user': |
| 573 | kwargs['queryset'] = User.select_by_user(request.user) |
| 574 | return super(ServicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | 8d108e2 | 2015-05-11 20:39:32 -0400 | [diff] [blame] | 575 | |
| 576 | def queryset(self, request): |
| 577 | return ServicePrivilege.select_by_user(request.user) |
| 578 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 579 | class SiteDeploymentInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 580 | model = SiteDeployment |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 581 | extra = 0 |
Tony Mack | 1081225 | 2015-01-30 10:58:29 -0500 | [diff] [blame] | 582 | suit_classes = 'suit-tab suit-tab-sitedeployments' |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 583 | fields = ['backend_status_icon', 'deployment','site', 'controller'] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 584 | readonly_fields = ('backend_status_icon', ) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 585 | |
| 586 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 587 | if db_field.name == 'site': |
| 588 | kwargs['queryset'] = Site.select_by_user(request.user) |
| 589 | |
| 590 | if db_field.name == 'deployment': |
| 591 | kwargs['queryset'] = Deployment.select_by_user(request.user) |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 592 | |
| 593 | if db_field.name == 'controller': |
Scott Baker | 4103eb3 | 2015-09-21 14:52:15 -0700 | [diff] [blame] | 594 | if len(resolve(request.path).args) > 0: |
| 595 | kwargs['queryset'] = Controller.select_by_user(request.user).filter(deployment__id=int(resolve(request.path).args[0])) |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 596 | |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 597 | return super(SiteDeploymentInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 598 | |
| 599 | def queryset(self, request): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 600 | return SiteDeployment.select_by_user(request.user) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 601 | |
| 602 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 603 | class SlicePrivilegeInline(XOSTabularInline): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 604 | model = SlicePrivilege |
| 605 | suit_classes = 'suit-tab suit-tab-sliceprivileges' |
| 606 | extra = 0 |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 607 | fields = ('backend_status_icon', 'user', 'slice', 'role') |
| 608 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 609 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 610 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 611 | if db_field.name == 'slice': |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 612 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 613 | if db_field.name == 'user': |
Scott Baker | 521abcc | 2015-07-16 12:40:07 -0700 | [diff] [blame] | 614 | # all users are available to be granted SlicePrivilege |
| 615 | kwargs['queryset'] = User.objects.all() |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 616 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 617 | return super(SlicePrivilegeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 618 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 619 | def queryset(self, request): |
| 620 | return SlicePrivilege.select_by_user(request.user) |
| 621 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 622 | class SliceNetworkInline(XOSTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 623 | model = Network.slices.through |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 624 | selflink_fieldname = "network" |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 625 | extra = 0 |
| 626 | verbose_name = "Network Connection" |
| 627 | verbose_name_plural = "Network Connections" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 628 | suit_classes = 'suit-tab suit-tab-slicenetworks' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 629 | fields = ['backend_status_icon', 'network'] |
| 630 | readonly_fields = ('backend_status_icon', ) |
Scott Baker | 2170b97 | 2014-06-03 12:14:07 -0700 | [diff] [blame] | 631 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 632 | class ImageDeploymentsInline(XOSTabularInline): |
Sapan Bhatia | e9f96f6 | 2014-11-19 15:10:16 -0500 | [diff] [blame] | 633 | model = ImageDeployments |
Scott Baker | 2170b97 | 2014-06-03 12:14:07 -0700 | [diff] [blame] | 634 | extra = 0 |
| 635 | verbose_name = "Image Deployments" |
| 636 | verbose_name_plural = "Image Deployments" |
| 637 | suit_classes = 'suit-tab suit-tab-imagedeployments' |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 638 | fields = ['backend_status_icon', 'image', 'deployment'] |
| 639 | readonly_fields = ['backend_status_icon'] |
| 640 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 641 | class ControllerImagesInline(XOSTabularInline): |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 642 | model = ControllerImages |
| 643 | extra = 0 |
| 644 | verbose_name = "Controller Images" |
| 645 | verbose_name_plural = "Controller Images" |
| 646 | suit_classes = 'suit-tab suit-tab-admin-only' |
| 647 | fields = ['backend_status_icon', 'image', 'controller', 'glance_image_id'] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 648 | readonly_fields = ['backend_status_icon', 'glance_image_id'] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 649 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 650 | class SliceRoleAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 651 | model = SliceRole |
| 652 | pass |
| 653 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 654 | class SiteRoleAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 655 | model = SiteRole |
| 656 | pass |
| 657 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 658 | class DeploymentAdminForm(forms.ModelForm): |
Scott Baker | de0f441 | 2014-06-11 15:40:26 -0700 | [diff] [blame] | 659 | images = forms.ModelMultipleChoiceField( |
| 660 | queryset=Image.objects.all(), |
| 661 | required=False, |
| 662 | help_text="Select which images should be deployed on this deployment", |
| 663 | widget=FilteredSelectMultiple( |
| 664 | verbose_name=('Images'), is_stacked=False |
| 665 | ) |
| 666 | ) |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 667 | flavors = forms.ModelMultipleChoiceField( |
| 668 | queryset=Flavor.objects.all(), |
| 669 | required=False, |
| 670 | help_text="Select which flavors should be usable on this deployment", |
| 671 | widget=FilteredSelectMultiple( |
| 672 | verbose_name=('Flavors'), is_stacked=False |
| 673 | ) |
| 674 | ) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 675 | class Meta: |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 676 | model = Deployment |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 677 | many_to_many = ["flavors",] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 678 | |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 679 | def __init__(self, *args, **kwargs): |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 680 | request = kwargs.pop('request', None) |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 681 | super(DeploymentAdminForm, self).__init__(*args, **kwargs) |
| 682 | |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 683 | self.fields['accessControl'].initial = "allow site " + request.user.site.name |
| 684 | |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 685 | if self.instance and self.instance.pk: |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 686 | self.fields['images'].initial = [x.image for x in self.instance.imagedeployments.all()] |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 687 | self.fields['flavors'].initial = self.instance.flavors.all() |
Scott Baker | de0f441 | 2014-06-11 15:40:26 -0700 | [diff] [blame] | 688 | |
| 689 | def manipulate_m2m_objs(self, this_obj, selected_objs, all_relations, relation_class, local_attrname, foreign_attrname): |
| 690 | """ helper function for handling m2m relations from the MultipleChoiceField |
| 691 | |
| 692 | this_obj: the source object we want to link from |
| 693 | |
| 694 | selected_objs: a list of destination objects we want to link to |
| 695 | |
| 696 | all_relations: the full set of relations involving this_obj, including ones we don't want |
| 697 | |
| 698 | relation_class: the class that implements the relation from source to dest |
| 699 | |
| 700 | local_attrname: field name representing this_obj in relation_class |
| 701 | |
| 702 | foreign_attrname: field name representing selected_objs in relation_class |
| 703 | |
| 704 | This function will remove all newobjclass relations from this_obj |
| 705 | that are not contained in selected_objs, and add any relations that |
| 706 | are in selected_objs but don't exist in the data model yet. |
| 707 | """ |
| 708 | |
| 709 | existing_dest_objs = [] |
| 710 | for relation in list(all_relations): |
| 711 | if getattr(relation, foreign_attrname) not in selected_objs: |
| 712 | #print "deleting site", sdp.site |
| 713 | relation.delete() |
| 714 | else: |
| 715 | existing_dest_objs.append(getattr(relation, foreign_attrname)) |
| 716 | |
| 717 | for dest_obj in selected_objs: |
| 718 | if dest_obj not in existing_dest_objs: |
| 719 | #print "adding site", site |
| 720 | kwargs = {foreign_attrname: dest_obj, local_attrname: this_obj} |
| 721 | relation = relation_class(**kwargs) |
| 722 | relation.save() |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 723 | |
| 724 | def save(self, commit=True): |
| 725 | deployment = super(DeploymentAdminForm, self).save(commit=False) |
| 726 | |
| 727 | if commit: |
| 728 | deployment.save() |
Scott Baker | 61b6aec | 2014-10-06 17:17:40 -0700 | [diff] [blame] | 729 | # this has to be done after save() if/when a deployment is first created |
| 730 | deployment.flavors = self.cleaned_data['flavors'] |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 731 | |
| 732 | if deployment.pk: |
Scott Baker | c9b14f7 | 2014-05-22 13:44:20 -0700 | [diff] [blame] | 733 | # save_m2m() doesn't seem to work with 'through' relations. So we |
| 734 | # create/destroy the through models ourselves. There has to be |
| 735 | # a better way... |
| 736 | |
Tony Mack | 592aa95 | 2014-12-15 11:45:02 -0500 | [diff] [blame] | 737 | self.manipulate_m2m_objs(deployment, self.cleaned_data['images'], deployment.imagedeployments.all(), ImageDeployments, "deployment", "image") |
| 738 | # manipulate_m2m_objs doesn't work for Flavor/Deployment relationship |
| 739 | # so well handle that manually here |
| 740 | for flavor in deployment.flavors.all(): |
| 741 | if getattr(flavor, 'name') not in self.cleaned_data['flavors']: |
Tony Mack | 11f4d20 | 2014-12-15 12:37:59 -0500 | [diff] [blame] | 742 | deployment.flavors.remove(flavor) |
Tony Mack | 592aa95 | 2014-12-15 11:45:02 -0500 | [diff] [blame] | 743 | for flavor in self.cleaned_data['flavors']: |
| 744 | if flavor not in deployment.flavors.all(): |
| 745 | flavor.deployments.add(deployment) |
Scott Baker | c9b14f7 | 2014-05-22 13:44:20 -0700 | [diff] [blame] | 746 | |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 747 | self.save_m2m() |
Siobhan Tully | 320b462 | 2014-01-17 15:11:14 -0500 | [diff] [blame] | 748 | |
| 749 | return deployment |
| 750 | |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 751 | class DeploymentAdminROForm(DeploymentAdminForm): |
| 752 | def save(self, commit=True): |
| 753 | raise PermissionDenied |
| 754 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 755 | class SiteAssocInline(XOSTabularInline): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 756 | model = Site.deployments.through |
| 757 | extra = 0 |
| 758 | suit_classes = 'suit-tab suit-tab-sites' |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 759 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 760 | class DeploymentAdmin(XOSBaseAdmin): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 761 | model = Deployment |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 762 | fieldList = ['backend_status_text', 'name', 'images', 'flavors', 'accessControl'] |
| 763 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 764 | # node no longer directly connected to deployment |
| 765 | #inlines = [DeploymentPrivilegeInline,NodeInline,TagInline,ImageDeploymentsInline] |
Tony Mack | 1081225 | 2015-01-30 10:58:29 -0500 | [diff] [blame] | 766 | inlines = [DeploymentPrivilegeInline,TagInline,ImageDeploymentsInline,SiteDeploymentInline] |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 767 | list_display = ['backend_status_icon', 'name'] |
| 768 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 769 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 770 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 771 | user_readonly_fields = ['name'] |
| 772 | |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 773 | # nodes no longer direclty connected to deployments |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 774 | suit_form_tabs =(('general','Deployment Details'),('deploymentprivileges','Privileges'), ('sitedeployments', 'Sites')) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 775 | |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 776 | def get_form(self, request, obj=None, **kwargs): |
Tony Mack | d893dfb | 2015-02-05 06:13:04 -0500 | [diff] [blame] | 777 | if request.user.isReadOnlyUser() or not request.user.is_admin: |
Scott Baker | ff5e0f3 | 2014-05-22 14:40:27 -0700 | [diff] [blame] | 778 | kwargs["form"] = DeploymentAdminROForm |
| 779 | else: |
| 780 | kwargs["form"] = DeploymentAdminForm |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 781 | adminForm = super(DeploymentAdmin,self).get_form(request, obj, **kwargs) |
| 782 | |
| 783 | # from stackexchange: pass the request object into the form |
| 784 | |
| 785 | class AdminFormMetaClass(adminForm): |
| 786 | def __new__(cls, *args, **kwargs): |
| 787 | kwargs['request'] = request |
| 788 | return adminForm(*args, **kwargs) |
| 789 | |
| 790 | return AdminFormMetaClass |
| 791 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 792 | class ControllerAdmin(XOSBaseAdmin): |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 793 | model = Controller |
svavilap | fa144d8 | 2015-10-13 23:50:03 -0400 | [diff] [blame] | 794 | fieldList = ['deployment', 'name', 'backend_type', 'version', 'auth_url', 'admin_user', 'admin_tenant','admin_password', 'domain', 'rabbit_host', 'rabbit_user', 'rabbit_password'] |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 795 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 796 | inlines = [ControllerSiteInline] # ,ControllerImagesInline] |
Tony Mack | 528d422 | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 797 | list_display = ['backend_status_icon', 'name', 'version', 'backend_type'] |
| 798 | list_display_links = ('backend_status_icon', 'name', ) |
| 799 | readonly_fields = ('backend_status_text',) |
| 800 | |
| 801 | user_readonly_fields = [] |
| 802 | |
Tony Mack | c36cafb | 2015-01-13 17:33:08 -0500 | [diff] [blame] | 803 | def save_model(self, request, obj, form, change): |
| 804 | # update openstack connection to use this site/tenant |
| 805 | obj.save_by_user(request.user) |
| 806 | |
| 807 | def delete_model(self, request, obj): |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 808 | obj.delete_by_user(request.user) |
| 809 | |
Tony Mack | 79e2e66 | 2015-02-18 11:41:36 -0500 | [diff] [blame] | 810 | def queryset(self, request): |
| 811 | return Controller.select_by_user(request.user) |
| 812 | |
Scott Baker | ae233f4 | 2015-02-10 08:40:34 -0800 | [diff] [blame] | 813 | @property |
| 814 | def suit_form_tabs(self): |
| 815 | tabs = [('general', 'Controller Details'), |
| 816 | ] |
| 817 | |
| 818 | request=getattr(_thread_locals, "request", None) |
| 819 | if request and request.user.is_admin: |
| 820 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 821 | |
| 822 | return tabs |
Tony Mack | c36cafb | 2015-01-13 17:33:08 -0500 | [diff] [blame] | 823 | |
Scott Baker | 462a1d9 | 2015-10-15 15:59:19 -0700 | [diff] [blame] | 824 | class TenantAttributeAdmin(XOSBaseAdmin): |
| 825 | model = TenantAttribute |
| 826 | list_display = ('backend_status_icon', 'tenant', 'name', 'value') |
| 827 | list_display_links = ('backend_status_icon', 'name') |
| 828 | fieldList = ('backend_status_text', 'tenant', 'name', 'value', ) |
| 829 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
| 830 | readonly_fields = ('backend_status_text', ) |
| 831 | |
| 832 | suit_form_tabs =(('general', 'Tenant Root Details'), |
| 833 | ) |
| 834 | |
| 835 | class TenantAttrAsTabInline(XOSTabularInline): |
| 836 | model = TenantAttribute |
| 837 | fields = ['name','value'] |
| 838 | extra = 0 |
| 839 | suit_classes = 'suit-tab suit-tab-tenantattrs' |
| 840 | |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 841 | class TenantRootRoleAdmin(XOSBaseAdmin): |
| 842 | model = TenantRootRole |
| 843 | fields = ('role',) |
| 844 | |
| 845 | class TenantRootTenantInline(XOSTabularInline): |
| 846 | model = Tenant |
| 847 | fields = ['provider_service', 'subscriber_root'] |
| 848 | extra = 0 |
| 849 | suit_classes = 'suit-tab suit-tab-tenantroots' |
| 850 | fk_name = 'subscriber_root' |
| 851 | verbose_name = 'subscribed tenant' |
| 852 | verbose_name_plural = 'subscribed tenants' |
| 853 | |
| 854 | #def queryset(self, request): |
| 855 | # qs = super(TenantRootTenantInline, self).queryset(request) |
| 856 | # return qs.filter(kind="coarse") |
| 857 | |
| 858 | class TenantRootPrivilegeInline(XOSTabularInline): |
| 859 | model = TenantRootPrivilege |
| 860 | extra = 0 |
| 861 | suit_classes = 'suit-tab suit-tab-tenantrootprivileges' |
| 862 | fields = ['backend_status_icon', 'user', 'role', 'tenant_root'] |
| 863 | readonly_fields = ('backend_status_icon', ) |
| 864 | |
| 865 | def queryset(self, request): |
| 866 | return TenantRootPrivilege.select_by_user(request.user) |
| 867 | |
| 868 | class TenantRootAdmin(XOSBaseAdmin): |
| 869 | model = TenantRoot |
| 870 | list_display = ('backend_status_icon', 'name', 'kind') |
| 871 | list_display_links = ('backend_status_icon', 'name') |
| 872 | fieldList = ('backend_status_text', 'name', 'kind', ) |
| 873 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
| 874 | inlines = (TenantRootTenantInline, TenantRootPrivilegeInline) |
| 875 | readonly_fields = ('backend_status_text', ) |
| 876 | |
| 877 | suit_form_tabs =(('general', 'Tenant Root Details'), |
| 878 | ('tenantroots','Tenancy'), |
| 879 | ('tenantrootprivileges','Privileges') |
| 880 | ) |
| 881 | |
Scott Baker | 925a8fa | 2015-04-26 20:30:40 -0700 | [diff] [blame] | 882 | class ProviderTenantInline(XOSTabularInline): |
| 883 | model = CoarseTenant |
| 884 | fields = ['provider_service', 'subscriber_service', 'connect_method'] |
| 885 | extra = 0 |
| 886 | suit_classes = 'suit-tab suit-tab-servicetenants' |
| 887 | fk_name = 'provider_service' |
| 888 | verbose_name = 'provided tenant' |
| 889 | verbose_name_plural = 'provided tenants' |
| 890 | |
| 891 | def queryset(self, request): |
| 892 | qs = super(ProviderTenantInline, self).queryset(request) |
| 893 | return qs.filter(kind="coarse") |
| 894 | |
| 895 | class SubscriberTenantInline(XOSTabularInline): |
| 896 | model = CoarseTenant |
| 897 | fields = ['provider_service', 'subscriber_service', 'connect_method'] |
| 898 | extra = 0 |
| 899 | suit_classes = 'suit-tab suit-tab-servicetenants' |
| 900 | fk_name = 'subscriber_service' |
| 901 | verbose_name = 'subscribed tenant' |
| 902 | verbose_name_plural = 'subscribed tenants' |
| 903 | |
| 904 | def queryset(self, request): |
| 905 | qs = super(SubscriberTenantInline, self).queryset(request) |
| 906 | return qs.filter(kind="coarse") |
| 907 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 908 | class ServiceAttrAsTabInline(XOSTabularInline): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 909 | model = ServiceAttribute |
| 910 | fields = ['name','value'] |
| 911 | extra = 0 |
| 912 | suit_classes = 'suit-tab suit-tab-serviceattrs' |
| 913 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 914 | class ServiceAdmin(XOSBaseAdmin): |
Scott Baker | 008a996 | 2015-04-15 20:58:20 -0700 | [diff] [blame] | 915 | list_display = ("backend_status_icon","name","kind","versionNumber","enabled","published") |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 916 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | f60c010 | 2015-11-12 16:22:52 -0800 | [diff] [blame] | 917 | fieldList = ["backend_status_text","name","kind","description","versionNumber","enabled","published","view_url","icon_url","public_key","private_key_fn","service_specific_attribute","service_specific_id"] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 918 | fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})] |
Tony Mack | 8d108e2 | 2015-05-11 20:39:32 -0400 | [diff] [blame] | 919 | inlines = [ServiceAttrAsTabInline,SliceInline,ProviderTenantInline,SubscriberTenantInline,ServicePrivilegeInline] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 920 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 921 | |
| 922 | user_readonly_fields = fieldList |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 923 | |
| 924 | suit_form_tabs =(('general', 'Service Details'), |
| 925 | ('slices','Slices'), |
| 926 | ('serviceattrs','Additional Attributes'), |
Scott Baker | 925a8fa | 2015-04-26 20:30:40 -0700 | [diff] [blame] | 927 | ('servicetenants','Tenancy'), |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 928 | ('serviceprivileges','Privileges') |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 929 | ) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 930 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 931 | class SiteNodeInline(XOSTabularInline): |
Tony Mack | 82df1d0 | 2015-01-14 20:58:38 -0500 | [diff] [blame] | 932 | model = Node |
| 933 | fields = ['name', 'site_deployment'] |
| 934 | extra = 0 |
| 935 | suit_classes = 'suit-tab suit-tab-nodes' |
| 936 | |
Tony Mack | 26b5953 | 2015-02-25 11:39:34 -0500 | [diff] [blame] | 937 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 938 | # only display site deployments associated with this site |
| 939 | if db_field.name == 'site_deployment': |
| 940 | kwargs['queryset'] = SiteDeployment.objects.filter(site__id=int(request.path.split('/')[-2])) |
| 941 | |
| 942 | return super(SiteNodeInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 943 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 944 | class SiteAdmin(XOSBaseAdmin): |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 945 | #fieldList = ['backend_status_text', 'name', 'site_url', 'enabled', 'is_public', 'login_base', 'accountLink','location'] |
Tony Mack | 2862dca | 2015-08-04 17:21:55 -0400 | [diff] [blame] | 946 | fieldList = ['backend_status_text', 'name', 'site_url', 'enabled', 'login_base', 'location', 'is_public', 'hosts_nodes', 'hosts_users'] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 947 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 948 | (None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}), |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 949 | #('Deployment Networks', {'fields': ['deployments'], 'classes':['suit-tab suit-tab-deployments']}), |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 950 | ] |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 951 | #readonly_fields = ['backend_status_text', 'accountLink'] |
| 952 | readonly_fields = ['backend_status_text'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 953 | |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 954 | #user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'accountLink'] |
Tony Mack | 2862dca | 2015-08-04 17:21:55 -0400 | [diff] [blame] | 955 | user_readonly_fields = ['name', 'deployments','site_url', 'enabled', 'is_public', 'login_base', 'hosts_nodes', 'hosts_users'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 956 | |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 957 | list_display = ('backend_status_icon', 'name', 'login_base','site_url', 'enabled') |
| 958 | list_display_links = ('backend_status_icon', 'name', ) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 959 | filter_horizontal = ('deployments',) |
Tony Mack | 1081225 | 2015-01-30 10:58:29 -0500 | [diff] [blame] | 960 | inlines = [SliceInline,UserInline,TagInline, SitePrivilegeInline, SiteNodeInline] |
Tony Mack | 10328a1 | 2015-01-14 12:11:05 -0500 | [diff] [blame] | 961 | admin_inlines = [ControllerSiteInline] |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 962 | search_fields = ['name'] |
| 963 | |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 964 | @property |
| 965 | def suit_form_tabs(self): |
| 966 | tabs = [('general', 'Site Details'), |
| 967 | ('users','Users'), |
| 968 | ('siteprivileges','Privileges'), |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 969 | ('slices','Slices'), |
Tony Mack | 82df1d0 | 2015-01-14 20:58:38 -0500 | [diff] [blame] | 970 | ('nodes','Nodes'), |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 971 | ] |
| 972 | |
| 973 | request=getattr(_thread_locals, "request", None) |
| 974 | if request and request.user.is_admin: |
| 975 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 976 | |
| 977 | return tabs |
| 978 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 979 | def queryset(self, request): |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 980 | return Site.select_by_user(request.user) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 981 | |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame] | 982 | def get_formsets(self, request, obj=None): |
| 983 | for inline in self.get_inline_instances(request, obj): |
| 984 | # hide MyInline in the add view |
| 985 | if obj is None: |
| 986 | continue |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 987 | if isinstance(inline, InstanceInline): |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 988 | inline.model.caller = request.user |
Tony Mack | 5cd1320 | 2013-05-01 21:48:38 -0400 | [diff] [blame] | 989 | yield inline.get_formset(request, obj) |
| 990 | |
Scott Baker | 545db2a | 2013-12-09 18:44:43 -0800 | [diff] [blame] | 991 | def accountLink(self, obj): |
| 992 | link_obj = obj.accounts.all() |
| 993 | if link_obj: |
| 994 | reverse_path = "admin:core_account_change" |
| 995 | url = reverse(reverse_path, args =(link_obj[0].id,)) |
| 996 | return "<a href='%s'>%s</a>" % (url, "view billing details") |
| 997 | else: |
| 998 | return "no billing data for this site" |
| 999 | accountLink.allow_tags = True |
| 1000 | accountLink.short_description = "Billing" |
| 1001 | |
Tony Mack | 332ee1d | 2014-02-04 15:33:45 -0500 | [diff] [blame] | 1002 | def save_model(self, request, obj, form, change): |
| 1003 | # update openstack connection to use this site/tenant |
| 1004 | obj.save_by_user(request.user) |
| 1005 | |
| 1006 | def delete_model(self, request, obj): |
| 1007 | obj.delete_by_user(request.user) |
| 1008 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1009 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1010 | class SitePrivilegeAdmin(XOSBaseAdmin): |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1011 | fieldList = ['backend_status_text', 'user', 'site', 'role'] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1012 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1013 | (None, {'fields': fieldList, 'classes':['collapse']}) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1014 | ] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1015 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1016 | list_display = ('backend_status_icon', 'user', 'site', 'role') |
| 1017 | list_display_links = list_display |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1018 | user_readonly_fields = fieldList |
| 1019 | user_readonly_inlines = [] |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1020 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1021 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1022 | if db_field.name == 'site': |
| 1023 | if not request.user.is_admin: |
| 1024 | # only show sites where user is an admin or pi |
| 1025 | sites = set() |
| 1026 | for site_privilege in SitePrivilege.objects.filer(user=request.user): |
| 1027 | if site_privilege.role.role_type in ['admin', 'pi']: |
| 1028 | sites.add(site_privilege.site) |
| 1029 | kwargs['queryset'] = Site.objects.filter(site__in=list(sites)) |
| 1030 | |
| 1031 | if db_field.name == 'user': |
| 1032 | if not request.user.is_admin: |
| 1033 | # only show users from sites where caller has admin or pi role |
| 1034 | roles = Role.objects.filter(role_type__in=['admin', 'pi']) |
| 1035 | site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles) |
| 1036 | sites = [site_privilege.site for site_privilege in site_privileges] |
| 1037 | site_privileges = SitePrivilege.objects.filter(site__in=sites) |
| 1038 | emails = [site_privilege.user.email for site_privilege in site_privileges] |
| 1039 | users = User.objects.filter(email__in=emails) |
| 1040 | kwargs['queryset'] = users |
| 1041 | |
| 1042 | return super(SitePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1043 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1044 | def queryset(self, request): |
| 1045 | # admins can see all privileges. Users can only see privileges at sites |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1046 | # where they have the admin role or pi role. |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1047 | qs = super(SitePrivilegeAdmin, self).queryset(request) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1048 | #if not request.user.is_admin: |
| 1049 | # roles = Role.objects.filter(role_type__in=['admin', 'pi']) |
| 1050 | # site_privileges = SitePrivilege.objects.filter(user=request.user).filter(role__in=roles) |
| 1051 | # login_bases = [site_privilege.site.login_base for site_privilege in site_privileges] |
| 1052 | # sites = Site.objects.filter(login_base__in=login_bases) |
| 1053 | # qs = qs.filter(site__in=sites) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1054 | return qs |
| 1055 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1056 | class SliceForm(forms.ModelForm): |
| 1057 | class Meta: |
| 1058 | model = Slice |
| 1059 | widgets = { |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 1060 | 'service': LinkedSelect |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1061 | } |
| 1062 | |
Tony Mack | 2cbd380 | 2014-09-29 16:10:52 -0400 | [diff] [blame] | 1063 | def clean(self): |
| 1064 | cleaned_data = super(SliceForm, self).clean() |
| 1065 | name = cleaned_data.get('name') |
Scott Baker | 6efad46 | 2014-10-06 23:09:59 -0700 | [diff] [blame] | 1066 | site = cleaned_data.get('site') |
Tony Mack | 585cb19 | 2014-10-22 12:54:19 -0400 | [diff] [blame] | 1067 | slice_id = self.instance.id |
| 1068 | if not site and slice_id: |
| 1069 | site = Slice.objects.get(id=slice_id).site |
Scott Baker | 6efad46 | 2014-10-06 23:09:59 -0700 | [diff] [blame] | 1070 | if (not isinstance(site,Site)): |
| 1071 | # previous code indicates 'site' could be a site_id and not a site? |
| 1072 | site = Slice.objects.get(id=site.id) |
Tony Mack | 2cbd380 | 2014-09-29 16:10:52 -0400 | [diff] [blame] | 1073 | if not name.startswith(site.login_base): |
| 1074 | raise forms.ValidationError('slice name must begin with %s' % site.login_base) |
| 1075 | return cleaned_data |
| 1076 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1077 | class ControllerSliceInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1078 | model = ControllerSlice |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1079 | extra = 0 |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1080 | verbose_name = "Controller Slices" |
| 1081 | verbose_name_plural = "Controller Slices" |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1082 | suit_classes = 'suit-tab suit-tab-admin-only' |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1083 | fields = ['backend_status_icon', 'controller', 'tenant_id'] |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1084 | readonly_fields = ('backend_status_icon', 'controller' ) |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1085 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1086 | class SliceAdmin(XOSBaseAdmin): |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 1087 | form = SliceForm |
Scott Baker | de08853 | 2015-12-14 19:37:55 -0800 | [diff] [blame] | 1088 | fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_instances', "default_isolation", "network"] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1089 | fieldsets = [('Slice Details', {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1090 | readonly_fields = ('backend_status_text', ) |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1091 | list_display = ('backend_status_icon', 'name', 'site','serviceClass', 'slice_url', 'max_instances') |
Tony Mack | 7d45990 | 2014-09-03 13:18:57 -0400 | [diff] [blame] | 1092 | list_display_links = ('backend_status_icon', 'name', ) |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1093 | normal_inlines = [SlicePrivilegeInline, InstanceInline, TagInline, ReservationInline, SliceNetworkInline] |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1094 | inlines = normal_inlines |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1095 | admin_inlines = [ControllerSliceInline] |
Scott Baker | 591fb06 | 2015-09-15 15:21:50 -0700 | [diff] [blame] | 1096 | suit_form_includes = (('slice_instance_tab.html', 'bottom', 'instances'),) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1097 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1098 | user_readonly_fields = fieldList |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1099 | |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1100 | @property |
| 1101 | def suit_form_tabs(self): |
| 1102 | tabs =[('general', 'Slice Details'), |
| 1103 | ('slicenetworks','Networks'), |
| 1104 | ('sliceprivileges','Privileges'), |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1105 | ('instances','Instances'), |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 1106 | #('reservations','Reservations'), |
Tony Mack | b34553e | 2015-01-15 14:44:06 -0500 | [diff] [blame] | 1107 | ('tags','Tags'), |
Scott Baker | c4efdc7 | 2014-10-15 16:54:04 -0700 | [diff] [blame] | 1108 | ] |
| 1109 | |
| 1110 | request=getattr(_thread_locals, "request", None) |
| 1111 | if request and request.user.is_admin: |
| 1112 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 1113 | |
| 1114 | return tabs |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1115 | |
| 1116 | def add_view(self, request, form_url='', extra_context=None): |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1117 | # Ugly hack for CORD |
| 1118 | self.inlines = self.normal_inlines |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1119 | # revert to default read-only fields |
| 1120 | self.readonly_fields = ('backend_status_text',) |
| 1121 | return super(SliceAdmin, self).add_view(request, form_url, extra_context=extra_context) |
| 1122 | |
| 1123 | def change_view(self, request, object_id, form_url='', extra_context=None): |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1124 | # cannot change the site of an existing slice so make the site field read only |
| 1125 | if object_id: |
| 1126 | self.readonly_fields = ('backend_status_text','site') |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1127 | |
Tony Mack | 7b8505a | 2014-10-22 11:54:29 -0400 | [diff] [blame] | 1128 | return super(SliceAdmin, self).change_view(request, object_id, form_url) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1129 | |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1130 | def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1131 | deployment_nodes = [] |
| 1132 | for node in Node.objects.all(): |
Scott Baker | 39293d7 | 2015-01-21 16:24:07 -0800 | [diff] [blame] | 1133 | deployment_nodes.append( (node.site_deployment.deployment.id, node.id, node.name) ) |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1134 | |
Scott Baker | 7a61dc4 | 2014-09-02 17:08:20 -0700 | [diff] [blame] | 1135 | deployment_flavors = [] |
| 1136 | for flavor in Flavor.objects.all(): |
| 1137 | for deployment in flavor.deployments.all(): |
| 1138 | deployment_flavors.append( (deployment.id, flavor.id, flavor.name) ) |
| 1139 | |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1140 | deployment_images = [] |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1141 | for image in Image.objects.all(): |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1142 | for deployment_image in image.imagedeployments.all(): |
Scott Baker | a6a0c77 | 2014-12-22 17:35:34 -0800 | [diff] [blame] | 1143 | deployment_images.append( (deployment_image.deployment.id, image.id, image.name) ) |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1144 | |
Tony Mack | ec23b99 | 2014-09-02 21:18:45 -0400 | [diff] [blame] | 1145 | site_login_bases = [] |
| 1146 | for site in Site.objects.all(): |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1147 | site_login_bases.append((site.id, site.login_base)) |
| 1148 | |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1149 | context["deployment_nodes"] = deployment_nodes |
Scott Baker | 7a61dc4 | 2014-09-02 17:08:20 -0700 | [diff] [blame] | 1150 | context["deployment_flavors"] = deployment_flavors |
Scott Baker | 93e80cd | 2014-09-09 09:58:49 -0700 | [diff] [blame] | 1151 | context["deployment_images"] = deployment_images |
Tony Mack | ec23b99 | 2014-09-02 21:18:45 -0400 | [diff] [blame] | 1152 | context["site_login_bases"] = site_login_bases |
Scott Baker | 510fdbb | 2014-08-05 17:19:24 -0700 | [diff] [blame] | 1153 | return super(SliceAdmin, self).render_change_form(request, context, add, change, form_url, obj) |
| 1154 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1155 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1156 | if db_field.name == 'site': |
Tony Mack | 15136b5 | 2015-08-04 17:53:23 -0400 | [diff] [blame] | 1157 | kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_users=True) |
Tony Mack | ec23b99 | 2014-09-02 21:18:45 -0400 | [diff] [blame] | 1158 | kwargs['widget'] = forms.Select(attrs={'onChange': "update_slice_prefix(this, $($(this).closest('fieldset')[0]).find('.field-name input')[0].id)"}) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1159 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1160 | return super(SliceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1161 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1162 | def queryset(self, request): |
| 1163 | # admins can see all keys. Users can only see slices they belong to. |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1164 | return Slice.select_by_user(request.user) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1165 | |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 1166 | def get_formsets(self, request, obj=None): |
| 1167 | for inline in self.get_inline_instances(request, obj): |
| 1168 | # hide MyInline in the add view |
| 1169 | if obj is None: |
| 1170 | continue |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1171 | if isinstance(inline, InstanceInline): |
Tony Mack | 2bd5b41 | 2013-06-11 21:05:06 -0400 | [diff] [blame] | 1172 | inline.model.caller = request.user |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 1173 | yield inline.get_formset(request, obj) |
| 1174 | |
Scott Baker | 03394b3 | 2015-09-15 17:48:57 -0700 | [diff] [blame] | 1175 | def add_extra_context(self, request, extra_context): |
| 1176 | super(SliceAdmin, self).add_extra_context(request, extra_context) |
| 1177 | # set context["slice_id"] to the PK passed in the URL to this view |
| 1178 | if len(request.resolver_match.args)>0: |
| 1179 | extra_context["slice_id"] = request.resolver_match.args[0] |
| 1180 | |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1181 | def UNUSED_get_inline_instances(self, request, obj=None): |
| 1182 | # HACK for CORD to do something special on vcpe slice page |
| 1183 | # this was a good idea, but failed miserably, as something still |
| 1184 | # expects there to be a deployment field. |
| 1185 | # XXX this approach is better than clobbering self.inlines, so |
| 1186 | # try to make this work post-demo. |
| 1187 | if (obj is not None) and (obj.name == "mysite_vcpe"): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1188 | cord_vcpe_inlines = [ SlicePrivilegeInline, CordInstanceInline, TagInline, ReservationInline,SliceNetworkInline] |
Scott Baker | 0e289fd | 2015-06-12 10:40:15 -0700 | [diff] [blame] | 1189 | |
| 1190 | inlines=[] |
| 1191 | for inline_class in cord_vcpe_inlines: |
| 1192 | inlines.append(inline_class(self.model, self.admin_site)) |
| 1193 | else: |
| 1194 | inlines = super(SliceAdmin, self).get_inline_instances(request, obj) |
| 1195 | |
| 1196 | return inlines |
| 1197 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1198 | class SlicePrivilegeAdmin(XOSBaseAdmin): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1199 | fieldsets = [ |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1200 | (None, {'fields': ['backend_status_text', 'user', 'slice', 'role']}) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1201 | ] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1202 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1203 | list_display = ('backend_status_icon', 'user', 'slice', 'role') |
| 1204 | list_display_links = list_display |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 1205 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1206 | user_readonly_fields = ['user', 'slice', 'role'] |
| 1207 | user_readonly_inlines = [] |
| 1208 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1209 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1210 | if db_field.name == 'slice': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1211 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1212 | |
| 1213 | if db_field.name == 'user': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1214 | kwargs['queryset'] = User.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1215 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1216 | return super(SlicePrivilegeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1217 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1218 | def queryset(self, request): |
| 1219 | # admins can see all memberships. Users can only see memberships of |
| 1220 | # slices where they have the admin role. |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1221 | return SlicePrivilege.select_by_user(request.user) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1222 | |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 1223 | def save_model(self, request, obj, form, change): |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1224 | # update openstack connection to use this site/tenant |
| 1225 | auth = request.session.get('auth', {}) |
Tony Mack | f7f79a1 | 2014-08-11 11:21:42 -0400 | [diff] [blame] | 1226 | auth['tenant'] = obj.slice.slicename |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1227 | obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 1228 | obj.save() |
| 1229 | |
| 1230 | def delete_model(self, request, obj): |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1231 | # update openstack connection to use this site/tenant |
| 1232 | auth = request.session.get('auth', {}) |
Tony Mack | f7f79a1 | 2014-08-11 11:21:42 -0400 | [diff] [blame] | 1233 | auth['tenant'] = obj.slice.slicename |
Tony Mack | 951dab4 | 2013-05-02 19:51:45 -0400 | [diff] [blame] | 1234 | obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
Tony Mack | 9bcbe4f | 2013-04-29 08:13:27 -0400 | [diff] [blame] | 1235 | obj.delete() |
| 1236 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1237 | class ImageAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1238 | |
Scott Baker | 36f5087 | 2014-08-21 13:01:25 -0700 | [diff] [blame] | 1239 | fieldsets = [('Image Details', |
Scott Baker | 1426623 | 2015-12-14 10:11:56 -0800 | [diff] [blame] | 1240 | {'fields': ['backend_status_text', 'name', 'kind', 'disk_format', 'container_format', 'tag', 'path'], |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1241 | 'classes': ['suit-tab suit-tab-general']}) |
| 1242 | ] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1243 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1244 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1245 | suit_form_tabs =(('general','Image Details'),('instances','Instances'),('imagedeployments','Deployments'), ('controllerimages', 'Controllers')) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1246 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1247 | inlines = [InstanceInline, ControllerImagesInline] |
Scott Baker | b6f9924 | 2014-06-11 11:34:44 -0700 | [diff] [blame] | 1248 | |
Scott Baker | 1426623 | 2015-12-14 10:11:56 -0800 | [diff] [blame] | 1249 | user_readonly_fields = ['name', 'disk_format', 'container_format', 'tag', 'path'] |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 1250 | |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1251 | list_display = ['backend_status_icon', 'name', 'kind'] |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1252 | list_display_links = ('backend_status_icon', 'name', ) |
| 1253 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1254 | class NodeForm(forms.ModelForm): |
| 1255 | class Meta: |
Scott Baker | 2a11f85 | 2015-09-21 15:06:38 -0700 | [diff] [blame] | 1256 | model = Node |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1257 | widgets = { |
| 1258 | 'site': LinkedSelect, |
| 1259 | 'deployment': LinkedSelect |
| 1260 | } |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1261 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1262 | class NodeAdmin(XOSBaseAdmin): |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1263 | form = NodeForm |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1264 | list_display = ('backend_status_icon', 'name', 'site_deployment') |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1265 | list_display_links = ('backend_status_icon', 'name', ) |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1266 | list_filter = ('site_deployment',) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1267 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1268 | inlines = [TagInline,InstanceInline] |
Scott Baker | 2a11f85 | 2015-09-21 15:06:38 -0700 | [diff] [blame] | 1269 | fieldsets = [('Node Details', {'fields': ['backend_status_text', 'name', 'site_deployment'], 'classes':['suit-tab suit-tab-details']})] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1270 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1271 | |
Tony Mack | 93d1b03 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 1272 | user_readonly_fields = ['name','site_deployment'] |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1273 | user_readonly_inlines = [TagInline,InstanceInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1274 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1275 | suit_form_tabs =(('details','Node Details'),('instances','Instances')) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1276 | |
Tony Mack | 17b97b8 | 2015-08-04 17:32:32 -0400 | [diff] [blame] | 1277 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1278 | if db_field.name == 'site': |
| 1279 | kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_nodes=True) |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 1280 | |
Scott Baker | 2a11f85 | 2015-09-21 15:06:38 -0700 | [diff] [blame] | 1281 | field = super(NodeAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1282 | |
| 1283 | return field |
| 1284 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1285 | class InstanceForm(forms.ModelForm): |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1286 | class Meta: |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1287 | model = Instance |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1288 | ip = forms.CharField(widget=PlainTextWidget) |
Tony Mack | 1826181 | 2013-05-02 16:39:20 -0400 | [diff] [blame] | 1289 | instance_name = forms.CharField(widget=PlainTextWidget) |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1290 | widgets = { |
| 1291 | 'ip': PlainTextWidget(), |
Tony Mack | 1826181 | 2013-05-02 16:39:20 -0400 | [diff] [blame] | 1292 | 'instance_name': PlainTextWidget(), |
Scott Baker | 887d4a8 | 2015-01-19 11:32:20 -0800 | [diff] [blame] | 1293 | 'instance_id': PlainTextWidget(), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1294 | 'slice': LinkedSelect, |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 1295 | 'deployment': LinkedSelect, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1296 | 'node': LinkedSelect, |
| 1297 | 'image': LinkedSelect |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1298 | } |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 1299 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1300 | class TagAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1301 | list_display = ['backend_status_icon', 'service', 'name', 'value', 'content_type', 'content_object',] |
| 1302 | list_display_links = list_display |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1303 | user_readonly_fields = ['service', 'name', 'value', 'content_type', 'content_object',] |
| 1304 | user_readonly_inlines = [] |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1305 | |
Tony Mack | 8bc36b9 | 2015-09-01 16:06:52 +0000 | [diff] [blame] | 1306 | class InstancePortInline(XOSTabularInline): |
Tony Mack | ea30da8 | 2015-09-10 21:58:15 +0000 | [diff] [blame] | 1307 | fields = ['backend_status_icon', 'network', 'instance', 'ip', 'mac'] |
Scott Baker | 0672e98 | 2015-09-08 18:22:15 -0700 | [diff] [blame] | 1308 | readonly_fields = ("backend_status_icon", "ip", "mac") |
Scott Baker | 43facad | 2015-08-26 09:43:33 -0700 | [diff] [blame] | 1309 | model = Port |
Scott Baker | 29514bc | 2015-11-16 16:21:47 -0800 | [diff] [blame] | 1310 | #selflink_fieldname = "network" |
Scott Baker | 0bdb6a5 | 2015-08-25 18:00:15 -0700 | [diff] [blame] | 1311 | extra = 0 |
| 1312 | verbose_name_plural = "Ports" |
| 1313 | verbose_name = "Port" |
| 1314 | suit_classes = 'suit-tab suit-tab-ports' |
| 1315 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1316 | class InstanceAdmin(XOSBaseAdmin): |
| 1317 | form = InstanceForm |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 1318 | fieldsets = [ |
Scott Baker | 04a356a | 2015-11-12 17:25:53 -0800 | [diff] [blame] | 1319 | ('Instance Details', {'fields': ['backend_status_text', 'slice', 'deployment', 'isolation', 'flavor', 'image', 'node', 'parent', 'all_ips_string', 'instance_id', 'instance_name', 'ssh_command', ], 'classes': ['suit-tab suit-tab-general'], }), |
Scott Baker | e1a6e0b | 2015-11-10 17:07:23 -0800 | [diff] [blame] | 1320 | ('Container Settings', {'fields': ['volumes'], 'classes': ['suit-tab suit-tab-container'], }), |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 1321 | ] |
Tony Mack | 7d61efb | 2015-01-30 17:20:46 -0500 | [diff] [blame] | 1322 | readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string') |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1323 | list_display = ['backend_status_icon', 'all_ips_string', 'instance_id', 'instance_name', 'isolation', 'slice', 'flavor', 'image', 'node', 'deployment'] |
Scott Baker | f0b403f | 2015-02-13 14:38:21 -0800 | [diff] [blame] | 1324 | list_display_links = ('backend_status_icon', 'all_ips_string', 'instance_id', ) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1325 | |
Scott Baker | e1a6e0b | 2015-11-10 17:07:23 -0800 | [diff] [blame] | 1326 | suit_form_tabs =(('general', 'Instance Details'), ('ports', 'Ports'), ('container', 'Container Settings')) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1327 | |
Tony Mack | 6a782f9 | 2015-09-13 22:50:39 +0000 | [diff] [blame] | 1328 | inlines = [TagInline, InstancePortInline] |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 1329 | |
Tony Mack | bf6aa30 | 2014-12-26 13:38:02 -0500 | [diff] [blame] | 1330 | user_readonly_fields = ['slice', 'deployment', 'node', 'ip', 'instance_name', 'flavor', 'image'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1331 | |
Scott Baker | 970314b | 2015-01-25 22:16:13 -0800 | [diff] [blame] | 1332 | def ssh_command(self, obj): |
| 1333 | ssh_command = obj.get_ssh_command() |
| 1334 | if ssh_command: |
| 1335 | return ssh_command |
| 1336 | else: |
| 1337 | return "(not available)" |
| 1338 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1339 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1340 | if db_field.name == 'slice': |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1341 | kwargs['queryset'] = Slice.select_by_user(request.user) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1342 | |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1343 | return super(InstanceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1344 | |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1345 | def queryset(self, request): |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1346 | # admins can see all instances. Users can only see instances of |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1347 | # the slices they belong to. |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1348 | return Instance.select_by_user(request.user) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1349 | |
Scott Baker | b84392d | 2015-09-21 21:42:41 -0700 | [diff] [blame] | 1350 | def add_view(self, request, form_url='', extra_context = None): |
| 1351 | self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string') |
| 1352 | return super(InstanceAdmin,self).add_view(request, form_url, extra_context) |
Tony Mack | 0406283 | 2013-05-10 08:22:44 -0400 | [diff] [blame] | 1353 | |
Scott Baker | b84392d | 2015-09-21 21:42:41 -0700 | [diff] [blame] | 1354 | def change_view(self, request, object_id, extra_context=None): |
| 1355 | self.readonly_fields = ('backend_status_text', 'ssh_command', 'all_ips_string', 'deployment', 'slice', 'flavor', 'image', 'node') |
| 1356 | self.readonly_save = self.readonly_fields # for XOSAdminMixin.change_view's user_readonly_fields switching code |
| 1357 | return super(InstanceAdmin,self).change_view(request, object_id, extra_context) |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 1358 | |
Scott Baker | 530e4de | 2015-09-21 16:02:54 -0700 | [diff] [blame] | 1359 | def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): |
| 1360 | deployment_nodes = [] |
| 1361 | for node in Node.objects.all(): |
| 1362 | deployment_nodes.append( (node.site_deployment.deployment.id, node.id, node.name) ) |
| 1363 | |
| 1364 | deployment_flavors = [] |
| 1365 | for flavor in Flavor.objects.all(): |
| 1366 | for deployment in flavor.deployments.all(): |
| 1367 | deployment_flavors.append( (deployment.id, flavor.id, flavor.name) ) |
| 1368 | |
| 1369 | deployment_images = [] |
| 1370 | for image in Image.objects.all(): |
| 1371 | for deployment_image in image.imagedeployments.all(): |
| 1372 | deployment_images.append( (deployment_image.deployment.id, image.id, image.name) ) |
| 1373 | |
| 1374 | site_login_bases = [] |
| 1375 | for site in Site.objects.all(): |
| 1376 | site_login_bases.append((site.id, site.login_base)) |
| 1377 | |
| 1378 | context["deployment_nodes"] = deployment_nodes |
| 1379 | context["deployment_flavors"] = deployment_flavors |
| 1380 | context["deployment_images"] = deployment_images |
| 1381 | context["site_login_bases"] = site_login_bases |
| 1382 | return super(InstanceAdmin, self).render_change_form(request, context, add, change, form_url, obj) |
| 1383 | |
| 1384 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
| 1385 | if db_field.name == 'deployment': |
| 1386 | kwargs['queryset'] = Deployment.select_by_acl(request.user).filter(sitedeployments__nodes__isnull=False).distinct() |
| 1387 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_deployment_changed(this);"}) |
| 1388 | if db_field.name == 'flavor': |
| 1389 | kwargs['widget'] = forms.Select(attrs={'onChange': "instance_flavor_changed(this);"}) |
| 1390 | |
| 1391 | field = super(InstanceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1392 | |
| 1393 | return field |
| 1394 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1395 | #def save_model(self, request, obj, form, change): |
| 1396 | # # update openstack connection to use this site/tenant |
| 1397 | # auth = request.session.get('auth', {}) |
| 1398 | # auth['tenant'] = obj.slice.name |
| 1399 | # obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
| 1400 | # obj.creator = request.user |
| 1401 | # obj.save() |
Tony Mack | 53106f3 | 2013-04-27 16:43:01 -0400 | [diff] [blame] | 1402 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1403 | #def delete_model(self, request, obj): |
| 1404 | # # update openstack connection to use this site/tenant |
| 1405 | # auth = request.session.get('auth', {}) |
| 1406 | # auth['tenant'] = obj.slice.name |
| 1407 | # obj.os_manager = OpenStackManager(auth=auth, caller=request.user) |
| 1408 | # obj.delete() |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 1409 | |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1410 | #class ContainerPortInline(XOSTabularInline): |
| 1411 | # fields = ['backend_status_icon', 'network', 'container', 'ip', 'mac', 'segmentation_id'] |
| 1412 | # readonly_fields = ("backend_status_icon", "ip", "mac", "segmentation_id") |
| 1413 | # model = Port |
| 1414 | # selflink_fieldname = "network" |
| 1415 | # extra = 0 |
| 1416 | # verbose_name_plural = "Ports" |
| 1417 | # verbose_name = "Port" |
| 1418 | # suit_classes = 'suit-tab suit-tab-ports' |
Scott Baker | 1de8b0d | 2015-10-26 19:52:10 -0700 | [diff] [blame] | 1419 | |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1420 | #class ContainerAdmin(XOSBaseAdmin): |
| 1421 | # fieldsets = [ |
| 1422 | # ('Container Details', {'fields': ['backend_status_text', 'slice', 'node', 'docker_image', 'volumes', 'no_sync'], 'classes': ['suit-tab suit-tab-general'], }) |
| 1423 | # ] |
| 1424 | # readonly_fields = ('backend_status_text', ) |
| 1425 | # list_display = ['backend_status_icon', 'id'] |
| 1426 | # list_display_links = ('backend_status_icon', 'id', ) |
| 1427 | # |
| 1428 | # suit_form_tabs =(('general', 'Container Details'), ('ports', 'Ports')) |
| 1429 | # |
| 1430 | # inlines = [TagInline, ContainerPortInline] |
| 1431 | # |
| 1432 | # def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1433 | # if db_field.name == 'slice': |
| 1434 | # kwargs['queryset'] = Slice.select_by_user(request.user) |
| 1435 | # |
| 1436 | # return super(ContainerAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1437 | # |
| 1438 | # def queryset(self, request): |
| 1439 | # # admins can see all instances. Users can only see instances of |
| 1440 | # # the slices they belong to. |
| 1441 | # return Container.select_by_user(request.user) |
Scott Baker | da51365 | 2015-10-26 15:12:13 -0700 | [diff] [blame] | 1442 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1443 | class UserCreationForm(forms.ModelForm): |
| 1444 | """A form for creating new users. Includes all the required |
| 1445 | fields, plus a repeated password.""" |
| 1446 | password1 = forms.CharField(label='Password', widget=forms.PasswordInput) |
| 1447 | password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput) |
| 1448 | |
| 1449 | class Meta: |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1450 | model = User |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1451 | fields = ('email', 'firstname', 'lastname', 'phone', 'public_key') |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1452 | |
| 1453 | def clean_password2(self): |
| 1454 | # Check that the two password entries match |
| 1455 | password1 = self.cleaned_data.get("password1") |
| 1456 | password2 = self.cleaned_data.get("password2") |
| 1457 | if password1 and password2 and password1 != password2: |
| 1458 | raise forms.ValidationError("Passwords don't match") |
| 1459 | return password2 |
| 1460 | |
| 1461 | def save(self, commit=True): |
| 1462 | # Save the provided password in hashed format |
| 1463 | user = super(UserCreationForm, self).save(commit=False) |
Tony Mack | f9f4afb | 2013-05-01 21:02:12 -0400 | [diff] [blame] | 1464 | user.password = self.cleaned_data["password1"] |
| 1465 | #user.set_password(self.cleaned_data["password1"]) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1466 | if commit: |
| 1467 | user.save() |
| 1468 | return user |
| 1469 | |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 1470 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1471 | class UserChangeForm(forms.ModelForm): |
| 1472 | """A form for updating users. Includes all the fields on |
| 1473 | the user, but replaces the password field with admin's |
| 1474 | password hash display field. |
| 1475 | """ |
Siobhan Tully | 63b7ba4 | 2014-01-12 10:35:11 -0500 | [diff] [blame] | 1476 | password = ReadOnlyPasswordHashField(label='Password', |
| 1477 | help_text= '<a href=\"password/\">Change Password</a>.') |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1478 | |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1479 | PROFILE_CHOICES = ((None, '------'), ('regular', 'Regular user'), ('cp', 'Content Provider')) |
| 1480 | profile = forms.ChoiceField(choices=PROFILE_CHOICES, required=False, label="Quick Profile") |
| 1481 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1482 | class Meta: |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1483 | model = User |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 1484 | widgets = { 'public_key': UploadTextareaWidget, } |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1485 | |
| 1486 | def clean_password(self): |
| 1487 | # Regardless of what the user provides, return the initial value. |
| 1488 | # This is done here, rather than on the field, because the |
| 1489 | # field does not have access to the initial value |
| 1490 | return self.initial["password"] |
| 1491 | |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1492 | def save(self, *args, **kwargs): |
| 1493 | if self.cleaned_data['profile']: |
| 1494 | self.instance.apply_profile(self.cleaned_data['profile']) |
| 1495 | |
| 1496 | return super(UserChangeForm, self).save(*args, **kwargs) |
| 1497 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1498 | class UserDashboardViewInline(XOSTabularInline): |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1499 | model = UserDashboardView |
| 1500 | extra = 0 |
| 1501 | suit_classes = 'suit-tab suit-tab-dashboards' |
| 1502 | fields = ['user', 'dashboardView', 'order'] |
| 1503 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1504 | class ControllerUserInline(XOSTabularInline): |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1505 | model = ControllerUser |
| 1506 | extra = 0 |
| 1507 | suit_classes = 'suit-tab suit-tab-admin-only' |
| 1508 | fields = ['controller', 'user', 'kuser_id'] |
| 1509 | readonly_fields=['controller'] |
| 1510 | |
| 1511 | |
Scott Baker | a9412c3 | 2015-02-27 12:21:22 -0800 | [diff] [blame] | 1512 | class UserAdmin(XOSAdminMixin, UserAdmin): |
| 1513 | # Note: Make sure XOSAdminMixin is listed before |
Scott Baker | 86c83ab | 2014-10-03 13:10:47 -0700 | [diff] [blame] | 1514 | # admin.ModelAdmin in the class declaration. |
| 1515 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1516 | class Meta: |
| 1517 | app_label = "core" |
| 1518 | |
| 1519 | # The forms to add and change user instances |
| 1520 | form = UserChangeForm |
| 1521 | add_form = UserCreationForm |
| 1522 | |
| 1523 | # The fields to be used in displaying the User model. |
| 1524 | # These override the definitions on the base UserAdmin |
| 1525 | # that reference specific fields on auth.User. |
Scott Baker | f587f44 | 2015-01-24 13:33:26 -0800 | [diff] [blame] | 1526 | list_display = ('backend_status_icon', 'email', 'firstname', 'lastname', 'site', 'last_login') |
| 1527 | list_display_links = ("email",) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1528 | list_filter = ('site',) |
Scott Baker | 6e9027f | 2015-01-29 10:55:53 -0800 | [diff] [blame] | 1529 | inlines = [SlicePrivilegeInline,SitePrivilegeInline] |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1530 | admin_inlines = [ControllerUserInline] |
Scott Baker | e61e3a0 | 2015-06-10 16:14:58 -0700 | [diff] [blame] | 1531 | fieldListLoginDetails = ['backend_status_text', 'email', 'site','password','is_active','is_readonly','is_admin','is_appuser', 'public_key', 'login_page', 'profile'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1532 | fieldListContactInfo = ['firstname','lastname','phone','timezone'] |
| 1533 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1534 | fieldsets = ( |
Scott Baker | 74ebc7a | 2015-05-15 09:19:36 -0700 | [diff] [blame] | 1535 | ('Login Details', {'fields': ['backend_status_text', 'email', 'site','password', 'is_active', 'is_readonly', 'is_admin', 'is_appuser', 'public_key'], 'classes':['suit-tab suit-tab-general']}), |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1536 | ('Contact Information', {'fields': ('firstname','lastname','phone', 'timezone'), 'classes':['suit-tab suit-tab-contact']}), |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1537 | #('Important dates', {'fields': ('last_login',)}), |
| 1538 | ) |
| 1539 | add_fieldsets = ( |
| 1540 | (None, { |
| 1541 | 'classes': ('wide',), |
Scott Baker | 74ebc7a | 2015-05-15 09:19:36 -0700 | [diff] [blame] | 1542 | 'fields': ('site', 'email', 'firstname', 'lastname', 'is_admin', 'is_readonly', 'is_appuser', 'phone', 'public_key','password1', 'password2')}, |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1543 | ), |
| 1544 | ) |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1545 | readonly_fields = ('backend_status_text', ) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 1546 | search_fields = ('email',) |
| 1547 | ordering = ('email',) |
| 1548 | filter_horizontal = () |
| 1549 | |
Scott Baker | 3ca51f6 | 2014-05-23 12:05:11 -0700 | [diff] [blame] | 1550 | user_readonly_fields = fieldListLoginDetails + fieldListContactInfo |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1551 | |
Scott Baker | 0a5633b | 2014-10-06 17:51:20 -0700 | [diff] [blame] | 1552 | @property |
| 1553 | def suit_form_tabs(self): |
| 1554 | if getattr(_thread_locals, "obj", None) is None: |
| 1555 | return [] |
| 1556 | else: |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1557 | tabs = [('general','Login Details'), |
Scott Baker | 0a5633b | 2014-10-06 17:51:20 -0700 | [diff] [blame] | 1558 | ('contact','Contact Information'), |
| 1559 | ('sliceprivileges','Slice Privileges'), |
Scott Baker | 6e9027f | 2015-01-29 10:55:53 -0800 | [diff] [blame] | 1560 | ('siteprivileges','Site Privileges')] |
Tony Mack | 3c01ff9 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 1561 | |
| 1562 | request=getattr(_thread_locals, "request", None) |
| 1563 | if request and request.user.is_admin: |
| 1564 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 1565 | |
| 1566 | return tabs |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1567 | |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1568 | def formfield_for_foreignkey(self, db_field, request, **kwargs): |
| 1569 | if db_field.name == 'site': |
Tony Mack | 17b97b8 | 2015-08-04 17:32:32 -0400 | [diff] [blame] | 1570 | kwargs['queryset'] = Site.select_by_user(request.user).filter(hosts_users=True) |
Tony Mack | c2835a9 | 2013-05-28 09:18:49 -0400 | [diff] [blame] | 1571 | |
| 1572 | return super(UserAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1573 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1574 | def queryset(self, request): |
| 1575 | return User.select_by_user(request.user) |
| 1576 | |
Tony Mack | 6235fc8 | 2015-01-25 21:58:30 -0500 | [diff] [blame] | 1577 | def get_form(self, request, obj=None, **kwargs): |
Tony Mack | b2c407f | 2015-01-28 12:37:12 -0500 | [diff] [blame] | 1578 | # copy login details list |
| 1579 | login_details_fields = list(self.fieldListLoginDetails) |
Tony Mack | 92b1205 | 2015-01-28 12:49:58 -0500 | [diff] [blame] | 1580 | if not request.user.is_admin: |
Scott Baker | 6e9027f | 2015-01-29 10:55:53 -0800 | [diff] [blame] | 1581 | # only admins can see 'is_admin' and 'is_readonly' fields |
Tony Mack | b2c407f | 2015-01-28 12:37:12 -0500 | [diff] [blame] | 1582 | if 'is_admin' in login_details_fields: |
| 1583 | login_details_fields.remove('is_admin') |
| 1584 | if 'is_readonly' in login_details_fields: |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1585 | login_details_fields.remove('is_readonly') |
| 1586 | if 'is_appuser' in login_details_fields: |
| 1587 | login_details_fields.remove('is_admin') |
| 1588 | if 'profile' in login_details_fields: |
| 1589 | login_details_fields.remove('profile') |
Tony Mack | 92b1205 | 2015-01-28 12:49:58 -0500 | [diff] [blame] | 1590 | #if len(request.user.siteprivileges.filter(role__role = 'pi')) > 0: |
Scott Baker | 811d447 | 2015-05-19 16:39:48 -0700 | [diff] [blame] | 1591 | # only admins and pis can change a user's site |
Tony Mack | 92b1205 | 2015-01-28 12:49:58 -0500 | [diff] [blame] | 1592 | # self.readonly_fields = ('backend_status_text', 'site') |
Tony Mack | b2c407f | 2015-01-28 12:37:12 -0500 | [diff] [blame] | 1593 | self.fieldsets = ( |
| 1594 | ('Login Details', {'fields': login_details_fields, 'classes':['suit-tab suit-tab-general']}), |
| 1595 | ('Contact Information', {'fields': self.fieldListContactInfo, 'classes':['suit-tab suit-tab-contact']}), |
| 1596 | ) |
Tony Mack | 6235fc8 | 2015-01-25 21:58:30 -0500 | [diff] [blame] | 1597 | return super(UserAdmin, self).get_form(request, obj, **kwargs) |
| 1598 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1599 | class ControllerDashboardViewInline(XOSTabularInline): |
Scott Baker | a6a0c77 | 2014-12-22 17:35:34 -0800 | [diff] [blame] | 1600 | model = ControllerDashboardView |
Scott Baker | eef5a6b | 2014-12-19 16:41:12 -0800 | [diff] [blame] | 1601 | extra = 0 |
| 1602 | fields = ["controller", "url"] |
| 1603 | suit_classes = 'suit-tab suit-tab-controllers' |
| 1604 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1605 | class DashboardViewAdmin(XOSBaseAdmin): |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1606 | fieldsets = [('Dashboard View Details', |
Scott Baker | ecc55ac | 2015-02-17 13:34:32 -0800 | [diff] [blame] | 1607 | {'fields': ['backend_status_text', 'name', 'url', 'enabled', 'deployments'], |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 1608 | 'classes': ['suit-tab suit-tab-general']}) |
| 1609 | ] |
Scott Baker | 9daf19c | 2015-01-18 16:46:26 -0800 | [diff] [blame] | 1610 | list_display = ["name", "enabled", "url"] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1611 | readonly_fields = ('backend_status_text', ) |
Scott Baker | a6a0c77 | 2014-12-22 17:35:34 -0800 | [diff] [blame] | 1612 | inlines = [ControllerDashboardViewInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1613 | |
Scott Baker | eef5a6b | 2014-12-19 16:41:12 -0800 | [diff] [blame] | 1614 | suit_form_tabs =(('general','Dashboard View Details'), |
| 1615 | ('controllers', 'Per-controller Dashboard Details')) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1616 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1617 | class ServiceResourceInline(XOSTabularInline): |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1618 | model = ServiceResource |
| 1619 | extra = 0 |
| 1620 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1621 | class ServiceClassAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1622 | list_display = ('backend_status_icon', 'name', 'commitment', 'membershipFee') |
| 1623 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1624 | inlines = [ServiceResourceInline] |
| 1625 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1626 | user_readonly_fields = ['name', 'commitment', 'membershipFee'] |
| 1627 | user_readonly_inlines = [] |
| 1628 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1629 | class ReservedResourceInline(XOSTabularInline): |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1630 | model = ReservedResource |
| 1631 | extra = 0 |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1632 | suit_classes = 'suit-tab suit-tab-reservedresources' |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1633 | |
| 1634 | def formfield_for_foreignkey(self, db_field, request=None, **kwargs): |
| 1635 | field = super(ReservedResourceInline, self).formfield_for_foreignkey(db_field, request, **kwargs) |
| 1636 | |
| 1637 | if db_field.name == 'resource': |
| 1638 | # restrict resources to those that the slice's service class allows |
| 1639 | if request._slice is not None: |
| 1640 | field.queryset = field.queryset.filter(serviceClass = request._slice.serviceClass, calendarReservable=True) |
| 1641 | if len(field.queryset) > 0: |
| 1642 | field.initial = field.queryset.all()[0] |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 1643 | else: |
| 1644 | field.queryset = field.queryset.none() |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 1645 | elif db_field.name == 'instance': |
| 1646 | # restrict instances to those that belong to the slice |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 1647 | if request._slice is not None: |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1648 | field.queryset = field.queryset.filter(slice = request._slice) |
| 1649 | else: |
S.Çağlar Onur | 0e59183 | 2015-02-24 17:28:09 -0500 | [diff] [blame] | 1650 | field.queryset = field.queryset.none() |
| 1651 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1652 | return field |
| 1653 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1654 | def queryset(self, request): |
| 1655 | return ReservedResource.select_by_user(request.user) |
| 1656 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1657 | class ReservationChangeForm(forms.ModelForm): |
| 1658 | class Meta: |
| 1659 | model = Reservation |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1660 | widgets = { |
| 1661 | 'slice' : LinkedSelect |
| 1662 | } |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1663 | |
| 1664 | class ReservationAddForm(forms.ModelForm): |
| 1665 | slice = forms.ModelChoiceField(queryset=Slice.objects.all(), widget=forms.Select(attrs={"onChange":"document.getElementById('id_refresh').value=1; submit()"})) |
| 1666 | refresh = forms.CharField(widget=forms.HiddenInput()) |
| 1667 | |
| 1668 | class Media: |
Scott Baker | 97468b7 | 2015-02-18 15:15:58 -0800 | [diff] [blame] | 1669 | css = {'all': ('xos.css',)} # .field-refresh { display: none; } |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1670 | |
| 1671 | def clean_slice(self): |
| 1672 | slice = self.cleaned_data.get("slice") |
| 1673 | x = ServiceResource.objects.filter(serviceClass = slice.serviceClass, calendarReservable=True) |
| 1674 | if len(x) == 0: |
| 1675 | raise forms.ValidationError("The slice you selected does not have a service class that allows reservations") |
| 1676 | return slice |
| 1677 | |
| 1678 | class Meta: |
| 1679 | model = Reservation |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1680 | widgets = { |
| 1681 | 'slice' : LinkedSelect |
| 1682 | } |
| 1683 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1684 | |
| 1685 | class ReservationAddRefreshForm(ReservationAddForm): |
| 1686 | """ This form is displayed when the Reservation Form receives an update |
| 1687 | from the Slice dropdown onChange handler. It doesn't validate the |
| 1688 | data and doesn't save the data. This will cause the form to be |
| 1689 | redrawn. |
| 1690 | """ |
| 1691 | |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1692 | """ don't validate anything other than slice """ |
| 1693 | dont_validate_fields = ("startTime", "duration") |
| 1694 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1695 | def full_clean(self): |
| 1696 | result = super(ReservationAddForm, self).full_clean() |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1697 | |
| 1698 | for fieldname in self.dont_validate_fields: |
| 1699 | if fieldname in self._errors: |
| 1700 | del self._errors[fieldname] |
| 1701 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1702 | return result |
| 1703 | |
| 1704 | """ don't save anything """ |
| 1705 | def is_valid(self): |
| 1706 | return False |
| 1707 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1708 | class ReservationAdmin(XOSBaseAdmin): |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1709 | fieldList = ['backend_status_text', 'slice', 'startTime', 'duration'] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1710 | fieldsets = [('Reservation Details', {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})] |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1711 | readonly_fields = ('backend_status_text', ) |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1712 | list_display = ('startTime', 'duration') |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1713 | form = ReservationAddForm |
| 1714 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1715 | suit_form_tabs = (('general','Reservation Details'), ('reservedresources','Reserved Resources')) |
| 1716 | |
| 1717 | inlines = [ReservedResourceInline] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1718 | user_readonly_fields = fieldList |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 1719 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1720 | def add_view(self, request, form_url='', extra_context=None): |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 1721 | timezone.activate(request.user.timezone) |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1722 | request._refresh = False |
| 1723 | request._slice = None |
| 1724 | if request.method == 'POST': |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1725 | # "refresh" will be set to "1" if the form was submitted due to |
| 1726 | # a change in the Slice dropdown. |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1727 | if request.POST.get("refresh","1") == "1": |
| 1728 | request._refresh = True |
| 1729 | request.POST["refresh"] = "0" |
Scott Baker | 8737e5f | 2013-05-17 09:35:32 -0700 | [diff] [blame] | 1730 | |
| 1731 | # Keep track of the slice that was selected, so the |
| 1732 | # reservedResource inline can filter items for the slice. |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1733 | request._slice = request.POST.get("slice",None) |
| 1734 | if (request._slice is not None): |
| 1735 | request._slice = Slice.objects.get(id=request._slice) |
| 1736 | |
| 1737 | result = super(ReservationAdmin, self).add_view(request, form_url, extra_context) |
| 1738 | return result |
| 1739 | |
Scott Baker | acd4514 | 2013-05-19 16:19:16 -0700 | [diff] [blame] | 1740 | def changelist_view(self, request, extra_context = None): |
| 1741 | timezone.activate(request.user.timezone) |
| 1742 | return super(ReservationAdmin, self).changelist_view(request, extra_context) |
| 1743 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1744 | def get_form(self, request, obj=None, **kwargs): |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1745 | request._obj_ = obj |
| 1746 | if obj is not None: |
| 1747 | # For changes, set request._slice to the slice already set in the |
| 1748 | # object. |
| 1749 | request._slice = obj.slice |
| 1750 | self.form = ReservationChangeForm |
| 1751 | else: |
| 1752 | if getattr(request, "_refresh", False): |
| 1753 | self.form = ReservationAddRefreshForm |
| 1754 | else: |
| 1755 | self.form = ReservationAddForm |
| 1756 | return super(ReservationAdmin, self).get_form(request, obj, **kwargs) |
| 1757 | |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1758 | def get_readonly_fields(self, request, obj=None): |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 1759 | if (obj is not None): |
| 1760 | # Prevent slice from being changed after the reservation has been |
| 1761 | # created. |
| 1762 | return ['slice'] |
| 1763 | else: |
Scott Baker | 133c921 | 2013-05-17 09:09:11 -0700 | [diff] [blame] | 1764 | return [] |
Scott Baker | 3de3e37 | 2013-05-10 16:50:44 -0700 | [diff] [blame] | 1765 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 1766 | def queryset(self, request): |
| 1767 | return Reservation.select_by_user(request.user) |
| 1768 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1769 | class NetworkParameterTypeAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1770 | list_display = ("backend_status_icon", "name", ) |
| 1771 | list_display_links = ('backend_status_icon', 'name', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1772 | user_readonly_fields = ['name'] |
| 1773 | user_readonly_inlines = [] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1774 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1775 | class RouterAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1776 | list_display = ("backend_status_icon", "name", ) |
| 1777 | list_display_links = ('backend_status_icon', 'name', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1778 | user_readonly_fields = ['name'] |
| 1779 | user_readonly_inlines = [] |
| 1780 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1781 | class RouterInline(XOSTabularInline): |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1782 | model = Router.networks.through |
| 1783 | extra = 0 |
| 1784 | verbose_name_plural = "Routers" |
| 1785 | verbose_name = "Router" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1786 | suit_classes = 'suit-tab suit-tab-routers' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1787 | |
Scott Baker | b27b62c | 2014-08-15 16:29:16 -0700 | [diff] [blame] | 1788 | class NetworkParameterInline(PlStackGenericTabularInline): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1789 | model = NetworkParameter |
Scott Baker | 618e379 | 2014-08-15 13:42:29 -0700 | [diff] [blame] | 1790 | extra = 0 |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1791 | verbose_name_plural = "Parameters" |
| 1792 | verbose_name = "Parameter" |
| 1793 | suit_classes = 'suit-tab suit-tab-netparams' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1794 | fields = ['backend_status_icon', 'parameter', 'value'] |
| 1795 | readonly_fields = ('backend_status_icon', ) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1796 | |
Scott Baker | 0bdb6a5 | 2015-08-25 18:00:15 -0700 | [diff] [blame] | 1797 | class NetworkPortInline(XOSTabularInline): |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 1798 | fields = ['backend_status_icon', 'network', 'instance', 'ip', 'mac'] |
Scott Baker | 0672e98 | 2015-09-08 18:22:15 -0700 | [diff] [blame] | 1799 | readonly_fields = ("backend_status_icon", "ip", "mac") |
Scott Baker | 43facad | 2015-08-26 09:43:33 -0700 | [diff] [blame] | 1800 | model = Port |
Scott Baker | f3e905d | 2015-11-16 13:43:38 -0800 | [diff] [blame] | 1801 | #selflink_fieldname = "instance" |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1802 | extra = 0 |
Scott Baker | a68e6e3 | 2015-08-25 17:11:30 -0700 | [diff] [blame] | 1803 | verbose_name_plural = "Ports" |
| 1804 | verbose_name = "Port" |
| 1805 | suit_classes = 'suit-tab suit-tab-ports' |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1806 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1807 | class NetworkSlicesInline(XOSTabularInline): |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1808 | model = NetworkSlice |
Scott Baker | 874936e | 2014-01-13 18:15:34 -0800 | [diff] [blame] | 1809 | selflink_fieldname = "slice" |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1810 | extra = 0 |
| 1811 | verbose_name_plural = "Slices" |
| 1812 | verbose_name = "Slice" |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1813 | suit_classes = 'suit-tab suit-tab-networkslices' |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1814 | fields = ['backend_status_icon', 'network','slice'] |
| 1815 | readonly_fields = ('backend_status_icon', ) |
Scott Baker | d7d2a39 | 2013-08-06 08:57:30 -0700 | [diff] [blame] | 1816 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1817 | class ControllerNetworkInline(XOSTabularInline): |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1818 | model = ControllerNetwork |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1819 | extra = 0 |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1820 | verbose_name_plural = "Controller Networks" |
| 1821 | verbose_name = "Controller Network" |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1822 | suit_classes = 'suit-tab suit-tab-admin-only' |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 1823 | fields = ['backend_status_icon', 'controller','net_id','subnet_id'] |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1824 | readonly_fields = ('backend_status_icon', ) |
| 1825 | |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 1826 | class NetworkForm(forms.ModelForm): |
| 1827 | class Meta: |
| 1828 | model = Network |
| 1829 | widgets = { |
| 1830 | 'topologyParameters': UploadTextareaWidget, |
| 1831 | 'controllerParameters': UploadTextareaWidget, |
| 1832 | } |
| 1833 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1834 | class NetworkAdmin(XOSBaseAdmin): |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1835 | list_display = ("backend_status_icon", "name", "subnet", "ports", "labels") |
| 1836 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1837 | readonly_fields = ("subnet", ) |
Scott Baker | 0bdb6a5 | 2015-08-25 18:00:15 -0700 | [diff] [blame] | 1838 | inlines = [NetworkParameterInline, NetworkPortInline, NetworkSlicesInline, RouterInline] |
Tony Mack | a7dbd42 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 1839 | admin_inlines = [ControllerNetworkInline] |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1840 | |
Scott Baker | 9f6b8ed | 2014-11-17 23:44:03 -0800 | [diff] [blame] | 1841 | form=NetworkForm |
| 1842 | |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1843 | fieldsets = [ |
Scott Baker | a4c11bd | 2015-08-21 16:40:53 -0700 | [diff] [blame] | 1844 | (None, {'fields': ['backend_status_text', 'name','template','ports','labels', |
| 1845 | 'owner','guaranteed_bandwidth', 'permit_all_slices', |
| 1846 | 'permitted_slices','network_id','router_id','subnet_id', |
| 1847 | 'subnet', 'autoconnect'], |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1848 | 'classes':['suit-tab suit-tab-general']}), |
Scott Baker | 0451fb6 | 2015-01-03 12:29:29 -0800 | [diff] [blame] | 1849 | (None, {'fields': ['topology_parameters', 'controller_url', 'controller_parameters'], |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1850 | 'classes':['suit-tab suit-tab-sdn']}), |
| 1851 | ] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1852 | |
Scott Baker | 40c0076 | 2014-08-21 16:55:59 -0700 | [diff] [blame] | 1853 | readonly_fields = ('backend_status_text', ) |
Scott Baker | a4c11bd | 2015-08-21 16:40:53 -0700 | [diff] [blame] | 1854 | user_readonly_fields = ['name','template','ports','labels','owner','guaranteed_bandwidth', |
| 1855 | 'permit_all_slices','permitted_slices','network_id','router_id', |
| 1856 | 'subnet_id','subnet','autoconnect'] |
Siobhan Tully | 2d95e48 | 2013-09-06 10:56:06 -0400 | [diff] [blame] | 1857 | |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1858 | @property |
| 1859 | def suit_form_tabs(self): |
| 1860 | tabs=[('general','Network Details'), |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1861 | ('sdn', 'SDN Configuration'), |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1862 | ('netparams', 'Parameters'), |
Scott Baker | a68e6e3 | 2015-08-25 17:11:30 -0700 | [diff] [blame] | 1863 | ('ports','Ports'), |
Scott Baker | fbb4586 | 2014-10-17 16:27:23 -0700 | [diff] [blame] | 1864 | ('networkslices','Slices'), |
| 1865 | ('routers','Routers'), |
| 1866 | ] |
| 1867 | |
| 1868 | request=getattr(_thread_locals, "request", None) |
| 1869 | if request and request.user.is_admin: |
| 1870 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 1871 | |
| 1872 | return tabs |
| 1873 | |
| 1874 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1875 | class NetworkTemplateAdmin(XOSBaseAdmin): |
Scott Baker | 81fa17f | 2015-01-03 12:03:38 -0800 | [diff] [blame] | 1876 | list_display = ("backend_status_icon", "name", "guaranteed_bandwidth", "visibility") |
Scott Baker | 63d1a55 | 2014-08-21 15:19:07 -0700 | [diff] [blame] | 1877 | list_display_links = ('backend_status_icon', 'name', ) |
Scott Baker | 81fa17f | 2015-01-03 12:03:38 -0800 | [diff] [blame] | 1878 | user_readonly_fields = ["name", "guaranteed_bandwidth", "visibility"] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1879 | user_readonly_inlines = [] |
Scott Baker | 29514bc | 2015-11-16 16:21:47 -0800 | [diff] [blame] | 1880 | inlines = [NetworkParameterInline,] |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1881 | fieldsets = [ |
Scott Baker | 9d5bf3b | 2015-12-09 15:44:55 -0800 | [diff] [blame] | 1882 | (None, {'fields': ['name', 'description', 'guaranteed_bandwidth', 'visibility', 'translation', 'access', 'shared_network_name', 'shared_network_id', 'topology_kind', 'controller_kind'], |
Scott Baker | 4024871 | 2014-11-17 16:04:45 -0800 | [diff] [blame] | 1883 | 'classes':['suit-tab suit-tab-general']}),] |
Scott Baker | 29514bc | 2015-11-16 16:21:47 -0800 | [diff] [blame] | 1884 | suit_form_tabs = (('general','Network Template Details'), ('netparams', 'Parameters') ) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 1885 | |
Scott Baker | f3e905d | 2015-11-16 13:43:38 -0800 | [diff] [blame] | 1886 | class PortAdmin(XOSBaseAdmin): |
| 1887 | list_display = ("backend_status_icon", "name", "id", "ip") |
| 1888 | list_display_links = ('backend_status_icon', 'id') |
| 1889 | readonly_fields = ("subnet", ) |
| 1890 | inlines = [NetworkParameterInline] |
| 1891 | |
| 1892 | fieldsets = [ |
| 1893 | (None, {'fields': ['backend_status_text', 'network', 'instance', 'ip', 'port_id', 'mac'], |
| 1894 | 'classes':['suit-tab suit-tab-general']}), |
| 1895 | ] |
| 1896 | |
| 1897 | readonly_fields = ('backend_status_text', ) |
| 1898 | suit_form_tabs = (('general', 'Port Details'), ('netparams', 'Parameters')) |
| 1899 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1900 | class FlavorAdmin(XOSBaseAdmin): |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 1901 | list_display = ("backend_status_icon", "name", "flavor", "order", "default") |
| 1902 | list_display_links = ("backend_status_icon", "name") |
| 1903 | user_readonly_fields = ("name", "flavor") |
| 1904 | fields = ("name", "description", "flavor", "order", "default") |
| 1905 | |
Tony Mack | 31c2b8f | 2013-04-26 20:01:42 -0400 | [diff] [blame] | 1906 | # register a signal that caches the user's credentials when they log in |
| 1907 | def cache_credentials(sender, user, request, **kwds): |
| 1908 | auth = {'username': request.POST['username'], |
| 1909 | 'password': request.POST['password']} |
| 1910 | request.session['auth'] = auth |
| 1911 | user_logged_in.connect(cache_credentials) |
| 1912 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1913 | def dollar_field(fieldName, short_description): |
| 1914 | def newFunc(self, obj): |
| 1915 | try: |
| 1916 | x= "$ %0.2f" % float(getattr(obj, fieldName, 0.0)) |
| 1917 | except: |
| 1918 | x=getattr(obj, fieldName, 0.0) |
| 1919 | return x |
| 1920 | newFunc.short_description = short_description |
| 1921 | return newFunc |
| 1922 | |
| 1923 | def right_dollar_field(fieldName, short_description): |
| 1924 | def newFunc(self, obj): |
| 1925 | try: |
| 1926 | #x= '<div align=right style="width:6em">$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0)) |
| 1927 | x= '<div align=right>$ %0.2f</div>' % float(getattr(obj, fieldName, 0.0)) |
| 1928 | except: |
| 1929 | x=getattr(obj, fieldName, 0.0) |
| 1930 | return x |
| 1931 | newFunc.short_description = short_description |
| 1932 | newFunc.allow_tags = True |
| 1933 | return newFunc |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1934 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1935 | class InvoiceChargeInline(XOSTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1936 | model = Charge |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1937 | extra = 0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1938 | verbose_name_plural = "Charges" |
| 1939 | verbose_name = "Charge" |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1940 | exclude = ['account'] |
Scott Baker | 9cb88a2 | 2013-12-09 18:56:00 -0800 | [diff] [blame] | 1941 | fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1942 | readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1943 | can_delete = False |
| 1944 | max_num = 0 |
| 1945 | |
| 1946 | dollar_amount = right_dollar_field("amount", "Amount") |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1947 | |
| 1948 | class InvoiceAdmin(admin.ModelAdmin): |
| 1949 | list_display = ("date", "account") |
| 1950 | |
| 1951 | inlines = [InvoiceChargeInline] |
| 1952 | |
Scott Baker | 9cb88a2 | 2013-12-09 18:56:00 -0800 | [diff] [blame] | 1953 | fields = ["date", "account", "dollar_amount"] |
| 1954 | readonly_fields = ["date", "account", "dollar_amount"] |
| 1955 | |
| 1956 | dollar_amount = dollar_field("amount", "Amount") |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1957 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1958 | class InvoiceInline(XOSTabularInline): |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1959 | model = Invoice |
| 1960 | extra = 0 |
| 1961 | verbose_name_plural = "Invoices" |
| 1962 | verbose_name = "Invoice" |
Scott Baker | 0165fac | 2014-01-13 11:49:26 -0800 | [diff] [blame] | 1963 | fields = ["date", "dollar_amount"] |
| 1964 | readonly_fields = ["date", "dollar_amount"] |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1965 | suit_classes = 'suit-tab suit-tab-accountinvoice' |
| 1966 | can_delete=False |
| 1967 | max_num=0 |
| 1968 | |
| 1969 | dollar_amount = right_dollar_field("amount", "Amount") |
| 1970 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1971 | class PendingChargeInline(XOSTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1972 | model = Charge |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1973 | extra = 0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1974 | verbose_name_plural = "Charges" |
| 1975 | verbose_name = "Charge" |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1976 | exclude = ["invoice"] |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1977 | fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
| 1978 | readonly_fields = ["date", "kind", "state", "object", "coreHours", "dollar_amount", "slice"] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1979 | suit_classes = 'suit-tab suit-tab-accountpendingcharges' |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1980 | can_delete=False |
| 1981 | max_num=0 |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1982 | |
| 1983 | def queryset(self, request): |
| 1984 | qs = super(PendingChargeInline, self).queryset(request) |
| 1985 | qs = qs.filter(state="pending") |
| 1986 | return qs |
| 1987 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1988 | dollar_amount = right_dollar_field("amount", "Amount") |
| 1989 | |
Scott Baker | 022cdcd | 2015-02-18 15:50:11 -0800 | [diff] [blame] | 1990 | class PaymentInline(XOSTabularInline): |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1991 | model=Payment |
| 1992 | extra = 1 |
| 1993 | verbose_name_plural = "Payments" |
| 1994 | verbose_name = "Payment" |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1995 | fields = ["date", "dollar_amount"] |
| 1996 | readonly_fields = ["date", "dollar_amount"] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 1997 | suit_classes = 'suit-tab suit-tab-accountpayments' |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 1998 | can_delete=False |
| 1999 | max_num=0 |
| 2000 | |
| 2001 | dollar_amount = right_dollar_field("amount", "Amount") |
| 2002 | |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2003 | class AccountAdmin(admin.ModelAdmin): |
| 2004 | list_display = ("site", "balance_due") |
| 2005 | |
| 2006 | inlines = [InvoiceInline, PaymentInline, PendingChargeInline] |
| 2007 | |
| 2008 | fieldsets = [ |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 2009 | (None, {'fields': ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'],'classes':['suit-tab suit-tab-general']}),] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2010 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2011 | readonly_fields = ['site', 'dollar_balance_due', 'dollar_total_invoices', 'dollar_total_payments'] |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2012 | |
| 2013 | suit_form_tabs =( |
| 2014 | ('general','Account Details'), |
| 2015 | ('accountinvoice', 'Invoices'), |
| 2016 | ('accountpayments', 'Payments'), |
| 2017 | ('accountpendingcharges','Pending Charges'), |
| 2018 | ) |
| 2019 | |
Scott Baker | 15cddfa | 2013-12-09 13:45:19 -0800 | [diff] [blame] | 2020 | dollar_balance_due = dollar_field("balance_due", "Balance Due") |
| 2021 | dollar_total_invoices = dollar_field("total_invoices", "Total Invoices") |
| 2022 | dollar_total_payments = dollar_field("total_payments", "Total Payments") |
| 2023 | |
Scott Baker | 2461bec | 2015-08-14 09:10:11 -0700 | [diff] [blame] | 2024 | class ProgramForm(forms.ModelForm): |
| 2025 | class Meta: |
| 2026 | model = Program |
| 2027 | widgets = { |
| 2028 | 'contents': UploadTextareaWidget(attrs={'rows': 20, 'cols': 80, 'class': "input-xxlarge"}), |
| 2029 | 'description': forms.Textarea(attrs={'rows': 3, 'cols': 80, 'class': 'input-xxlarge'}), |
| 2030 | 'messages': forms.Textarea(attrs={'rows': 20, 'cols': 80, 'class': 'input-xxlarge'}), |
| 2031 | 'output': forms.Textarea(attrs={'rows': 3, 'cols': 80, 'class': 'input-xxlarge'}) |
| 2032 | } |
| 2033 | |
| 2034 | class ProgramAdmin(XOSBaseAdmin): |
| 2035 | list_display = ("name", "status") |
| 2036 | list_display_links = ('name', "status") |
| 2037 | |
| 2038 | form=ProgramForm |
| 2039 | |
| 2040 | fieldsets = [ |
| 2041 | (None, {'fields': ['name', 'command', 'kind', 'description', 'output', 'status'], |
| 2042 | 'classes':['suit-tab suit-tab-general']}), |
| 2043 | (None, {'fields': ['contents'], |
| 2044 | 'classes':['suit-tab suit-tab-contents']}), |
| 2045 | (None, {'fields': ['messages'], |
| 2046 | 'classes':['suit-tab suit-tab-messages']}), |
| 2047 | ] |
| 2048 | |
| 2049 | readonly_fields = ("status",) |
| 2050 | |
| 2051 | @property |
| 2052 | def suit_form_tabs(self): |
| 2053 | tabs=[('general','Program Details'), |
| 2054 | ('contents','Program Source'), |
| 2055 | ('messages','Messages'), |
| 2056 | ] |
| 2057 | |
| 2058 | request=getattr(_thread_locals, "request", None) |
| 2059 | if request and request.user.is_admin: |
| 2060 | tabs.append( ('admin-only', 'Admin-Only') ) |
| 2061 | |
| 2062 | return tabs |
| 2063 | |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 2064 | # Now register the new UserAdmin... |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 2065 | admin.site.register(User, UserAdmin) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 2066 | # ... and, since we're not using Django's builtin permissions, |
| 2067 | # unregister the Group model from admin. |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 2068 | #admin.site.unregister(Group) |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 2069 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2070 | # When debugging it is often easier to see all the classes, but for regular use |
| 2071 | # only the top-levels should be displayed |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 2072 | showAll = False |
Scott Baker | 4310504 | 2013-12-06 23:23:36 -0800 | [diff] [blame] | 2073 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2074 | admin.site.register(Deployment, DeploymentAdmin) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 2075 | admin.site.register(Controller, ControllerAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 2076 | admin.site.register(Site, SiteAdmin) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 2077 | admin.site.register(Slice, SliceAdmin) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 2078 | admin.site.register(Service, ServiceAdmin) |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 2079 | #admin.site.register(Reservation, ReservationAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 2080 | admin.site.register(Network, NetworkAdmin) |
Scott Baker | f3e905d | 2015-11-16 13:43:38 -0800 | [diff] [blame] | 2081 | admin.site.register(Port, PortAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 2082 | admin.site.register(Router, RouterAdmin) |
Scott Baker | 74d8e62 | 2013-07-29 16:04:22 -0700 | [diff] [blame] | 2083 | admin.site.register(NetworkTemplate, NetworkTemplateAdmin) |
Scott Baker | 2461bec | 2015-08-14 09:10:11 -0700 | [diff] [blame] | 2084 | admin.site.register(Program, ProgramAdmin) |
Tony Mack | 598eaf2 | 2015-01-25 12:35:29 -0500 | [diff] [blame] | 2085 | #admin.site.register(Account, AccountAdmin) |
| 2086 | #admin.site.register(Invoice, InvoiceAdmin) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2087 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 2088 | if True: |
| 2089 | admin.site.register(NetworkParameterType, NetworkParameterTypeAdmin) |
| 2090 | admin.site.register(ServiceClass, ServiceClassAdmin) |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 2091 | admin.site.register(Tag, TagAdmin) |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 2092 | admin.site.register(ControllerRole) |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 2093 | admin.site.register(SiteRole) |
| 2094 | admin.site.register(SliceRole) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2095 | admin.site.register(Node, NodeAdmin) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 2096 | #admin.site.register(SlicePrivilege, SlicePrivilegeAdmin) |
| 2097 | #admin.site.register(SitePrivilege, SitePrivilegeAdmin) |
Tony Mack | 3de59e3 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 2098 | admin.site.register(Instance, InstanceAdmin) |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 2099 | admin.site.register(Image, ImageAdmin) |
Scott Baker | 2c3cb64 | 2014-05-19 17:55:56 -0700 | [diff] [blame] | 2100 | admin.site.register(DashboardView, DashboardViewAdmin) |
Scott Baker | 37b4790 | 2014-09-02 14:37:41 -0700 | [diff] [blame] | 2101 | admin.site.register(Flavor, FlavorAdmin) |
Scott Baker | 1b06b6c | 2015-07-06 14:40:20 -0700 | [diff] [blame] | 2102 | admin.site.register(TenantRoot, TenantRootAdmin) |
| 2103 | admin.site.register(TenantRootRole, TenantRootRoleAdmin) |
Scott Baker | 462a1d9 | 2015-10-15 15:59:19 -0700 | [diff] [blame] | 2104 | admin.site.register(TenantAttribute, TenantAttributeAdmin) |
Scott Baker | 0cefa53 | 2015-11-09 16:17:11 -0800 | [diff] [blame] | 2105 | # admin.site.register(Container, ContainerAdmin) |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 2106 | |