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