1 from PLC.Method import Method
2 from PLC.Parameter import Parameter, Mixed
3 from PLC.Filter import Filter
4 from PLC.Auth import Auth
5 from PLC.Slices import Slice, Slices
6 from PLC.SliceTags import SliceTag, SliceTags
7 from PLC.Sites import Site, Sites
8 from PLC.Nodes import Node, Nodes
9 from PLC.Persons import Person, Persons
11 class SliceExtendedInfo(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 [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, return_attributes=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)
61 index = slices.index(slice)
62 node_ids = slices[index].pop('node_ids')
63 person_ids = slices[index].pop('person_ids')
64 attribute_ids = slices[index].pop('slice_tag_ids')
65 if return_users or return_users is None:
66 persons = Persons(self.api, person_ids)
67 person_info = [{'email': person['email'],
68 'person_id': person['person_id']} \
69 for person in persons]
70 slices[index]['users'] = person_info
71 if return_nodes or return_nodes is None:
72 nodes = Nodes(self.api, node_ids)
73 node_info = [{'hostname': node['hostname'],
74 'node_id': node['node_id']} \
76 slices[index]['nodes'] = node_info
77 if return_attributes or return_attributes is None:
78 attributes = SliceTags(self.api, attribute_ids)
79 attribute_info = [{'name': attribute['name'],
80 'value': attribute['value']} \
81 for attribute in attributes]
82 slices[index]['attributes'] = attribute_info