mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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 <chip.childers@gmail.com>
This commit is contained in:
parent
79e5a3a3ab
commit
2ee9253c78
@ -31,12 +31,17 @@ from cloudstackAPI import *
|
|||||||
import jsonHelper
|
import jsonHelper
|
||||||
|
|
||||||
class cloudConnection(object):
|
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.apiKey = apiKey
|
||||||
self.securityKey = securityKey
|
self.securityKey = securityKey
|
||||||
self.mgtSvr = mgtSvr
|
self.mgtSvr = mgtSvr
|
||||||
self.port = port
|
self.port = port
|
||||||
self.logging = logging
|
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:
|
if port == 8096:
|
||||||
self.auth = False
|
self.auth = False
|
||||||
else:
|
else:
|
||||||
@ -52,7 +57,7 @@ class cloudConnection(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def __copy__(self):
|
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={}):
|
def make_request_with_auth(self, command, requests={}):
|
||||||
requests["command"] = command
|
requests["command"] = command
|
||||||
@ -68,7 +73,7 @@ class cloudConnection(object):
|
|||||||
requestUrl += "&signature=%s"%sig
|
requestUrl += "&signature=%s"%sig
|
||||||
|
|
||||||
try:
|
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:
|
if self.logging is not None:
|
||||||
self.logging.debug("sending GET request: %s"%requestUrl)
|
self.logging.debug("sending GET request: %s"%requestUrl)
|
||||||
response = self.connection.read()
|
response = self.connection.read()
|
||||||
@ -100,7 +105,7 @@ class cloudConnection(object):
|
|||||||
requests = zip(requests.keys(), requests.values())
|
requests = zip(requests.keys(), requests.values())
|
||||||
requestUrl = "&".join(["=".join([request[0], urllib.quote_plus(str(request[1]))]) for request in requests])
|
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:
|
if self.logging is not None:
|
||||||
self.logging.debug("sending GET request without auth: %s"%requestUrl)
|
self.logging.debug("sending GET request without auth: %s"%requestUrl)
|
||||||
response = self.connection.read()
|
response = self.connection.read()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user