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']
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):
30 # Get slice information
31 slices = Slices(self.api, [slice_id_or_name])
33 raise PLCInvalidArgument, "No such slice"
35 slice = slices.values()[0]
38 nodes = Nodes(self.api, node_id_or_hostname_list).values()
40 # If we are not admin, make sure the caller is a pi
41 # of the site associated with the slice
42 if 'admin' not in self.caller['roles']:
43 if slice['site_id'] not in self.caller['site_ids']:
44 raise PLCPermissionDenied, "Not allowed to delete nodes from this slice"
46 # add slice to all nodes found
48 if slice['slice_id'] in node['slice_ids']:
49 slice.remove_node(node)