mirror of https://github.com/apache/cloudstack.git
marvin_refactor: pep8 all python files
Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
parent
b006c993f3
commit
50aa256699
|
|
@ -22,7 +22,8 @@ try:
|
|||
from requests import Timeout
|
||||
from requests import RequestException
|
||||
except ImportError:
|
||||
raise Exception("requests installation not found. use pip install requests to continue")
|
||||
raise Exception("requests installation not found. use pip install \
|
||||
requests to continue")
|
||||
import urllib
|
||||
import base64
|
||||
import hmac
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from argparse import ArgumentParser
|
|||
from generate.xmltoapi import codeGenerator
|
||||
from generate.apitoentity import generate
|
||||
|
||||
|
||||
def get_api_cmds():
|
||||
""" Returns the API cmdlet instances
|
||||
|
||||
|
|
@ -28,13 +29,13 @@ def get_api_cmds():
|
|||
"""
|
||||
namespace = {}
|
||||
execfile('cloudstackAPI/__init__.py', namespace)
|
||||
api_classes = __import__('cloudstackAPI', globals().update(namespace), fromlist=['*'], level=-1)
|
||||
|
||||
api_classes = __import__(
|
||||
'cloudstackAPI', globals().update(namespace), fromlist=['*'], level=-1)
|
||||
|
||||
cmdlist = map(
|
||||
lambda f: getattr(api_classes, f),
|
||||
filter(
|
||||
lambda t: t.startswith('__') == False,
|
||||
lambda t: t.startswith('__') is False,
|
||||
dir(api_classes)
|
||||
)
|
||||
)
|
||||
|
|
@ -45,7 +46,8 @@ def get_api_cmds():
|
|||
clslist = map(
|
||||
lambda g: getattr(g, g.__name__.split('.')[-1] + 'Cmd'),
|
||||
filter(
|
||||
lambda h: h.__name__.split('.')[-1] not in ['baseCmd', 'baseResponse', 'cloudstackAPIClient'],
|
||||
lambda h: h.__name__.split('.')[-1] not in [
|
||||
'baseCmd', 'baseResponse', 'cloudstackAPIClient'],
|
||||
cmdlist
|
||||
)
|
||||
)
|
||||
|
|
@ -55,16 +57,16 @@ def get_api_cmds():
|
|||
if __name__ == "__main__":
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("-o", "--output", dest="output",
|
||||
help="The path to the generated code entities, default\
|
||||
help="The path to the generated code entities, default\
|
||||
is .")
|
||||
parser.add_argument("-s", "--specfile", dest="spec",
|
||||
help="The path and name of the api spec xml file,\
|
||||
help="The path and name of the api spec xml file,\
|
||||
default is /etc/cloud/cli/commands.xml")
|
||||
parser.add_argument("-e", "--endpoint", dest="endpoint",
|
||||
help="The endpoint mgmt server (with open 8096) where\
|
||||
help="The endpoint mgmt server (with open 8096) where\
|
||||
apis are discovered, default is localhost")
|
||||
parser.add_argument("-y", "--entity", dest="entity", action="store_true",
|
||||
help="Generate entity based classes")
|
||||
help="Generate entity based classes")
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
|
|
@ -98,4 +100,4 @@ response=json' % options.endpoint
|
|||
cg.generateCodeFromJSON(endpointUrl)
|
||||
|
||||
if options.entity:
|
||||
generate(get_api_cmds())
|
||||
generate(get_api_cmds())
|
||||
|
|
|
|||
|
|
@ -20,13 +20,16 @@ try:
|
|||
from mysql import connector
|
||||
from mysql.connector import errors
|
||||
except ImportError:
|
||||
raise Exception("mysql-connector-python not installed. pip install mysql-connector-python to continue")
|
||||
raise Exception(
|
||||
"mysql-connector-python not installed. pip install \
|
||||
mysql-connector-python to continue")
|
||||
import contextlib
|
||||
import cloudstackException
|
||||
import os
|
||||
|
||||
|
||||
class dbConnection(object):
|
||||
|
||||
def __init__(self, host="localhost", port=3306, user='cloud',
|
||||
passwd='cloud', db='cloud'):
|
||||
self.host = host
|
||||
|
|
@ -52,7 +55,7 @@ class dbConnection(object):
|
|||
try:
|
||||
resultRow = cursor.fetchall()
|
||||
except errors.InterfaceError:
|
||||
#Raised on empty result - DML
|
||||
# Raised on empty result - DML
|
||||
resultRow = []
|
||||
return resultRow
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class VirtualMachineWithStaticNat(VirtualMachineFactory):
|
|||
domainid=self.domainid,
|
||||
zoneid=self.zoneid,
|
||||
)
|
||||
ipassoc.enableStaticNat(
|
||||
self.enableStaticNat(
|
||||
apiclient=self.apiclient,
|
||||
ipaddressid=ipassoc.id,
|
||||
virtualmachineid=self.id
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from cloudstackAPI import *
|
|||
|
||||
|
||||
class jsonLoader(object):
|
||||
|
||||
'''The recursive class for building and representing objects with.'''
|
||||
|
||||
def __init__(self, obj):
|
||||
|
|
@ -53,6 +54,7 @@ class jsonLoader(object):
|
|||
|
||||
|
||||
class jsonDump:
|
||||
|
||||
@staticmethod
|
||||
def __serialize(obj):
|
||||
"""Recursively walk object's hierarchy."""
|
||||
|
|
@ -75,7 +77,7 @@ class jsonDump:
|
|||
elif hasattr(obj, '__dict__'):
|
||||
return jsonDump.__serialize(obj.__dict__)
|
||||
else:
|
||||
return repr(obj) # Don't know how to handle, convert to string
|
||||
return repr(obj) # Don't know how to handle, convert to string
|
||||
|
||||
@staticmethod
|
||||
def dump(obj):
|
||||
|
|
@ -85,7 +87,8 @@ class jsonDump:
|
|||
def getClass(module, name):
|
||||
"""Get the CloudStack command class in a module given the name
|
||||
@param module: cloudstack API module eg: createVolume
|
||||
@param name: string name of the class within the module eg: createVolumeResponse
|
||||
@param name: string name of the class within the module eg:
|
||||
createVolumeResponse
|
||||
@return: response class
|
||||
"""
|
||||
module = inspect.getmodule(module)
|
||||
|
|
@ -258,7 +261,7 @@ due to missing parameter jobid"
|
|||
except cloudstackException.cloudstackAPIException, e:
|
||||
print e
|
||||
|
||||
result = { "queryasyncjobresultresponse" : {} }
|
||||
result = {"queryasyncjobresultresponse": {}}
|
||||
asynJob = getResultObj(result)
|
||||
print "AsyncJob %s" % asynJob
|
||||
|
||||
|
|
@ -282,13 +285,7 @@ due to missing parameter jobid"
|
|||
zone = getResultObj(result, res)
|
||||
print "Zone id %s" % zone.id
|
||||
|
||||
result = { "queryasyncjobresultresponse" : {"accountid":"4a8c3cd0-a696-11e2-b7a5-1aab0c3b0463","userid":"4a8c671e-a696-11e2-b7a5-1aab0c3b0463","cmd":"org.apache.cloudstack.api.command.admin.network.CreatePhysicalNetworkCmd","jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"physicalnetwork":{"id":"e0bc9017-9ba8-4551-a6f9-6b3b2ac1d59c","name":"Sandbox-pnet","broadcastdomainrange":"ZONE","zoneid":"88e796cd-953a-44b9-9445-a7c3ee205cc2","state":"Disabled"}},"created":"2013-04-16T18:37:01+0530","jobid":"8fc09350-f42a-4e04-9427-3d1b68f73dd0"} }
|
||||
res = createPhysicalNetwork.createPhysicalNetworkResponse()
|
||||
res = getResultObj(result, res)
|
||||
print "PhysicalNetworkResponse %s" % res
|
||||
print "PhysicalNetwork %s" % res.jobresult.id
|
||||
|
||||
result = { "listtemplatesresponse" : { } }
|
||||
result = {"listtemplatesresponse": {}}
|
||||
print getResultObj(result, listTemplates.listTemplatesResponse())
|
||||
|
||||
result = '''{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from marvin.entity.zone import Zone
|
|||
from marvin.entity.serviceoffering import ServiceOffering
|
||||
from marvin.entity.domain import Domain
|
||||
|
||||
|
||||
def get_domain(apiclient):
|
||||
"Returns a default `ROOT` domain"
|
||||
|
||||
|
|
@ -31,6 +32,7 @@ def get_domain(apiclient):
|
|||
else:
|
||||
raise Exception("Failed to find any domains")
|
||||
|
||||
|
||||
def get_zone(apiclient):
|
||||
"Returns the default enabled zone"
|
||||
|
||||
|
|
@ -46,6 +48,7 @@ def get_zone(apiclient):
|
|||
else:
|
||||
raise Exception("Failed to find specified zone.")
|
||||
|
||||
|
||||
def get_service_offering(apiclient, storagetype='shared', scope=None):
|
||||
"""Returns the service offering that is available in the zone
|
||||
|
||||
|
|
@ -62,6 +65,7 @@ def get_service_offering(apiclient, storagetype='shared', scope=None):
|
|||
return service
|
||||
raise Exception("No service offering for storagetype %s available")
|
||||
|
||||
|
||||
def get_template(apiclient, description=None):
|
||||
"Returns a featured template with a specific description"
|
||||
templates = Template.list(
|
||||
|
|
@ -74,6 +78,8 @@ def get_template(apiclient, description=None):
|
|||
if template.isready:
|
||||
return template
|
||||
else:
|
||||
raise Exception("None of the templates are ready in your deployment")
|
||||
raise Exception(
|
||||
"None of the templates are ready in your deployment")
|
||||
else:
|
||||
raise Exception("Failed to find ready and featured template of : %s" % description)
|
||||
raise Exception(
|
||||
"Failed to find ready and featured template of : %s" % description)
|
||||
|
|
|
|||
Loading…
Reference in New Issue