Fix more pep8 errors.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2012-04-23 12:04:46 +10:00
parent 3323d045d2
commit e67e9c80bf
6 changed files with 61 additions and 29 deletions

View File

@ -61,6 +61,7 @@ from heat.common import exception
SUCCESS = 0 SUCCESS = 0
FAILURE = 1 FAILURE = 1
def catch_error(action): def catch_error(action):
"""Decorator to provide sensible default error handling for actions.""" """Decorator to provide sensible default error handling for actions."""
def wrap(func): def wrap(func):
@ -89,6 +90,7 @@ def catch_error(action):
return wrapper return wrapper
return wrap return wrap
@catch_error('validate') @catch_error('validate')
def template_validate(options, arguments): def template_validate(options, arguments):
''' '''
@ -114,6 +116,7 @@ def template_validate(options, arguments):
result = client.validate_template(**parameters) result = client.validate_template(**parameters)
print json.dumps(result, indent=2) print json.dumps(result, indent=2)
@catch_error('gettemplate') @catch_error('gettemplate')
def get_template(options, arguments): def get_template(options, arguments):
''' '''
@ -123,6 +126,7 @@ def get_template(options, arguments):
''' '''
pass pass
@catch_error('create') @catch_error('create')
def stack_create(options, arguments): def stack_create(options, arguments):
''' '''
@ -168,6 +172,7 @@ def stack_create(options, arguments):
result = c.create_stack(**parameters) result = c.create_stack(**parameters)
print json.dumps(result, indent=2) print json.dumps(result, indent=2)
@catch_error('update') @catch_error('update')
def stack_update(options, arguments): def stack_update(options, arguments):
''' '''
@ -213,6 +218,7 @@ def stack_update(options, arguments):
result = c.update_stack(**parameters) result = c.update_stack(**parameters)
print json.dumps(result, indent=2) print json.dumps(result, indent=2)
@catch_error('delete') @catch_error('delete')
def stack_delete(options, arguments): def stack_delete(options, arguments):
''' '''
@ -234,6 +240,7 @@ def stack_delete(options, arguments):
result = c.delete_stack(**parameters) result = c.delete_stack(**parameters)
print json.dumps(result, indent=2) print json.dumps(result, indent=2)
@catch_error('describe') @catch_error('describe')
def stack_describe(options, arguments): def stack_describe(options, arguments):
''' '''
@ -253,6 +260,7 @@ def stack_describe(options, arguments):
result = c.describe_stacks(**parameters) result = c.describe_stacks(**parameters)
print json.dumps(result, indent=2) print json.dumps(result, indent=2)
@catch_error('events_list') @catch_error('events_list')
def stack_events_list(options, arguments): def stack_events_list(options, arguments):
''' '''
@ -270,6 +278,7 @@ def stack_events_list(options, arguments):
result = c.list_stack_events(**parameters) result = c.list_stack_events(**parameters)
print json.dumps(result, indent=2) print json.dumps(result, indent=2)
@catch_error('list') @catch_error('list')
def stack_list(options, arguments): def stack_list(options, arguments):
''' '''
@ -281,6 +290,7 @@ def stack_list(options, arguments):
result = c.list_stacks() result = c.list_stacks()
print json.dumps(result, indent=2) print json.dumps(result, indent=2)
@catch_error('jeos_create') @catch_error('jeos_create')
def jeos_create(options, arguments): def jeos_create(options, arguments):
''' '''
@ -309,13 +319,16 @@ def jeos_create(options, arguments):
print ' Usage:' print ' Usage:'
print ' heat jeos_create <distro> <arch> <instancetype>' print ' heat jeos_create <distro> <arch> <instancetype>'
print ' instance type can be:' print ' instance type can be:'
print ' gold builds a base image where userdata is used to initialize the instance' print ' gold builds a base image where userdata is used to' \
print ' cfntools builds a base image where AWS CloudFormation tools are present' ' initialize the instance'
print ' cfntools builds a base image where AWS CloudFormation' \
' tools are present'
sys.exit(1) sys.exit(1)
distro = arguments.pop(0) distro = arguments.pop(0)
arch = arguments.pop(0) arch = arguments.pop(0)
instance_type = arguments.pop(0) instance_type = arguments.pop(0)
images_dir = '/var/lib/libvirt/images'
arches = ('x86_64', 'i386', 'amd64') arches = ('x86_64', 'i386', 'amd64')
arches_str = " | ".join(arches) arches_str = " | ".join(arches)
@ -337,9 +350,9 @@ def jeos_create(options, arguments):
fedora_match = re.match('F(1[6-7])', distro) fedora_match = re.match('F(1[6-7])', distro)
if fedora_match: if fedora_match:
version = fedora_match.group(1) version = fedora_match.group(1)
iso = '/var/lib/libvirt/images/Fedora-%s-%s-DVD.iso' % (version, arch) iso = '%s/Fedora-%s-%s-DVD.iso' % (images_dir, version, arch)
elif distro == 'U10': elif distro == 'U10':
iso = '/var/lib/libvirt/images/ubuntu-10.04.3-server-%s.iso' % arch iso = '%s/ubuntu-10.04.3-server-%s.iso' % (images_dir, arch)
else: else:
logging.error('distro %s not supported' % distro) logging.error('distro %s not supported' % distro)
logging.error('try: F16, F17 or U10') logging.error('try: F16, F17 or U10')
@ -361,14 +374,17 @@ def jeos_create(options, arguments):
f = open('%s/%s' % (cfntools_path, cfnname), 'r') f = open('%s/%s' % (cfntools_path, cfnname), 'r')
cfscript_e64 = base64.b64encode(f.read()) cfscript_e64 = base64.b64encode(f.read())
f.close() f.close()
tdl_xml.xpathEval("/template/files/file[@name='/opt/aws/bin/%s']" % cfnname)[0].setContent(cfscript_e64) cfnpath = "/template/files/file[@name='/opt/aws/bin/%s']" % cfnname
tdl_xml.xpathEval(cfnpath)[0].setContent(cfscript_e64)
# TODO(sdake) INSECURE # TODO(sdake) INSECURE
tdl_xml.saveFormatFile('/tmp/tdl', format=1) tdl_xml.saveFormatFile('/tmp/tdl', format=1)
tdl_path = '/tmp/tdl' tdl_path = '/tmp/tdl'
dsk_filename = '/var/lib/libvirt/images/%s-%s-%s-jeos.dsk' % (distro, arch, instance_type) dsk_filename = '%s/%s-%s-%s-jeos.dsk' % (images_dir, distro,
qcow2_filename = '/var/lib/libvirt/images/%s-%s-%s-jeos.qcow2' % (distro, arch, instance_type) arch, instance_type)
qcow2_filename = '%s/%s-%s-%s-jeos.qcow2' % (images_dir, distro,
arch, instance_type)
image_name = '%s-%s-%s' % (distro, arch, instance_type) image_name = '%s-%s-%s' % (distro, arch, instance_type)
if not os.access(tdl_path, os.R_OK): if not os.access(tdl_path, os.R_OK):
@ -394,12 +410,13 @@ def jeos_create(options, arguments):
for image in images: for image in images:
if image['name'] == distro + '-' + arch + '-' + instance_type: if image['name'] == distro + '-' + arch + '-' + instance_type:
image_registered = True image_registered = True
#logging.warning(' *** image already in glance: %s > %s' % (image['name'], image['id']))
runoz = None runoz = None
if os.access(qcow2_filename, os.R_OK): if os.access(qcow2_filename, os.R_OK):
while runoz not in ('y', 'n'): while runoz not in ('y', 'n'):
runoz = raw_input('An existing JEOS was found on disk. Do you want to build a fresh JEOS? (y/n) ').lower() runoz = raw_input('An existing JEOS was found on disk.' \
' Do you want to build a fresh JEOS?' \
' (y/n) ').lower()
if runoz == 'y': if runoz == 'y':
os.remove(qcow2_filename) os.remove(qcow2_filename)
os.remove(dsk_filename) os.remove(dsk_filename)
@ -408,14 +425,17 @@ def jeos_create(options, arguments):
elif runoz == 'n': elif runoz == 'n':
answer = None answer = None
while answer not in ('y', 'n'): while answer not in ('y', 'n'):
answer = raw_input('Do you want to register your existing JEOS file with glance? (y/n) ').lower() answer = raw_input('Do you want to register your existing' \
' JEOS file with glance? (y/n) ').lower()
if answer == 'n': if answer == 'n':
logging.info('No action taken') logging.info('No action taken')
sys.exit(0) sys.exit(0)
elif answer == 'y' and image_registered: elif answer == 'y' and image_registered:
answer = None answer = None
while answer not in ('y', 'n'): while answer not in ('y', 'n'):
answer = raw_input('Do you want to delete the existing JEOS in glance? (y/n) ').lower() answer = raw_input('Do you want to delete the ' \
'existing JEOS in glance?' \
' (y/n) ').lower()
if answer == 'n': if answer == 'n':
logging.info('No action taken') logging.info('No action taken')
sys.exit(0) sys.exit(0)
@ -423,24 +443,29 @@ def jeos_create(options, arguments):
client.delete_image(image['id']) client.delete_image(image['id'])
if runoz == None or runoz == 'y': if runoz == None or runoz == 'y':
logging.info('Creating JEOS image (%s) - this takes approximately 10 minutes.' % image_name) logging.info('Creating JEOS image (%s) - '\
'this takes approximately 10 minutes.' % image_name)
extra_opts = ' ' extra_opts = ' '
if options.debug: if options.debug:
extra_opts = ' -d 3 ' extra_opts = ' -d 3 '
ozcmd="oz-install %s -t 50000 -u %s -x /dev/null" % (extra_opts, tdl_path) ozcmd = "oz-install %s -t 50000 -u %s -x /dev/null" % (extra_opts,
tdl_path)
logging.debug("Running : %s" % ozcmd) logging.debug("Running : %s" % ozcmd)
res = os.system(ozcmd) res = os.system(ozcmd)
if res == 256: if res == 256:
sys.exit(1) sys.exit(1)
if not os.access(dsk_filename, os.R_OK): if not os.access(dsk_filename, os.R_OK):
logging.error('oz-install did not create the image, check your oz installation.') logging.error('oz-install did not create the image,' \
' check your oz installation.')
sys.exit(1) sys.exit(1)
logging.info('Converting raw disk image to a qcow2 image.') logging.info('Converting raw disk image to a qcow2 image.')
os.system("qemu-img convert -O qcow2 %s %s" % (dsk_filename, qcow2_filename)) os.system("qemu-img convert -O qcow2 %s %s" % (dsk_filename,
qcow2_filename))
logging.info('Registering JEOS image (%s) with OpenStack Glance.' % image_name) logging.info('Registering JEOS image (%s) ' \
'with OpenStack Glance.' % image_name)
image_meta = {'name': image_name, image_meta = {'name': image_name,
'is_public': True, 'is_public': True,
@ -549,14 +574,15 @@ def create_options(parser):
metavar="STRATEGY", default=None, metavar="STRATEGY", default=None,
help="Authentication strategy (keystone or noauth)") help="Authentication strategy (keystone or noauth)")
parser.add_option('-u', '--template-url', metavar="template_url", default=None, parser.add_option('-u', '--template-url', metavar="template_url",
help="URL of template. Default: None") default=None, help="URL of template. Default: None")
parser.add_option('-t', '--template-file', metavar="template_file", default=None, parser.add_option('-t', '--template-file', metavar="template_file",
help="Path to the template. Default: None") default=None, help="Path to the template. Default: None")
parser.add_option('-P', '--parameters', metavar="parameters", default=None, parser.add_option('-P', '--parameters', metavar="parameters", default=None,
help="Parameter values used to create the stack.") help="Parameter values used to create the stack.")
def credentials_from_env(): def credentials_from_env():
return dict(username=os.getenv('OS_USERNAME'), return dict(username=os.getenv('OS_USERNAME'),
password=os.getenv('OS_PASSWORD'), password=os.getenv('OS_PASSWORD'),
@ -564,6 +590,7 @@ def credentials_from_env():
auth_url=os.getenv('OS_AUTH_URL'), auth_url=os.getenv('OS_AUTH_URL'),
auth_strategy=os.getenv('OS_AUTH_STRATEGY')) auth_strategy=os.getenv('OS_AUTH_STRATEGY'))
def parse_options(parser, cli_args): def parse_options(parser, cli_args):
""" """
Returns the parsed CLI options, command to run and its arguments, merged Returns the parsed CLI options, command to run and its arguments, merged
@ -657,6 +684,7 @@ def lookup_command(parser, command_name):
return command return command
def main(): def main():
''' '''
''' '''

