mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
marvin: a1b979da8 breaks formatting and pep8.
setup/dev/advanced.cfg is used by the simulator deployments that are usually not https. disabled the http within this config file. Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
parent
a1b979da86
commit
dfa0678fc6
@ -220,9 +220,9 @@
|
||||
"user": "root",
|
||||
"port": 8096,
|
||||
"hypervisor": "simulator",
|
||||
"useHttps": "True",
|
||||
"certCAPath": "NA",
|
||||
"certPath": "NA"
|
||||
"useHttps": "False",
|
||||
"certCAPath": "NA",
|
||||
"certPath": "NA"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -35,7 +35,8 @@ class cloudConnection(object):
|
||||
|
||||
""" Connections to make API calls to the cloudstack management server
|
||||
"""
|
||||
def __init__(self, mgmtDet,asyncTimeout=3600, logging=None, scheme='http',path='client/api'):
|
||||
def __init__(self, mgmtDet, asyncTimeout=3600, logging=None,
|
||||
scheme='http', path='client/api'):
|
||||
self.loglevel() # Turn off requests logs
|
||||
self.apiKey = mgmtDet.apiKey
|
||||
self.securityKey = mgmtDet.securityKey
|
||||
@ -43,19 +44,19 @@ class cloudConnection(object):
|
||||
self.port = mgmtDet.port
|
||||
self.user = mgmtDet.user
|
||||
self.passwd = mgmtDet.passwd
|
||||
self.certCAPath = mgmtDet.certCAPath
|
||||
self.certPath = mgmtDet.certPath
|
||||
self.certCAPath = mgmtDet.certCAPath
|
||||
self.certPath = mgmtDet.certPath
|
||||
self.logging = logging
|
||||
self.path = path
|
||||
self.retries = 5
|
||||
self.protocol = "http"
|
||||
self.protocol = scheme
|
||||
self.asyncTimeout = asyncTimeout
|
||||
self.auth = True
|
||||
if self.port == 8096 or \
|
||||
(self.apiKey is None and self.securityKey is None):
|
||||
self.auth = False
|
||||
if mgmtDet.useHttps == "True":
|
||||
self.protocol = "https"
|
||||
self.protocol = "https"
|
||||
self.baseurl = "%s://%s:%d/%s"\
|
||||
% (self.protocol, self.mgtSvr, self.port, self.path)
|
||||
|
||||
@ -143,52 +144,53 @@ class cloudConnection(object):
|
||||
payload["signature"] = signature
|
||||
|
||||
try:
|
||||
'''
|
||||
https_flag : Signifies whether to verify connection over http or https, if set to true uses https otherwise http
|
||||
cert_path : Signifies ca and cert path required by requests library for the connection
|
||||
'''
|
||||
https_flag = False
|
||||
cert_path = ()
|
||||
if self.protocol == "https":
|
||||
https_flag = True
|
||||
if self.certCAPath != "NA" and self.certPath != "NA":
|
||||
cert_path = ( self.certCAPath,self.certPath )
|
||||
|
||||
'''
|
||||
Verify whether protocol is "http", then call the request over http
|
||||
'''
|
||||
if self.protocol == "http":
|
||||
if method == 'POST':
|
||||
response = requests.post(self.baseurl, params=payload, verify=https_flag)
|
||||
else:
|
||||
response = requests.get(self.baseurl, params=payload, verify=https_flag)
|
||||
#https_flag : whether https enabled or not
|
||||
#cert_path : ca and cert paths of the https connection
|
||||
https_flag = False
|
||||
cert_path = ()
|
||||
if self.protocol == "https":
|
||||
https_flag = True
|
||||
if self.certCAPath != "NA" and self.certPath != "NA":
|
||||
cert_path = (self.certCAPath, self.certPath)
|
||||
#Verify whether protocol is "http", then call the request over http
|
||||
if self.protocol == "http":
|
||||
if method == 'POST':
|
||||
response = requests.post(self.baseurl, params=payload,
|
||||
verify=https_flag)
|
||||
else:
|
||||
response = requests.get(self.baseurl, params=payload,
|
||||
verify=https_flag)
|
||||
else:
|
||||
exception_check = False
|
||||
exception_info = None
|
||||
'''
|
||||
If protocol is https, then request the url with user provided certificates provided as part of cert
|
||||
'''
|
||||
try:
|
||||
if method == 'POST':
|
||||
response = requests.post(self.baseurl, params=payload, cert=cert_path, verify=https_flag)
|
||||
else:
|
||||
response = requests.get(self.baseurl, params=payload, cert=cert_path, verify=https_flag)
|
||||
except Exception,e:
|
||||
'''
|
||||
If an exception occurs with current CA certs, then try with default certs path, we dont need to mention here the cert path
|
||||
'''
|
||||
self.logging.debug( "Creating CS connection over https didnt worked with user provided certs %s"%e )
|
||||
exception_check = True
|
||||
exception_info = e
|
||||
if method == 'POST':
|
||||
response = requests.post(self.baseurl, params=payload, verify=https_flag)
|
||||
else:
|
||||
response = requests.get(self.baseurl, params=payload, verify=https_flag)
|
||||
finally:
|
||||
if exception_check == True and exception_info is not None:
|
||||
raise exception_info
|
||||
exception_check = False
|
||||
exception_info = None
|
||||
#use user provided CA certs for request
|
||||
try:
|
||||
if method == 'POST':
|
||||
response = requests.post(self.baseurl, params=payload,
|
||||
cert=cert_path,
|
||||
verify=https_flag)
|
||||
else:
|
||||
response = requests.get(self.baseurl, params=payload,
|
||||
cert=cert_path,
|
||||
verify=https_flag)
|
||||
except Exception, e:
|
||||
# attempt a connection using default certs
|
||||
self.logging.debug("connection failed using provided certs"
|
||||
" because of %s" % e)
|
||||
exception_check = True
|
||||
exception_info = e
|
||||
if method == 'POST':
|
||||
response = requests.post(self.baseurl, params=payload,
|
||||
verify=https_flag)
|
||||
else:
|
||||
response = requests.get(self.baseurl, params=payload,
|
||||
verify=https_flag)
|
||||
finally:
|
||||
if exception_check and exception_info is not None:
|
||||
raise exception_info
|
||||
except ConnectionError, c:
|
||||
self.logging.debug("Connection refused. Reason: %s : %s" %(self.baseurl, c))
|
||||
self.logging.debug("Connection refused."
|
||||
" Reason: %s : %s" % (self.baseurl, c))
|
||||
raise c
|
||||
except HTTPError, h:
|
||||
self.logging.debug("Server returned error code: %s" % h)
|
||||
|
||||
@ -25,9 +25,11 @@ import hashlib
|
||||
|
||||
|
||||
class cloudstackTestClient(object):
|
||||
def __init__(self,mgmtDetails,asyncTimeout=3600,defaultWorkerThreads=10, logging=None):
|
||||
def __init__(self, mgmtDetails, asyncTimeout=3600,
|
||||
defaultWorkerThreads=10, logging=None):
|
||||
self.connection = \
|
||||
cloudstackConnection.cloudConnection( mgmtDetails,asyncTimeout,logging)
|
||||
cloudstackConnection.cloudConnection(mgmtDetails, asyncTimeout,
|
||||
logging)
|
||||
self.apiClient =\
|
||||
cloudstackAPIClient.CloudStackAPIClient(self.connection)
|
||||
self.dbConnection = None
|
||||
@ -46,8 +48,8 @@ class cloudstackTestClient(object):
|
||||
|
||||
def dbConfigure(self, host="localhost", port=3306, user='cloud',
|
||||
passwd='cloud', db='cloud'):
|
||||
self.dbConnection = dbConnection.dbConnection(host, port, user, passwd,
|
||||
db)
|
||||
self.dbConnection = dbConnection.dbConnection(host, port,
|
||||
user, passwd, db)
|
||||
|
||||
def isAdminContext(self):
|
||||
"""
|
||||
|
||||
@ -27,9 +27,9 @@ class managementServer(object):
|
||||
self.port = 8096
|
||||
self.apiKey = None
|
||||
self.securityKey = None
|
||||
self.useHttps = None
|
||||
self.certCAPath = None
|
||||
self.certPath = None
|
||||
self.certCAPath = None
|
||||
self.useHttps = None
|
||||
self.certPath = None
|
||||
|
||||
|
||||
class dbServer(object):
|
||||
|
||||
@ -32,7 +32,7 @@ class deployDataCenters(object):
|
||||
if not path.exists(cfgFile) \
|
||||
and not path.exists(path.abspath(cfgFile)):
|
||||
raise IOError("config file %s not found. please \
|
||||
specify a valid config file" % cfgFile)
|
||||
specify a valid config file" % cfgFile)
|
||||
self.configFile = cfgFile
|
||||
|
||||
def addHosts(self, hosts, zoneId, podId, clusterId, hypervisor):
|
||||
@ -512,7 +512,8 @@ specify a valid config file" % cfgFile)
|
||||
try:
|
||||
self.config = configGenerator.get_setup_config(self.configFile)
|
||||
except:
|
||||
raise cloudstackException.InvalidParameterException("Failed to load config %s" % self.configFile)
|
||||
raise cloudstackException.InvalidParameterException(
|
||||
"Failed to load config %s" % self.configFile)
|
||||
|
||||
mgtDetails = self.config.mgtSvr[0]
|
||||
loggers = self.config.logger
|
||||
@ -532,27 +533,28 @@ specify a valid config file" % cfgFile)
|
||||
if testClientLogFile is not None:
|
||||
testClientLogger = logging.getLogger("testclient.testengine.run")
|
||||
fh = logging.FileHandler(testClientLogFile)
|
||||
fh.setFormatter(logging.
|
||||
Formatter("%(asctime)s - %(levelname)s - %(name)s\
|
||||
- %(message)s"))
|
||||
fh.setFormatter(logging.Formatter(
|
||||
"%(asctime)s - %(levelname)s - %(name)s\ - %(message)s")
|
||||
)
|
||||
testClientLogger.addHandler(fh)
|
||||
testClientLogger.setLevel(logging.INFO)
|
||||
self.testClientLogger = testClientLogger
|
||||
|
||||
self.testClient = \
|
||||
cloudstackTestClient.\
|
||||
cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
|
||||
cloudstackTestClient.cloudstackTestClient(
|
||||
mgtDetails, logging=self.testClientLogger)
|
||||
|
||||
if mgtDetails.apiKey is None:
|
||||
mgtDetails.apiKey,mgtDetails.securityKey = self.registerApiKey()
|
||||
mgtDetails.port = 8080
|
||||
self.testClient = cloudstackTestClient.cloudstackTestClient( mgtDetails,logging=self.testClientLogger)
|
||||
mgtDetails.apiKey, mgtDetails.securityKey = self.registerApiKey()
|
||||
mgtDetails.port = 8080
|
||||
self.testClient = cloudstackTestClient.cloudstackTestClient(
|
||||
mgtDetails, logging=self.testClientLogger)
|
||||
|
||||
"""config database"""
|
||||
dbSvr = self.config.dbSvr
|
||||
if dbSvr is not None:
|
||||
self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \
|
||||
dbSvr.passwd, dbSvr.db)
|
||||
self.testClient.dbConfigure(
|
||||
dbSvr.dbSvr, dbSvr.port, dbSvr.user, dbSvr.passwd, dbSvr.db)
|
||||
|
||||
self.apiClient = self.testClient.getApiClient()
|
||||
"""set hypervisor"""
|
||||
@ -561,7 +563,6 @@ specify a valid config file" % cfgFile)
|
||||
else:
|
||||
self.apiClient.hypervisor = "XenServer" # Defaults to Xenserver
|
||||
|
||||
|
||||
def updateConfiguration(self, globalCfg):
|
||||
if globalCfg is None:
|
||||
return None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user