Updated Branches: refs/heads/trunk 91ead9e80 -> 935224014
AMBARI-3257. Ambari-Client https support. (Andrew Onischuk via mahadev) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/93522401 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/93522401 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/93522401 Branch: refs/heads/trunk Commit: 935224014dd04375b83278f4fee923c925c41b2f Parents: 91ead9e Author: Mahadev Konar <[email protected]> Authored: Wed Sep 18 13:06:16 2013 -0700 Committer: Mahadev Konar <[email protected]> Committed: Wed Sep 18 13:06:16 2013 -0700 ---------------------------------------------------------------------- .../src/main/python/ambari_client/ambari_api.py | 17 +++++++++++++---- .../main/python/ambari_client/core/http_client.py | 2 ++ ambari-client/src/test/python/TestAmbariClient.py | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/93522401/ambari-client/src/main/python/ambari_client/ambari_api.py ---------------------------------------------------------------------- diff --git a/ambari-client/src/main/python/ambari_client/ambari_api.py b/ambari-client/src/main/python/ambari_client/ambari_api.py index 53b608f..9f8e109 100755 --- a/ambari-client/src/main/python/ambari_client/ambari_api.py +++ b/ambari-client/src/main/python/ambari_client/ambari_api.py @@ -35,7 +35,7 @@ class AmbariClient(RestResource): AmbariClient top-level root resources. """ - def __init__(self, host_name, port=None, user_name="admin", password="admin", + def __init__(self, host_name, port=None, user_name="admin", password="admin", use_https = False, version=API_VERSION , client=None): """ Creates a RestResource object. @@ -49,9 +49,18 @@ class AmbariClient(RestResource): """ self._version = version - protocol = "http" - if port is None: - port = 8080 + + if use_https: + protocol = "https" + if port is None: + port = 8443 + else: + protocol = "http" + if port is None: + port = 8080 + + + host_url = "%s://%s:%s/api/v%s" % (protocol, host_name, port, version) if client is None: client = HttpClient(host_url, user_name , password) http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/93522401/ambari-client/src/main/python/ambari_client/core/http_client.py ---------------------------------------------------------------------- diff --git a/ambari-client/src/main/python/ambari_client/core/http_client.py b/ambari-client/src/main/python/ambari_client/core/http_client.py index 5b49be3..f2d82f3 100755 --- a/ambari-client/src/main/python/ambari_client/core/http_client.py +++ b/ambari-client/src/main/python/ambari_client/core/http_client.py @@ -95,6 +95,8 @@ class HttpClient(object): buf = cStringIO.StringIO() self.c.setopt(pycurl.WRITEFUNCTION, buf.write) + self.c.setopt(pycurl.SSL_VERIFYPEER, 0) + LOG.debug ("invoke : url = "+str(url)) # set http_method if http_method == "GET": http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/93522401/ambari-client/src/test/python/TestAmbariClient.py ---------------------------------------------------------------------- diff --git a/ambari-client/src/test/python/TestAmbariClient.py b/ambari-client/src/test/python/TestAmbariClient.py index 6830b6d..a18aa0d 100755 --- a/ambari-client/src/test/python/TestAmbariClient.py +++ b/ambari-client/src/test/python/TestAmbariClient.py @@ -48,6 +48,12 @@ class TestAmbariClient(unittest.TestCase): self.assertEqual(client.host_url, "http://localhost:8080/api/v1", "host_url should be http://localhost:8080/api/v1") + + client = AmbariClient("localhost", 8443, "admin", "admin", use_https=True) + self.assertEqual(client.version, 1, "version should be 1") + self.assertEqual(client.host_url, "https://localhost:8443/api/v1", + "host_url should be https://localhost:8443/api/v1") + @patch("ambari_client.core.http_client.HttpClient")
