Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 17 | NETWORK_CHOICES = ((None, 'Default'), ('host', 'Host'), ('bridged', 'Bridged'), ('noauto', 'No Automatic Networks')) |
| 18 | |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 19 | @property |
| 20 | def slicename(self): |
| 21 | return "%s_%s" % (self.site.login_base, self.name) |
| 22 | |
Sapan Bhatia | 9227b4d | 2017-07-25 23:14:48 -0400 | [diff] [blame] | 23 | def __xos_save_base(self, *args, **kwds): |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 24 | # set creator on first save |
| 25 | if not self.creator and hasattr(self, 'caller'): |
| 26 | self.creator = self.caller |
| 27 | |
| 28 | # only admins change a slice's creator |
| 29 | if 'creator' in self.changed_fields and \ |
| 30 | (not hasattr(self, 'caller') or not self.caller.is_admin): |
| 31 | |
| 32 | if (self._initial["creator"]==None) and (self.creator==getattr(self,"caller",None)): |
| 33 | # it's okay if the creator is being set by the caller to |
| 34 | # himeself on a new slice object. |
| 35 | pass |
| 36 | else: |
shivani vaidya | 443d463 | 2017-05-08 14:17:38 -0700 | [diff] [blame] | 37 | raise PermissionDenied("Insufficient privileges to change slice creator", |
| 38 | {'creator': "Insufficient privileges to change slice creator"}) |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 39 | |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 40 | if self.network=="Private Only": |
| 41 | # "Private Only" was the default from the old Tenant View |
| 42 | self.network=None |
| 43 | self.enforce_choices(self.network, self.NETWORK_CHOICES) |