]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Fix more pep8 errors.
authorAngus Salkeld <asalkeld@redhat.com>
Mon, 23 Apr 2012 02:04:46 +0000 (12:04 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Mon, 23 Apr 2012 02:06:24 +0000 (12:06 +1000)
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
bin/heat
bin/heat-engine
heat/db/sqlalchemy/api.py
heat/db/sqlalchemy/models.py
heat/engine/manager.py
heat/engine/parser.py

index 4e8244d76ab67755d8120676c5dc577eda5d549c..dc79e58799afaefe7b7d5fc8dae70d22df81f031 100755 (executable)
--- a/bin/heat
+++ b/bin/heat
@@ -61,6 +61,7 @@ from heat.common import exception
 SUCCESS = 0
 FAILURE = 1
 
+
 def catch_error(action):
     """Decorator to provide sensible default error handling for actions."""
     def wrap(func):
@@ -89,6 +90,7 @@ def catch_error(action):
         return wrapper
     return wrap
 
+
 @catch_error('validate')
 def template_validate(options, arguments):
     '''
@@ -114,6 +116,7 @@ def template_validate(options, arguments):
     result = client.validate_template(**parameters)
     print json.dumps(result, indent=2)
 
+
 @catch_error('gettemplate')
 def get_template(options, arguments):
     '''
@@ -123,6 +126,7 @@ def get_template(options, arguments):
     '''
     pass
 
+
 @catch_error('create')
 def stack_create(options, arguments):
     '''
@@ -168,6 +172,7 @@ def stack_create(options, arguments):
     result = c.create_stack(**parameters)
     print json.dumps(result, indent=2)
 
+
 @catch_error('update')
 def stack_update(options, arguments):
     '''
@@ -213,11 +218,12 @@ def stack_update(options, arguments):
     result = c.update_stack(**parameters)
     print json.dumps(result, indent=2)
 
+
 @catch_error('delete')
 def stack_delete(options, arguments):
     '''
     Delete an existing stack.  This shuts down all VMs associated with
-    the stack and (perhaps wrongly) also removes all events associated 
+    the stack and (perhaps wrongly) also removes all events associated
     with the given stack.
 
     Usage: heat delete <stack name>
@@ -234,6 +240,7 @@ def stack_delete(options, arguments):
     result = c.delete_stack(**parameters)
     print json.dumps(result, indent=2)
 
+
 @catch_error('describe')
 def stack_describe(options, arguments):
     '''
@@ -253,6 +260,7 @@ def stack_describe(options, arguments):
     result = c.describe_stacks(**parameters)
     print json.dumps(result, indent=2)
 
+
 @catch_error('events_list')
 def stack_events_list(options, arguments):
     '''
@@ -270,6 +278,7 @@ def stack_events_list(options, arguments):
     result = c.list_stack_events(**parameters)
     print json.dumps(result, indent=2)
 
+
 @catch_error('list')
 def stack_list(options, arguments):
     '''
@@ -281,6 +290,7 @@ def stack_list(options, arguments):
     result = c.list_stacks()
     print json.dumps(result, indent=2)
 
+
 @catch_error('jeos_create')
 def jeos_create(options, arguments):
     '''
@@ -309,13 +319,16 @@ def jeos_create(options, arguments):
         print '  Usage:'
         print '   heat jeos_create <distro> <arch> <instancetype>'
         print '     instance type can be:'
-        print '     gold builds a base image where userdata is used to initialize the instance'
-        print '     cfntools builds a base image where AWS CloudFormation tools are present'
+        print '     gold builds a base image where userdata is used to' \
+              ' initialize the instance'
+        print '     cfntools builds a base image where AWS CloudFormation' \
+              ' tools are present'
         sys.exit(1)
 
     distro = arguments.pop(0)
     arch = arguments.pop(0)
     instance_type = arguments.pop(0)
+    images_dir = '/var/lib/libvirt/images'
 
     arches = ('x86_64', 'i386', 'amd64')
     arches_str = " | ".join(arches)
@@ -337,9 +350,9 @@ def jeos_create(options, arguments):
     fedora_match = re.match('F(1[6-7])', distro)
     if fedora_match:
         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':
-        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:
         logging.error('distro %s not supported' % distro)
         logging.error('try: F16, F17 or U10')
@@ -361,14 +374,17 @@ def jeos_create(options, arguments):
             f = open('%s/%s' % (cfntools_path, cfnname), 'r')
             cfscript_e64 = base64.b64encode(f.read())
             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
         tdl_xml.saveFormatFile('/tmp/tdl', format=1)
         tdl_path = '/tmp/tdl'
 
-    dsk_filename = '/var/lib/libvirt/images/%s-%s-%s-jeos.dsk' % (distro, arch, instance_type)
-    qcow2_filename = '/var/lib/libvirt/images/%s-%s-%s-jeos.qcow2' % (distro, arch, instance_type)
+    dsk_filename = '%s/%s-%s-%s-jeos.dsk' % (images_dir, distro,
+                                             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)
 
     if not os.access(tdl_path, os.R_OK):
@@ -394,12 +410,13 @@ def jeos_create(options, arguments):
     for image in images:
         if image['name'] == distro + '-' + arch + '-' + instance_type:
             image_registered = True
-            #logging.warning(' *** image already in glance: %s > %s' % (image['name'], image['id']))
 
     runoz = None
     if os.access(qcow2_filename, os.R_OK):
         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':
             os.remove(qcow2_filename)
             os.remove(dsk_filename)
@@ -408,14 +425,17 @@ def jeos_create(options, arguments):
         elif runoz == 'n':
             answer = None
             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':
                     logging.info('No action taken')
                     sys.exit(0)
                 elif answer == 'y' and image_registered:
                     answer = None
                     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':
                         logging.info('No action taken')
                         sys.exit(0)
@@ -423,24 +443,29 @@ def jeos_create(options, arguments):
                         client.delete_image(image['id'])
 
     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 = ' '
         if options.debug:
             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)
         res = os.system(ozcmd)
         if res == 256:
             sys.exit(1)
         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)
 
         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,
                   'is_public': True,
