From 2ee9253c78152d517f8448f66a779c6e3777b19c Mon Sep 17 00:00:00 2001 From: Chip Childers Date: Mon, 19 Nov 2012 12:06:18 -0500 Subject: [PATCH] CLOUDSTACK-514: Adding https and api path support to Marvin. This is the first part of fixing CLOUDSTACK-514, and is hopefully backward compatible with previous use of Marvin. I added two new parameters to the cloudstackConnection module, protocol and path. Both have been defaulted to the previously *assumed* values. Signed-off-by: Chip Childers --- tools/marvin/marvin/cloudstackConnection.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index bd8a5b2ea2c..c8052130fe6 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -31,12 +31,17 @@ from cloudstackAPI import * import jsonHelper class cloudConnection(object): - def __init__(self, mgtSvr, port=8096, apiKey = None, securityKey = None, asyncTimeout=3600, logging=None): + def __init__(self, mgtSvr, port=8096, apiKey = None, securityKey = None, asyncTimeout=3600, logging=None, protocol='http', path='/client/api'): self.apiKey = apiKey self.securityKey = securityKey self.mgtSvr = mgtSvr self.port = port self.logging = logging + if protocol != 'http' and protocol != 'https': + raise ValueError("Protocol must be 'http' or 'https'.") + else: + self.protocol=protocol + self.path = path if port == 8096: self.auth = False else: @@ -52,7 +57,7 @@ class cloudConnection(object): pass def __copy__(self): - return cloudConnection(self.mgtSvr, self.port, self.apiKey, self.securityKey, self.asyncTimeout, self.logging) + return cloudConnection(self.mgtSvr, self.port, self.apiKey, self.securityKey, self.asyncTimeout, self.logging, self.protocol, self.path) def make_request_with_auth(self, command, requests={}): requests["command"] = command @@ -68,7 +73,7 @@ class cloudConnection(object): requestUrl += "&signature=%s"%sig try: - self.connection = urllib2.urlopen("http://%s:%d/client/api?%s"%(self.mgtSvr, self.port, requestUrl)) + self.connection = urllib2.urlopen("%s://%s:%d%s?%s"%(self.protocol, self.mgtSvr, self.port, self.path, requestUrl)) if self.logging is not None: self.logging.debug("sending GET request: %s"%requestUrl) response = self.connection.read() @@ -100,7 +105,7 @@ class cloudConnection(object): requests = zip(requests.keys(), requests.values()) requestUrl = "&".join(["=".join([request[0], urllib.quote_plus(str(request[1]))]) for request in requests]) - self.connection = urllib2.urlopen("http://%s:%d/client/api?%s"%(self.mgtSvr, self.port, requestUrl)) + self.connection = urllib2.urlopen("%s://%s:%d%s?%s"%(self.protocol, self.mgtSvr, self.port, self.path, requestUrl)) if self.logging is not None: self.logging.debug("sending GET request without auth: %s"%requestUrl) response = self.connection.read()