View File

@ -48,6 +48,7 @@ logger = logging.getLogger('heat.engine')
if __name__ == '__main__': if __name__ == '__main__':
default_manager = 'heat.engine.manager.EngineManager'
conf = config.HeatEngineConfigOpts() conf = config.HeatEngineConfigOpts()
conf() conf()
config.FLAGS = conf config.FLAGS = conf
@ -59,7 +60,7 @@ if __name__ == '__main__':
#utils.monkey_patch() #utils.monkey_patch()
server = service.Service.create(binary='heat-engine', server = service.Service.create(binary='heat-engine',
topic='engine', topic='engine',
manager='heat.engine.manager.EngineManager', manager=default_manager,
config=conf) config=conf)
service.serve(server) service.serve(server)
service.wait() service.wait()

View File

@ -19,6 +19,7 @@ from sqlalchemy.orm.session import Session
from heat.db.sqlalchemy import models from heat.db.sqlalchemy import models
from heat.db.sqlalchemy.session import get_session from heat.db.sqlalchemy.session import get_session
def model_query(context, *args, **kwargs): def model_query(context, *args, **kwargs):
""" """
:param session: if present, the session to use :param session: if present, the session to use

View File

@ -149,7 +149,6 @@ class Event(BASE, HeatBase):
resource_properties = Column(PickleType) resource_properties = Column(PickleType)
class Resource(BASE, HeatBase): class Resource(BASE, HeatBase):
"""Represents a resource created by the heat engine.""" """Represents a resource created by the heat engine."""

