def __init__(self, api, path): self.nodes = [] node_ids = api.get(path) ### If IDs list if isinstance(node_ids, list): for n_id in node_ids: n = Node(api.get(url.join(path, n_id))) if Node is not None: self.nodes.append(n) ### If immediate entity elif isinstance(node_ids, dict): self.nodes.append(Node(node_ids)) ### Automatic sorting self.sort()
def visit(path, recursive=None, level=0): response = api.get(path) print_alinea(path, level) if isinstance(response, dict): if 'message' in response.keys(): if 'This service does not exist' in response.values(): logging.warn('Skipped: ' + path + ' (not implemented by OVH)') return elif 'does not answer to the GET HTTP method' in response['message']: logging.warn('Skipped: ' + response['message']) #(Cannot be browsed: OVH REST map unconsistent) return ### Node has direct children elif 'apis' in response.keys(): for k in response['apis']: subpath = url.join(path, k['path']) if recursive: visit(subpath, recursive, level+1) ### Node is an entity else: n = Node(response) logging.info(n) ### Path is a list of IDs elif isinstance(response, list): if not response: pass logging.info('Skipped: ' + path + ' (empty list of IDs)') else: for id in response: entity_path = url.join(path, id) if recursive: visit(entity_path, recursive, level+1) else: print_alinea(path, level)