Skip to content

Commit

Permalink
add usage api for dedicated deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificDou committed Nov 4, 2024
1 parent 0d6b37d commit 42e70d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions roboflow/adapters/deploymentapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
18 changes: 18 additions & 0 deletions roboflow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 42e70d7

Please sign in to comment.