1 from PLC.Method import Method
2 from PLC.Parameter import Parameter, Mixed
3 from PLC.Faults import *
4 from PLC.Filter import Filter
5 from PLC.Auth import Auth
6 from PLC.Slices import Slice, Slices
7 from PLC.Sites import Site, Sites
8 from PLC.Persons import Person, Persons
9 from PLC.Nodes import Node, Nodes
11 class SliceInfo(Method):
13 Deprecated. Can be implemented with GetSlices.
15 Returns an array of structs containing details about slices.
16 The summary can optionally include the list of nodes in and
19 Users may only query slices of which they are members. PIs may
20 query any of the slices at their sites. Admins may query any
21 slice. If a slice that cannot be queried is specified in
22 slice_filter, details about that slice will not be returned.
27 roles = ['admin', 'pi', 'user']
31 [Mixed(Slice.fields['name'])],
32 Parameter(bool, "Whether or not to return users for the slices", nullok = True),
33 Parameter(bool, "Whether or not to return nodes for the slices", nullok = True)
36 returns = [Slice.fields]
39 def call(self, auth, slice_name_list=None, return_users=None, return_nodes=None):
40 # If we are not admin, make sure to return only viewable
42 slice_filter = slice_name_list
43 slices = Slices(self.api, slice_filter)
45 raise PLCInvalidArgument, "No such slice"
47 if 'admin' not in self.caller['roles']:
48 # Get slices that we are able to view
49 valid_slice_ids = self.caller['slice_ids']
50 if 'pi' in self.caller['roles'] and self.caller['site_ids']:
51 sites = Sites(self.api, self.caller['site_ids'])
53 valid_slice_ids += site['slice_ids']
55 if not valid_slice_ids:
58 slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices)
62 index = slices.index(slice)
63 node_ids = slices[index].pop('node_ids')
64 person_ids = slices[index].pop('person_ids')
65 if return_users or return_users is None:
66 persons = Persons(self.api, person_ids)
67 emails = [person['email'] for person in persons]
68 slices[index]['users'] = emails
69 if return_nodes or return_nodes is None:
70 nodes = Nodes(self.api, node_ids)
71 hostnames = [node['hostname'] for node in nodes]
72 slices[index]['nodes'] = hostnames