@@ -549,14 +574,15 @@ def create_options(parser):
                       metavar="STRATEGY", default=None,
                       help="Authentication strategy (keystone or noauth)")
 
-    parser.add_option('-u', '--template-url', metavar="template_url", default=None,
-                      help="URL of template. Default: None")
-    parser.add_option('-t', '--template-file', metavar="template_file", default=None,
-                      help="Path to the template. Default: None")
+    parser.add_option('-u', '--template-url', metavar="template_url",
+                      default=None, help="URL of template. Default: None")
+    parser.add_option('-t', '--template-file', metavar="template_file",
+                      default=None, help="Path to the template. Default: None")
 
     parser.add_option('-P', '--parameters', metavar="parameters", default=None,
                       help="Parameter values used to create the stack.")
 
+
 def credentials_from_env():
     return dict(username=os.getenv('OS_USERNAME'),
                 password=os.getenv('OS_PASSWORD'),
@@ -564,6 +590,7 @@ def credentials_from_env():
                 auth_url=os.getenv('OS_AUTH_URL'),
                 auth_strategy=os.getenv('OS_AUTH_STRATEGY'))
 
+
 def parse_options(parser, cli_args):
     """
     Returns the parsed CLI options, command to run and its arguments, merged
@@ -657,6 +684,7 @@ def lookup_command(parser, command_name):
 
     return command
 
+
 def main():
     '''
     '''
index b6e4cbf1569009adbf46f95e8b0fd4ab0775a7fb..4136f4d70b4b1d3954f0bfa5ca9cbf223f636501 100755 (executable)
@@ -48,6 +48,7 @@ logger = logging.getLogger('heat.engine')
 
 if __name__ == '__main__':
 
+    default_manager = 'heat.engine.manager.EngineManager'
     conf = config.HeatEngineConfigOpts()
     conf()
     config.FLAGS = conf
@@ -59,7 +60,7 @@ if __name__ == '__main__':
     #utils.monkey_patch()
     server = service.Service.create(binary='heat-engine',
                                     topic='engine',
-                                    manager='heat.engine.manager.EngineManager',
+                                    manager=default_manager,
                                     config=conf)
     service.serve(server)
     service.wait()
index 14829c4b0210fa438dc3eede35b9c0354495dd5f..1e8c10f005f07acafc4739542246d5fa559e18cf 100644 (file)
@@ -19,6 +19,7 @@ from sqlalchemy.orm.session import Session
 from heat.db.sqlalchemy import models
 from heat.db.sqlalchemy.session import get_session
 
+
 def model_query(context, *args, **kwargs):
     """
     :param session: if present, the session to use
@@ -162,7 +163,7 @@ def stack_delete(context, stack_name):
         rrt[r.parsed_template.raw_template.id] = \
             r.parsed_template.raw_template
         session.delete(r)
-    
+
     for pt in rpt.values():
         session.delete(pt)
 
index b85c3c9f2886bc663e11f9ce2bcc3353bdc4189e..fce55751293b519d111b33ac3bc6129a0b59926a 100644 (file)
@@ -149,7 +149,6 @@ class Event(BASE, HeatBase):
     resource_properties = Column(PickleType)
 
 
-
 class Resource(BASE, HeatBase):
     """Represents a resource created by the heat engine."""
 
index e4472df9413c7b1cb23b597b01317816dea0dd86..13f8f08a04d9565a619b7d335c44ba7ae6236548 100644 (file)
@@ -58,7 +58,8 @@ class EngineManager(manager.Manager):
         if stacks == None:
             return res
         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['stack_id'] = s.id
             mem['stack_name'] = s.name
@@ -80,7 +81,8 @@ class EngineManager(manager.Manager):
         res = {'stacks': []}
         s = db_api.stack_get(None, stack_name)
         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['stack_id'] = s.id
             mem['stack_name'] = s.name
@@ -170,7 +172,8 @@ class EngineManager(manager.Manager):
 
         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()
         return None
 
index 63a0509b14e5ce78633444986fbf4814344ab2f5..1aa59f5ae4ee7213711ec44e094c8e0835889f34 100644 (file)
@@ -142,8 +142,8 @@ class Stack(object):
         if pt:
             pt.template = self.t
         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):
         '''