View File

@ -58,7 +58,8 @@ class EngineManager(manager.Manager):
if stacks == None: if stacks == None:
return res return res
for s in stacks: for s in stacks:
ps = parser.Stack(s.name, s.raw_template.parsed_template.template, s.id, params) ps = parser.Stack(s.name, s.raw_template.parsed_template.template,
s.id, params)
mem = {} mem = {}
mem['stack_id'] = s.id mem['stack_id'] = s.id
mem['stack_name'] = s.name mem['stack_name'] = s.name
@ -80,7 +81,8 @@ class EngineManager(manager.Manager):
res = {'stacks': []} res = {'stacks': []}
s = db_api.stack_get(None, stack_name) s = db_api.stack_get(None, stack_name)
if s: if s:
ps = parser.Stack(s.name, s.raw_template.parsed_template.template, s.id, params) ps = parser.Stack(s.name, s.raw_template.parsed_template.template,
s.id, params)
mem = {} mem = {}
mem['stack_id'] = s.id mem['stack_id'] = s.id
mem['stack_name'] = s.name mem['stack_name'] = s.name
@ -170,7 +172,8 @@ class EngineManager(manager.Manager):
logger.info('deleting stack %s' % stack_name) logger.info('deleting stack %s' % stack_name)
ps = parser.Stack(st.name, st.raw_template.parsed_template.template, st.id, params) ps = parser.Stack(st.name, st.raw_template.parsed_template.template,
st.id, params)
ps.delete() ps.delete()
return None return None

View File

@ -142,8 +142,8 @@ class Stack(object):
if pt: if pt:
pt.template = self.t pt.template = self.t
else: else:
logger.warn('Cant find parsed template to update %d' % self.parsed_template_id) logger.warn('Cant find parsed template to update %d' % \
self.parsed_template_id)
def create_blocking(self): def create_blocking(self):
''' '''