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()