diff --git a/roboflow/adapters/deploymentapi.py b/roboflow/adapters/deploymentapi.py index 1fef374..555e89e 100644 --- a/roboflow/adapters/deploymentapi.py +++ b/roboflow/adapters/deploymentapi.py @@ -41,6 +41,18 @@ def list_deployment(api_key): return response.status_code, response.json() +def get_workspace_usage(api_key, target_month, return_details): + url = f"{DEDICATED_DEPLOYMENT_URL}/get_usage?api_key={api_key}" + if target_month is not None: + url += f"&target_month={target_month}" + if return_details: + url += f"&return_details={return_details}" + response = requests.get(url) + if response.status_code != 200: + return response.status_code, response.text + return response.status_code, response.json() + + def delete_deployment(api_key, deployment_name): url = f"{DEDICATED_DEPLOYMENT_URL}/delete" response = requests.post(url, json={"api_key": api_key, "deployment_name": deployment_name}) diff --git a/roboflow/deployment.py b/roboflow/deployment.py index 97c77ff..3d505cc 100644 --- a/roboflow/deployment.py +++ b/roboflow/deployment.py @@ -18,6 +18,7 @@ def add_deployment_parser(subparsers): "get", help="show detailed info for a dedicated deployment" ) deployment_list_parser = deployment_subparsers.add_parser("list", help="list dedicated deployments in a workspace") + deployment_usage_parser = deployment_subparsers.add_parser("usage", help="get dedicated deployments usage in a workspace") deployment_delete_parser = deployment_subparsers.add_parser("delete", help="delete a dedicated deployment") deployment_log_parser = deployment_subparsers.add_parser("log", help="show log info for a dedicated deployment") @@ -65,6 +66,11 @@ def add_deployment_parser(subparsers): deployment_list_parser.set_defaults(func=list_deployment) deployment_list_parser.add_argument("-a", "--api_key", help="api key") + + deployment_usage_parser.set_defaults(func=get_workspace_usage) + deployment_usage_parser.add_argument("-a", "--api_key", help="api key") + deployment_usage_parser.add_argument("target_month", help="target month (format: YYYYMM)", nargs='?') + deployment_usage_parser.add_argument("-d", "--details", help="get usage details", action="store_true") deployment_delete_parser.set_defaults(func=delete_deployment) deployment_delete_parser.add_argument("-a", "--api_key", help="api key") @@ -151,6 +157,18 @@ def list_deployment(args): print(json.dumps(msg, indent=2)) +def get_workspace_usage(args): + api_key = args.api_key or load_roboflow_api_key(None) + if api_key is None: + print("Please provide an api key") + exit(1) + status_code, msg = deploymentapi.get_workspace_usage(api_key, args.target_month, args.details) + if status_code != 200: + print(f"{status_code}: {msg}") + exit(status_code) + print(json.dumps(msg, indent=2)) + + def delete_deployment(args): api_key = args.api_key or load_roboflow_api_key(None) if api_key is None: