3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Filter import Filter
6 from PLC.Auth import Auth
7 from PLC.Slices import Slice, Slices
8 from PLC.SliceTags import SliceTag, SliceTags
9 from PLC.Sites import Site, Sites
10 from PLC.Nodes import Node, Nodes
11 from PLC.Persons import Person, Persons
13 class SliceExtendedInfo(Method):
15 Deprecated. Can be implemented with GetSlices.
17 Returns an array of structs containing details about slices.
18 The summary can optionally include the list of nodes in and
21 Users may only query slices of which they are members. PIs may
22 query any of the slices at their sites. Admins may query any
23 slice. If a slice that cannot be queried is specified in
24 slice_filter, details about that slice will not be returned.
29 roles = ['admin', 'pi', 'user']
33 [Slice.fields['name']],
34 Parameter(bool, "Whether or not to return users for the slices", nullok = True),
35 Parameter(bool, "Whether or not to return nodes for the slices", nullok = True)
38 returns = [Slice.fields]
41 def call(self, auth, slice_name_list=None, return_users=None, return_nodes=None, return_attributes=None):
42 # If we are not admin, make sure to return only viewable
44 slice_filter = slice_name_list
45 slices = Slices(self.api, slice_filter)
47 raise PLCInvalidArgument, "No such slice"
49 if 'admin' not in self.caller['roles']:
50 # Get slices that we are able to view
51 valid_slice_ids = self.caller['slice_ids']
52 if 'pi' in self.caller['roles'] and self.caller['site_ids']:
53 sites = Sites(self.api, self.caller['site_ids'])
55 valid_slice_ids += site['slice_ids']
57 if not valid_slice_ids:
60 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 attribute_ids = slices[index].pop('slice_tag_ids')
67 if return_users or return_users is None:
68 persons = Persons(self.api, person_ids)
69 person_info = [{'email': person['email'],
70 'person_id': person['person_id']} \
71 for person in persons]
72 slices[index]['users'] = person_info
73 if return_nodes or return_nodes is None:
74 nodes = Nodes(self.api, node_ids)
75 node_info = [{'hostname': node['hostname'],
76 'node_id': node['node_id']} \
78 slices[index]['nodes'] = node_info
79 if return_attributes or return_attributes is None:
80 attributes = SliceTags(self.api, attribute_ids)
81 attribute_info = [{'name': attribute['name'],
82 'value': attribute['value']} \
83 for attribute in attributes]
84 slices[index]['attributes'] = attribute_info