Skip to content

Commit cc61452

Browse files
authoredJul 27, 2022
Add support to connect smart-1 cloud (#47)
·
v1.9.0v1.5.0
1 parent c5f21f4 commit cc61452

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed
 

‎cpapi/mgmt_api.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class APIClientArgs:
4242
def __init__(self, port=None, fingerprint=None, sid=None, server="127.0.0.1", http_debug_level=0,
4343
api_calls=None, debug_file="", proxy_host=None, proxy_port=8080,
4444
api_version=None, unsafe=False, unsafe_auto_accept=False, context="web_api", single_conn=True,
45-
user_agent="python-api-wrapper", sync_frequency=2):
45+
user_agent="python-api-wrapper", sync_frequency=2, cloud_mgmt_id=""):
4646
self.port = port
4747
# management server fingerprint
4848
self.fingerprint = fingerprint
@@ -74,6 +74,8 @@ def __init__(self, port=None, fingerprint=None, sid=None, server="127.0.0.1", ht
7474
self.user_agent = user_agent
7575
# Interval size in seconds of the task update
7676
self.sync_frequency = sync_frequency
77+
# Smart-1 Cloud management UID
78+
self.cloud_mgmt_id = cloud_mgmt_id
7779

7880

7981
class APIClient:
@@ -124,6 +126,8 @@ def __init__(self, api_client_args=None):
124126
self.user_agent = api_client_args.user_agent
125127
# Interval size in seconds of the task update
126128
self.sync_frequency = api_client_args.sync_frequency
129+
# Smart-1 Cloud management UID
130+
self.cloud_mgmt_id = api_client_args.cloud_mgmt_id
127131

128132
def __enter__(self):
129133
return self
@@ -318,7 +322,18 @@ def api_call(self, command, payload=None, sid=None, wait_for_task=True, timeout=
318322

319323
# init https connection. if single connection is True, use last connection
320324
conn = self.get_https_connection()
321-
url = "/" + self.context + "/" + (("v" + str(self.api_version) + "/") if self.api_version else "") + command
325+
326+
url = ""
327+
if self.cloud_mgmt_id != "":
328+
url += "/" + self.cloud_mgmt_id
329+
330+
url += "/" + self.context
331+
332+
if self.api_version:
333+
url += "/v" + str(self.api_version)
334+
335+
url += "/" + command
336+
322337
response = None
323338
try:
324339
# Send the data to the server

0 commit comments

Comments
 (0)
Please sign in to comment.