Skip to content

Commit 95f931d

Browse files
authored
Merge pull request #87 from vineyyadav/master
Added support for providing host_uri argument when creating a Nebula object
2 parents 1775127 + 908770a commit 95f931d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

NebulaPythonSDK/sdk.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ class Nebula:
1212
# the nebula class init module serves as the login against the nebula API as it's the only shared thing among the
1313
# class functions
1414
def __init__(self, username=None, password=None, token=None, host="127.0.0.1", port=80, protocol="http",
15-
request_timeout=60):
15+
host_uri=None, request_timeout=60):
1616
self.request_timeout = request_timeout
1717
self.username = username
1818
self.password = password
1919
self.token = token
2020
self.protocol = protocol
2121
self.port = port
22-
self.host = protocol + "://" + host + ":" + str(port)
22+
if host_uri:
23+
self.host = host_uri
24+
else:
25+
self.host = protocol + "://" + host + ":" + str(port)
2326
self.headers = {
2427
'content-type': "application/json",
2528
'cache-control': "no-cache"

test/test_nebula_python_sdk.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,18 @@ def test_cron_job_flow(self, cron_job="unit_test_cron_job"):
454454
reply = nebula_connection_object.delete_cron_job(cron_job)
455455
self.assertEqual(reply["status_code"], 200)
456456
self.assertEqual(reply["reply"], {})
457+
458+
def test_nebula_connection_with_host_uri(self):
459+
nebula_user = os.getenv("NEBULA_TEST_USERNAME", "nebula")
460+
nebula_password = os.getenv("NEBULA_TEST_PASSWORD", "nebula")
461+
nebula_host_uri = os.getenv("NEBULA_HOST_URI", "http://127.0.0.1:80")
462+
connection = Nebula(username=nebula_user, password=nebula_password, host_uri=nebula_host_uri)
463+
464+
# check that the host param is set correctly
465+
self.assertEqual(connection.host, nebula_host_uri)
466+
467+
# check that connects to manager successfully
468+
reply = connection.check_api()
469+
self.assertEqual(reply["status_code"], 200)
470+
self.assertEqual(reply["reply"]["api_available"], True)
471+

0 commit comments

Comments
 (0)