2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Nodes import Node, Nodes
6 from PLC.Slices import Slice, Slices
7 from PLC.Auth import Auth
9 class AddSliceToNodesWhitelist(Method):
11 Adds the specified slice to the whitelist on the specified nodes. Nodes may be
12 either local or foreign nodes.
14 If the slice is already associated with a node, no errors are
17 Returns 1 if successful, faults otherwise.
24 Mixed(Slice.fields['slice_id'],
25 Slice.fields['name']),
26 [Mixed(Node.fields['node_id'],
27 Node.fields['hostname'])]
30 returns = Parameter(int, '1 if successful')
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"
39 if slice['peer_id'] is not None:
40 raise PLCInvalidArgument, "Not a local slice"
42 # Get specified nodes, add them to the slice
43 nodes = Nodes(self.api, node_id_or_hostname_list)
45 if node['peer_id'] is not None:
46 raise PLCInvalidArgument, "%s not a local node" % node['hostname']
47 if slice['slice_id'] not in node['slice_ids_whitelist']:
48 slice.add_to_node_whitelist(node, commit = False)
52 self.event_objects = {'Node': [node['node_id'] for node in nodes],
53 'Slice': [slice['slice_id']]}