blob: c057f2a3e73da807f94fb95114cbe37de21499d7 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
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 Bhatia504cc972017-04-27 01:56:28 +020017NETWORK_CHOICES = ((None, 'Default'), ('host', 'Host'), ('bridged', 'Bridged'), ('noauto', 'No Automatic Networks'))
18
Sapan Bhatia504cc972017-04-27 01:56:28 +020019@property
20def slicename(self):
21 return "%s_%s" % (self.site.login_base, self.name)
22
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040023def __xos_save_base(self, *args, **kwds):
Sapan Bhatia504cc972017-04-27 01:56:28 +020024 # 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 vaidya443d4632017-05-08 14:17:38 -070037 raise PermissionDenied("Insufficient privileges to change slice creator",
38 {'creator': "Insufficient privileges to change slice creator"})
Sapan Bhatia504cc972017-04-27 01:56:28 +020039
Sapan Bhatia504cc972017-04-27 01:56:28 +020040 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)