1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Nodes import Node, Nodes
5 from PLC.Slices import Slice, Slices
6 from PLC.Auth import PasswordAuth
8 class DeleteSliceFromNodes(Method):
10 Deletes the specified slice from the specified nodes. If the slice is
11 not associated with a node, no errors are returned.
13 Returns 1 if successful, faults otherwise.
16 roles = ['admin', 'pi', 'user']
20 Mixed(Slice.fields['slice_id'],
21 Slice.fields['name']),
22 [Mixed(Node.fields['node_id'],
23 Node.fields['hostname'])]
26 returns = Parameter(int, '1 if successful')
28 def call(self, auth, slice_id_or_name, node_id_or_hostname_list):
29 # Get slice information
30 slices = Slices(self.api, [slice_id_or_name])
32 raise PLCInvalidArgument, "No such slice"
34 slice = slices.values()[0]
37 nodes = Nodes(self.api, node_id_or_hostname_list).values()
39 if 'admin' not in self.caller['roles']:
40 if self.caller['person_id'] in slice['person_ids']:
42 elif 'pi' not in self.caller['roles']:
43 raise PLCPermissionDenied, "Not a member of the specified slice"
44 elif slice['site_id'] not in self.caller['site_ids']:
45 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
47 # Remove slice from all nodes found
49 if slice['slice_id'] in node['slice_ids']:
50 slice.remove_node(node)