X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FSliceInfo.py;h=9f36f65440369e5adb113113a9702c1d232f45cc;hb=268fbc849b46b762926b335e0735d51209e259fb;hp=5be35d6fb746aa1e2c5806930e93031a3f2f0a97;hpb=bc15dc8096f4465bb8c3e9da2177b010828fe5b5;p=plcapi.git diff --git a/PLC/Methods/SliceInfo.py b/PLC/Methods/SliceInfo.py index 5be35d6..9f36f65 100644 --- a/PLC/Methods/SliceInfo.py +++ b/PLC/Methods/SliceInfo.py @@ -1,16 +1,21 @@ +# $Id$ +# $URL$ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed +from PLC.Faults import * from PLC.Filter import Filter from PLC.Auth import Auth from PLC.Slices import Slice, Slices from PLC.Sites import Site, Sites +from PLC.Persons import Person, Persons +from PLC.Nodes import Node, Nodes class SliceInfo(Method): """ Deprecated. Can be implemented with GetSlices. - Returns an array of structs containing details about slices. - The summary can optionally include the list of nodes in and + Returns an array of structs containing details about slices. + The summary can optionally include the list of nodes in and users of each slice. Users may only query slices of which they are members. PIs may @@ -19,24 +24,26 @@ class SliceInfo(Method): slice_filter, details about that slice will not be returned. """ + status = "deprecated" + roles = ['admin', 'pi', 'user'] accepts = [ Auth(), - [Mixed(Slice.fields['name']], - Parameter(bool, "Whether or not to return users for the slices", nullok = True) - Parameter(bool, "Whether or not to return nodes for the slices", nullok = True) + [Mixed(Slice.fields['name'])], + Parameter(bool, "Whether or not to return users for the slices", nullok = True), + Parameter(bool, "Whether or not to return nodes for the slices", nullok = True) ] returns = [Slice.fields] - + def call(self, auth, slice_name_list=None, return_users=None, return_nodes=None): - # If we are not admin, make sure to return only viewable - # slices. - slice_filter = slice_name_list - slices = Slices(self.api, slice_filter) - if not slices: + # If we are not admin, make sure to return only viewable + # slices. + slice_filter = slice_name_list + slices = Slices(self.api, slice_filter) + if not slices: raise PLCInvalidArgument, "No such slice" if 'admin' not in self.caller['roles']: @@ -49,18 +56,22 @@ class SliceInfo(Method): if not valid_slice_ids: return [] - - slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices) - - for slice in slices: - slices.pop(slice) - person_ids = slice.pop('person_ids') - node_ids = slice.pop('node_ids') - if return_users: - slice['users'] = person_ids - if return_nodes: - slice['nodes'] = node_ids - slices.add(slice) - - + + slices = filter(lambda slice: slice['slice_id'] in valid_slice_ids, slices) + + + for slice in slices: + index = slices.index(slice) + node_ids = slices[index].pop('node_ids') + person_ids = slices[index].pop('person_ids') + if return_users or return_users is None: + persons = Persons(self.api, person_ids) + emails = [person['email'] for person in persons] + slices[index]['users'] = emails + if return_nodes or return_nodes is None: + nodes = Nodes(self.api, node_ids) + hostnames = [node['hostname'] for node in nodes] + slices[index]['nodes'] = hostnames + + return slices