X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=PLC%2FMethods%2FGetAddresses.py;h=7ebc80ba77f6d6bf1756c6463e4df716c7c106ae;hb=91e6eb8f4cb875e6967fb51135b90ba2dc184cc6;hp=a558f540abe7a73dd52a0ff5c72ae9782a9a1ee4;hpb=90c27a56ff08439137ce31a99f1fe0888d3b238e;p=plcapi.git diff --git a/PLC/Methods/GetAddresses.py b/PLC/Methods/GetAddresses.py index a558f54..7ebc80b 100644 --- a/PLC/Methods/GetAddresses.py +++ b/PLC/Methods/GetAddresses.py @@ -1,44 +1,32 @@ +# $Id$ +# $URL$ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter from PLC.Addresses import Address, Addresses -from PLC.Sites import Site, Sites -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth class GetAddresses(Method): """ - Get an array of structs containing the addresses of the specified - site. If address_id_list is specified, only the specified - addresses will be queried. + Returns an array of structs containing details about addresses. If + address_filter is specified and is an array of address + identifiers, or a struct of address attributes, only addresses + matching the filter will be returned. If return_fields is + specified, only the specified details will be returned. """ - roles = ['admin', 'pi', 'user', 'tech'] + roles = ['admin', 'pi', 'user', 'tech', 'node'] accepts = [ - PasswordAuth(), - Mixed(Site.fields['site_id'], - Site.fields['login_base']), - [Address.fields['address_id']], + Auth(), + Mixed([Address.fields['address_id']], + Filter(Address.fields)), + Parameter([str], "List of fields to return", nullok = True) ] returns = [Address.fields] - def call(self, auth, site_id_or_login_base, address_id_list = None): - sites = Sites(self.api, [site_id_or_login_base]).values() - if not sites: - raise PLCInvalidArgument, "No such site" - site = sites[0] - if address_id_list is None: - address_id_list = site['address_ids'] - else: - if set(address_id_list).intersection(site['address_ids']) != \ - set(address_id_list): - raise PLCInvalidArgument, "Invalid address ID(s)" - - addresses = Addresses(self.api, address_id_list).values() - - # Turn each address into a real dict - addresses = [dict(address.items) for address in addresses] - - return addresses + def call(self, auth, address_filter = None, return_fields = None): + return Addresses(self.api, address_filter, return_fields)