From d57113ca48f1ffdaf455b7e683e97c731d75ffc2 Mon Sep 17 00:00:00 2001 From: Stan Lagun Date: Wed, 27 Mar 2013 11:40:37 +0400 Subject: [PATCH] PEP-8 --- conductor/bin/conductor | 1 - conductor/conductor/app.py | 1 - conductor/conductor/cloud_formation.py | 14 ++++++----- .../conductor/commands/cloud_formation.py | 24 ++++++++----------- conductor/conductor/commands/dispatcher.py | 1 - conductor/conductor/commands/windows_agent.py | 6 ++--- conductor/conductor/config.py | 1 + conductor/conductor/helpers.py | 5 +--- conductor/conductor/rabbitmq.py | 2 ++ conductor/conductor/reporting.py | 2 +- conductor/conductor/windows_agent.py | 12 ++++++---- conductor/conductor/workflow.py | 1 + 12 files changed, 33 insertions(+), 37 deletions(-) diff --git a/conductor/bin/conductor b/conductor/bin/conductor index 8c74b5c..4c938b8 100644 --- a/conductor/bin/conductor +++ b/conductor/bin/conductor @@ -16,7 +16,6 @@ # License for the specific language governing permissions and limitations # under the License. -import os import sys diff --git a/conductor/conductor/app.py b/conductor/conductor/app.py index 41f4ef0..4d60180 100644 --- a/conductor/conductor/app.py +++ b/conductor/conductor/app.py @@ -62,7 +62,6 @@ def task_received(task, message_id): message_id, anyjson.dumps(task))) - class ConductorWorkflowService(service.Service): def __init__(self): super(ConductorWorkflowService, self).__init__() diff --git a/conductor/conductor/cloud_formation.py b/conductor/conductor/cloud_formation.py index ba33c8e..ca9c06f 100644 --- a/conductor/conductor/cloud_formation.py +++ b/conductor/conductor/cloud_formation.py @@ -6,6 +6,7 @@ from random import choice import time import string + def update_cf_stack(engine, context, body, template, mappings, arguments, **kwargs): command_dispatcher = context['/commandDispatcher'] @@ -17,6 +18,7 @@ def update_cf_stack(engine, context, body, template, name='cf', command='CreateOrUpdate', template=template, mappings=mappings, arguments=arguments, callback=callback) + def delete_cf_stack(engine, context, body, **kwargs): command_dispatcher = context['/commandDispatcher'] @@ -31,8 +33,8 @@ def prepare_user_data(context, hostname, service, unit, template='Default', **kw settings = config.CONF.rabbitmq with open('data/init.ps1') as init_script_file: - with open('data/templates/agent-config/%s.template' - % template) as template_file: + with open('data/templates/agent-config/{0}.template'.format( + template)) as template_file: init_script = init_script_file.read() template_data = template_file.read() template_data = template_data.replace( @@ -44,8 +46,8 @@ def prepare_user_data(context, hostname, service, unit, template='Default', **kw ) template_data = template_data.replace( '%RESULT_QUEUE%', - '-execution-results-%s' % - str(context['/dataSource']['id']).lower()) + '-execution-results-{0}'.format( + str(context['/dataSource']['id'])).lower()) init_script = init_script.replace( '%WINDOWS_AGENT_CONFIG_BASE64%', @@ -57,6 +59,7 @@ def prepare_user_data(context, hostname, service, unit, template='Default', **kw counter = 0 + def int2base(x, base): digs = string.digits + string.lowercase if x < 0: sign = -1 @@ -72,6 +75,7 @@ def int2base(x, base): digits.reverse() return ''.join(digits) + def generate_hostname(**kwargs): global counter prefix = ''.join(choice(string.lowercase) for _ in range(5)) @@ -81,8 +85,6 @@ def generate_hostname(**kwargs): return prefix + timestamp + suffix - - xml_code_engine.XmlCodeEngine.register_function( update_cf_stack, "update-cf-stack") diff --git a/conductor/conductor/commands/cloud_formation.py b/conductor/conductor/commands/cloud_formation.py index cf0c2f0..1d1a0e7 100644 --- a/conductor/conductor/commands/cloud_formation.py +++ b/conductor/conductor/commands/cloud_formation.py @@ -19,7 +19,7 @@ class HeatExecutor(CommandBase): self._stack = 'e' + stack settings = conductor.config.CONF.heat self._heat_client = Client('1', settings.url, - token_only=True, token=token) + token_only=True, token=token) def execute(self, command, callback, **kwargs): log.debug('Got command {0} on stack {1}'.format(command, self._stack)) @@ -33,7 +33,6 @@ class HeatExecutor(CommandBase): elif command == 'Delete': return self._execute_delete(callback) - def _execute_create_update(self, template, mappings, arguments, callback): with open('data/templates/cf/%s.template' % template) as template_file: template_data = template_file.read() @@ -52,10 +51,9 @@ class HeatExecutor(CommandBase): 'callback': callback }) - def has_pending_commands(self): return len(self._update_pending_list) + \ - len(self._delete_pending_list) > 0 + len(self._delete_pending_list) > 0 def execute_pending(self): r1 = self._execute_pending_updates() @@ -74,7 +72,8 @@ class HeatExecutor(CommandBase): arguments = conductor.helpers.merge_dicts( arguments, t['arguments'], max_levels=1) - log.info('Executing heat template {0} with arguments {1} on stack {2}' + log.info( + 'Executing heat template {0} with arguments {1} on stack {2}' .format(anyjson.dumps(template), arguments, self._stack)) try: @@ -82,8 +81,8 @@ class HeatExecutor(CommandBase): stack_id=self._stack, parameters=arguments, template=template) - log.debug('Waiting for the stack {0} to be update' - .format(self._stack)) + log.debug( + 'Waiting for the stack {0} to be update'.format(self._stack)) self._wait_state('UPDATE_COMPLETE') log.info('Stack {0} updated'.format(self._stack)) except heatclient.exc.HTTPNotFound: @@ -91,12 +90,11 @@ class HeatExecutor(CommandBase): stack_name=self._stack, parameters=arguments, template=template) - log.debug('Waiting for the stack {0} to be create' - .format(self._stack)) + log.debug('Waiting for the stack {0} to be create'.format( + self._stack)) self._wait_state('CREATE_COMPLETE') log.info('Stack {0} created'.format(self._stack)) - pending_list = self._update_pending_list self._update_pending_list = [] @@ -113,8 +111,8 @@ class HeatExecutor(CommandBase): try: self._heat_client.stacks.delete( stack_id=self._stack) - log.debug('Waiting for the stack {0} to be deleted' - .format(self._stack)) + log.debug( + 'Waiting for the stack {0} to be deleted'.format(self._stack)) self._wait_state(['DELETE_COMPLETE', '']) log.info('Stack {0} deleted'.format(self._stack)) except Exception as ex: @@ -133,7 +131,6 @@ class HeatExecutor(CommandBase): else: states = [state] - while True: try: status = self._heat_client.stacks.get( @@ -147,4 +144,3 @@ class HeatExecutor(CommandBase): if status not in states: raise EnvironmentError() return - diff --git a/conductor/conductor/commands/dispatcher.py b/conductor/conductor/commands/dispatcher.py index d44f224..3f7716a 100644 --- a/conductor/conductor/commands/dispatcher.py +++ b/conductor/conductor/commands/dispatcher.py @@ -28,7 +28,6 @@ class CommandDispatcher(command.CommandBase): return result - def close(self): for t in self._command_map.values(): t.close() diff --git a/conductor/conductor/commands/windows_agent.py b/conductor/conductor/commands/windows_agent.py index c4d8086..ea66b71 100644 --- a/conductor/conductor/commands/windows_agent.py +++ b/conductor/conductor/commands/windows_agent.py @@ -18,9 +18,8 @@ class WindowsAgentExecutor(CommandBase): rmqclient.declare(self._results_queue) def execute(self, template, mappings, host, service, callback): - with open('data/templates/agent/%s.template' % - template) as template_file: - template_data = template_file.read() + with open('data/templates/agent/%s.template' % template) as file: + template_data = file.read() template_data = conductor.helpers.transform_json( json.loads(template_data), mappings) @@ -57,7 +56,6 @@ class WindowsAgentExecutor(CommandBase): self._pending_list.pop(index) item['callback'](msg.body) - return True diff --git a/conductor/conductor/config.py b/conductor/conductor/config.py index 5190918..f93bd78 100644 --- a/conductor/conductor/config.py +++ b/conductor/conductor/config.py @@ -73,6 +73,7 @@ def parse_args(args=None, usage=None, default_config_files=None): usage=usage, default_config_files=default_config_files) + def setup_logging(): """ Sets up the logging options for a log with supplied name diff --git a/conductor/conductor/helpers.py b/conductor/conductor/helpers.py index b133836..435a35b 100644 --- a/conductor/conductor/helpers.py +++ b/conductor/conductor/helpers.py @@ -1,5 +1,6 @@ import types + def transform_json(json, mappings): if isinstance(json, types.ListType): return [transform_json(t, mappings) for t in json] @@ -46,7 +47,3 @@ def find(f, seq): return item, index index += 1 return None, -1 - - -def generate(length): - return ''.join(choice(chars) for _ in range(length)) diff --git a/conductor/conductor/rabbitmq.py b/conductor/conductor/rabbitmq.py index 6a6de5e..7183dee 100644 --- a/conductor/conductor/rabbitmq.py +++ b/conductor/conductor/rabbitmq.py @@ -4,6 +4,7 @@ puka = patcher.import_patched('puka') import anyjson import config + class RmqClient(object): def __init__(self): settings = config.CONF.rabbitmq @@ -65,6 +66,7 @@ class RmqClient(object): return Subscription(self._client, queue) + class Subscription(object): def __init__(self, client, queue): self._client = client diff --git a/conductor/conductor/reporting.py b/conductor/conductor/reporting.py index cf47440..b6c1458 100644 --- a/conductor/conductor/reporting.py +++ b/conductor/conductor/reporting.py @@ -1,7 +1,7 @@ import xml_code_engine -import json import rabbitmq + class Reporter(object): def __init__(self, rmqclient, task_id, environment_id): self._rmqclient = rmqclient diff --git a/conductor/conductor/windows_agent.py b/conductor/conductor/windows_agent.py index 2778a0d..e39fa37 100644 --- a/conductor/conductor/windows_agent.py +++ b/conductor/conductor/windows_agent.py @@ -6,12 +6,14 @@ log = logging.getLogger(__name__) def send_command(engine, context, body, template, service, host, mappings=None, result=None, **kwargs): - if not mappings: mappings = {} + if not mappings: + mappings = {} command_dispatcher = context['/commandDispatcher'] def callback(result_value): - log.info('Received result from {3} for {0}: {1}. Body is {2}'.format( - template, result_value, body, host)) + log.info( + 'Received result from {3} for {0}: {1}. Body is {2}'.format( + template, result_value, body, host)) if result is not None: context[result] = result_value['Result'] @@ -19,8 +21,8 @@ def send_command(engine, context, body, template, service, host, mappings=None, if success_handler is not None: engine.evaluate_content(success_handler, context) - command_dispatcher.execute(name='agent', - template=template, mappings=mappings, + command_dispatcher.execute( + name='agent', template=template, mappings=mappings, host=host, service=service, callback=callback) diff --git a/conductor/conductor/workflow.py b/conductor/conductor/workflow.py index bdf6224..e0f6198 100644 --- a/conductor/conductor/workflow.py +++ b/conductor/conductor/workflow.py @@ -5,6 +5,7 @@ import re import xml_code_engine import function_context + class Workflow(object): def __init__(self, filename, data, command_dispatcher, config, reporter): self._data = data