1
+ import urllib
2
+
1
3
import requests
2
4
3
5
from roboflow .config import DEDICATED_DEPLOYMENT_URL
@@ -42,15 +44,25 @@ def list_deployment(api_key):
42
44
43
45
44
46
def get_workspace_usage (api_key , from_timestamp , to_timestamp ):
45
- url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_workspace?api_key={ api_key } &from_timestamp={ from_timestamp .isoformat ()} &to_timestamp={ to_timestamp .isoformat ()} "
47
+ params = {"api_key" : api_key }
48
+ if from_timestamp is not None :
49
+ params ["from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
50
+ if to_timestamp is not None :
51
+ params ["to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
52
+ url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_workspace?{ urllib .parse .urlencode (params )} "
46
53
response = requests .get (url )
47
54
if response .status_code != 200 :
48
55
return response .status_code , response .text
49
56
return response .status_code , response .json ()
50
57
51
58
52
59
def get_deployment_usage (api_key , deployment_name , from_timestamp , to_timestamp ):
53
- url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_deployment?api_key={ api_key } &deployment_name={ deployment_name } &from_timestamp={ from_timestamp .isoformat ()} &to_timestamp={ to_timestamp .isoformat ()} "
60
+ params = {"api_key" : api_key , "deployment_name" : deployment_name }
61
+ if from_timestamp is not None :
62
+ params ["from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
63
+ if to_timestamp is not None :
64
+ params ["to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
65
+ url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_deployment?{ urllib .parse .urlencode (params )} "
54
66
response = requests .get (url )
55
67
if response .status_code != 200 :
56
68
return response .status_code , response .text
@@ -74,13 +86,14 @@ def list_machine_types(api_key):
74
86
75
87
76
88
def get_deployment_log (api_key , deployment_name , from_timestamp = None , to_timestamp = None , max_entries = - 1 ):
77
- url = f" { DEDICATED_DEPLOYMENT_URL } /get_log? api_key= { api_key } & deployment_name= { deployment_name } "
89
+ params = { " api_key" : api_key , " deployment_name" : deployment_name }
78
90
if from_timestamp is not None :
79
- url += f"& from_timestamp= { from_timestamp .isoformat ()} "
91
+ params [ "from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
80
92
if to_timestamp is not None :
81
- url += f"& to_timestamp= { to_timestamp .isoformat ()} "
93
+ params [ "to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
82
94
if max_entries > 0 :
83
- url += f"&max_entries={ max_entries } "
95
+ params ["max_entries" ] = max_entries
96
+ url = f"{ DEDICATED_DEPLOYMENT_URL } /get_log?{ urllib .parse .urlencode (params )} "
84
97
response = requests .get (url )
85
98
if response .status_code != 200 :
86
99
return response .status_code , response .text
0 commit comments