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.ForeignNodes import ForeignNode, ForeignNodes
6 from PLC.Slices import Slice, Slices
7 from PLC.Auth import Auth
9 class DeleteSliceFromNodes(Method):
11 Deletes the specified slice from the specified nodes. If the slice is
12 not associated with a node, no errors are returned.
14 Returns 1 if successful, faults otherwise.
17 roles = ['admin', 'pi', 'user']
21 Mixed(Slice.fields['slice_id'],
22 Slice.fields['name']),
23 [Mixed(Node.fields['node_id'],
24 Node.fields['hostname'])]
27 returns = Parameter(int, '1 if successful')
29 event_type = 'DeleteFrom'
32 def call(self, auth, slice_id_or_name, node_id_or_hostname_list):
33 # Get slice information
34 slices = Slices(self.api, [slice_id_or_name])
36 raise PLCInvalidArgument, "No such slice"
40 if 'admin' not in self.caller['roles']:
41 if self.caller['person_id'] in slice['person_ids']:
43 elif 'pi' not in self.caller['roles']:
44 raise PLCPermissionDenied, "Not a member of the specified slice"
45 elif slice['site_id'] not in self.caller['site_ids']:
46 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
48 # Remove slice from all nodes found
51 nodes = Nodes(self.api, node_id_or_hostname_list)
52 foreign_nodes = ForeignNodes(self.api, node_id_or_hostname_list)
53 all_nodes = nodes+foreign_nodes;
54 for node in all_nodes:
55 if slice['slice_id'] in node['slice_ids']:
56 slice.remove_node(node, commit = False)
60 self.object_ids = [node['node_id'] for node in all_nodes]