Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
#
# Examples:
#
# (1) Initialize, authenticate:
# (1a) Initialize, authenticate:
# ```
# client = VcoRequestManager("vcoXX-usvi1.velocloud.net")
# client.authenticate(os.environ["VC_USERNAME"], os.environ["VC_PASSWORD"], is_operator=True)
# ```

# (1b) Initialize, set API token:
# ```
# client = VcoRequestManager("vcoXX-usvi1.velocloud.net")
# client.set_token("TOKENABCXYZ")
# ```

# (2) Get Edges
# ```
# client.call_api("enterprise/getEnterpriseEdges", { "enterpriseId": 1 })
Expand All @@ -42,6 +48,7 @@ def __init__(self, hostname, verify_ssl=True):
self._portal_url = self._root_url + "/portal/"
self._livepull_url = self._root_url + "/livepull/liveData/"
self._seqno = 0
self._token = None

def _get_root_url(self, hostname):
"""
Expand All @@ -52,6 +59,14 @@ def _get_root_url(self, hostname):
proto = "https://"
return proto + hostname

def set_token(self, token):
"""
Set token to allow for token auth via API
:param token: Token string
:return: None
"""
self._token = "Token " + token

def authenticate(self, username, password, is_operator=True):
"""
Authenticate to API - on success, a cookie is stored in the session
Expand All @@ -70,6 +85,8 @@ def call_api(self, method, params):
"""
self._seqno += 1
headers = { "Content-Type": "application/json" }
if self._token:
headers["Authorization"] = self._token
method = self._clean_method_name(method)
payload = { "jsonrpc": "2.0",
"id": self._seqno,
Expand Down