3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Nodes import Node, Nodes
7 from PLC.Slices import Slice, Slices
8 from PLC.Auth import Auth
10 class DeleteSliceFromNodes(Method):
12 Deletes the specified slice from the specified nodes. If the slice is
13 not associated with a node, no errors are returned.
15 Returns 1 if successful, faults otherwise.
18 roles = ['admin', 'pi', 'user']
22 Mixed(Slice.fields['slice_id'],
23 Slice.fields['name']),
24 [Mixed(Node.fields['node_id'],
25 Node.fields['hostname'])]
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, slice_id_or_name, node_id_or_hostname_list):
31 # Get slice information
32 slices = Slices(self.api, [slice_id_or_name])
34 raise PLCInvalidArgument, "No such slice"
37 if 'admin' not in self.caller['roles']:
38 if self.caller['person_id'] in slice['person_ids']:
40 elif 'pi' not in self.caller['roles']:
41 raise PLCPermissionDenied, "Not a member of the specified slice"
42 elif slice['site_id'] not in self.caller['site_ids']:
43 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
45 # Remove slice from all nodes found
48 nodes = Nodes(self.api, node_id_or_hostname_list)
50 if slice['peer_id'] is not None and node['peer_id'] is not None:
51 raise PLCPermissionDenied, "Not allowed to remove peer slice from peer node"
52 if slice['slice_id'] in node['slice_ids']:
53 slice.remove_node(node, commit = False)
57 self.event_objects = {'Node': [node['node_id'] for node in nodes],
58 'Slice': [slice['slice_id']]}