def describe_datasets(dataset_id): try: url = "{}/datasets".format(ORGANIZATION_ENDPOINT) if dataset_id == 'all' \ else "{}/datasets/{}".format(ORGANIZATION_ENDPOINT, dataset_id) r = api_get(url) except Exception as e: logger.error('describe-dataset failed: {}'.format(e)) click.echo('describe-dataset failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(r))
def _get_all_dataset_items(base_url, q): next_page_token = None items = [] while True: if q is not None and next_page_token is None: url = "{}?q={}".format(base_url, q) elif next_page_token: url = "{}?next_page_token={}".format(base_url, next_page_token) else: url = base_url r = api_get(url) items += r['items'] if r['next_page_token'] is None: return {"items": items, "total_count": r['total_count']} next_page_token = r['next_page_token']
def get_organization_id() -> Optional[str]: try: r = api_get(ORGANIZATION_ENDPOINT) return r.get('id') except requests.exceptions.HTTPError as e: if 400 <= e.response.status_code < 500: # better to let users to know something wrong with api. click.secho('[error] something wrong with credential setting.', err=True, fg='red') else: # better to let users to know something wrong with api. click.secho('[error] something wrong with API, please try later.', err=True, fg='red') return None
def describe_dataset_items(dataset_id, dataset_item_id, q): if dataset_item_id and q: click.echo( 'describe-dataset-items failed: q cannot be specified when dataset-item-id is specified' ) sys.exit(ERROR_EXITCODE) try: if dataset_item_id is None: url = "{}/datasets/{}/items".format(ORGANIZATION_ENDPOINT, dataset_id) res = _get_all_dataset_items(url, q) else: url = "{}/datasets/{}/items/{}".format(ORGANIZATION_ENDPOINT, dataset_id, dataset_item_id) res = api_get(url) except Exception as e: logger.error('describe-dataset-items failed: {}'.format(e)) click.echo('describe-dataset-items failed.') sys.exit(ERROR_EXITCODE) click.echo(json_output_formatter(res))
def _describe_repository(repository_id): url = "{}/registry/repositories/{}".format(ORGANIZATION_ENDPOINT, repository_id) r = api_get(url) return r
def describe_training_version(name: str, version: int): return api_get("{}/training/definitions/{}/versions/{}".format( ORGANIZATION_ENDPOINT, name, version))