@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='authority to list (hrn/urn - mandatory)')
@args('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
- def list(self, xrn, type=None):
+ @args('-r', '--recursive', dest='recursive', metavar='<recursive>', help='list all child records',
+ action='store_true', default=False)
+ def list(self, xrn, type=None, recursive=False):
"""List names registered at a given authority - possibly filtered by type"""
xrn = Xrn(xrn, type)
- records = self.api.manager.List(self.api, xrn.get_hrn())
+ options = {'recursive': recursive}
+ records = self.api.manager.List(self.api, xrn.get_hrn(), options=options)
for record in records:
if not type or record['type'] == type:
print "%s (%s)" % (record['hrn'], record['type'])
parser.add_option("-F", "--fileformat", dest="fileformat", type="choice",
help="output file format ([xml]|xmllist|hrnlist)", default="xml",
choices=("xml", "xmllist", "hrnlist"))
-
+ if command == 'list':
+ parser.add_option("-r", "--recursive", dest="recursive", action='store_true',
+ help="list all child records", default=False)
if command in ("delegate"):
parser.add_option("-u", "--user",
action="store_true", dest="delegate_user", default=False,
self.print_help()
sys.exit(1)
hrn = args[0]
+ opts = {}
+ if options.recursive:
+ opts['recursive'] = options.recursive
+
try:
- list = self.registry().List(hrn, self.my_credential_string)
+ list = self.registry().List(hrn, self.my_credential_string, options)
except IndexError:
raise Exception, "Not enough parameters for the 'list' command"
return records
- def List (self, api, xrn, origin_hrn=None):
- hrn, type = urn_to_hrn(xrn)
- recursive = False
- if hrn.endswith('*'):
- hrn = hrn[:-1]
- recursive = True
+ def List (self, api, xrn, origin_hrn=None, options={}):
# load all know registry names into a prefix tree and attempt to find
# the longest matching prefix
+ hrn, type = urn_to_hrn(xrn)
registries = api.registries
registry_hrns = registries.keys()
tree = prefixTree()
credential = api.getCredential()
interface = api.registries[registry_hrn]
server_proxy = api.server_proxy(interface, credential)
- record_list = server_proxy.List(xrn, credential)
+ record_list = server_proxy.List(xrn, credential, options)
# same as above, no need to process what comes from through xmlrpc
# pass foreign records as-is
record_dicts = record_list
# if we still have not found the record yet, try the local registry
if not record_dicts:
+ recursive = False
+ if ('recursive' in options and options['recursive']):
+ recursive = True
+ elif hrn.endswith('*'):
+ hrn = hrn[:-1]
+ recursive = True
+
if not api.auth.hierarchy.auth_exists(hrn):
raise MissingAuthority(hrn)
if recursive:
# xxx used to be [SfaRecord]
returns = [Parameter(dict, "registry record")]
- def call(self, xrn, creds):
+ def call(self, xrn, creds, options={}):
hrn, type = urn_to_hrn(xrn)
valid_creds = self.api.auth.checkCredentials(creds, 'list')
origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
- return self.api.manager.List(self.api, xrn)
+ return self.api.manager.List(self.api, xrn, options=options)