From f33bd681ab5502bbd7ccec0dc7da55ce2c8745d2 Mon Sep 17 00:00:00 2001 From: Stan Lagun Date: Thu, 28 Mar 2013 01:11:06 +0400 Subject: [PATCH] Heat auto-discovery, keero-linux-keys -> keero-keys --- conductor/conductor/app.py | 61 +-- .../conductor/commands/cloud_formation.py | 16 +- conductor/conductor/config.py | 3 +- conductor/conductor/windows_agent.py | 56 +-- conductor/data/workflows/AD.xml | 442 +++++++++--------- conductor/data/workflows/IIS.xml | 128 ++--- conductor/etc/conductor.conf | 3 +- 7 files changed, 357 insertions(+), 352 deletions(-) diff --git a/conductor/conductor/app.py b/conductor/conductor/app.py index 0fb1244..e831845 100644 --- a/conductor/conductor/app.py +++ b/conductor/conductor/app.py @@ -22,42 +22,43 @@ log = logging.getLogger(__name__) def task_received(task, message_id): with rabbitmq.RmqClient() as rmqclient: - log.info('Starting processing task {0}: {1}'.format( - message_id, anyjson.dumps(task))) - reporter = reporting.Reporter(rmqclient, message_id, task['id']) + try: + log.info('Starting processing task {0}: {1}'.format( + message_id, anyjson.dumps(task))) + reporter = reporting.Reporter(rmqclient, message_id, task['id']) - command_dispatcher = CommandDispatcher( - task['id'], rmqclient, task['token'], task['tenant_id']) - workflows = [] - for path in glob.glob("data/workflows/*.xml"): - log.debug('Loading XML {0}'.format(path)) - workflow = Workflow(path, task, command_dispatcher, config, - reporter) - workflows.append(workflow) + command_dispatcher = CommandDispatcher( + task['id'], rmqclient, task['token'], task['tenant_id']) + workflows = [] + for path in glob.glob("data/workflows/*.xml"): + log.debug('Loading XML {0}'.format(path)) + workflow = Workflow(path, task, command_dispatcher, config, + reporter) + workflows.append(workflow) - while True: - try: - while True: - result = False - for workflow in workflows: - if workflow.execute(): - result = True - if not result: + while True: + try: + while True: + result = False + for workflow in workflows: + if workflow.execute(): + result = True + if not result: + break + if not command_dispatcher.execute_pending(): break - if not command_dispatcher.execute_pending(): + except Exception as ex: + log.exception(ex) break - except Exception as ex: - log.exception(ex) - break - command_dispatcher.close() + command_dispatcher.close() + finally: + del task['token'] + result_msg = rabbitmq.Message() + result_msg.body = task + result_msg.id = message_id - del task['token'] - result_msg = rabbitmq.Message() - result_msg.body = task - result_msg.id = message_id - - rmqclient.send(message=result_msg, key='task-results') + rmqclient.send(message=result_msg, key='task-results') log.info('Finished processing task {0}. Result = {1}'.format( message_id, anyjson.dumps(task))) diff --git a/conductor/conductor/commands/cloud_formation.py b/conductor/conductor/commands/cloud_formation.py index c9b3666..eb0084b 100644 --- a/conductor/conductor/commands/cloud_formation.py +++ b/conductor/conductor/commands/cloud_formation.py @@ -1,6 +1,7 @@ import anyjson import eventlet +import jsonpath from conductor.openstack.common import log as logging import conductor.helpers from command import CommandBase @@ -20,13 +21,18 @@ class HeatExecutor(CommandBase): self._stack = 'e' + stack settings = conductor.config.CONF.heat - client = ksclient.Client(endpoint=settings.keystone) - scoped_token = client.tokens.authenticate( + client = ksclient.Client(endpoint=settings.auth_url) + auth_data = client.tokens.authenticate( tenant_id=tenant_id, - token=token).id + token=token) - self._heat_client = Client('1', settings.url, - token_only=True, token=scoped_token) + scoped_token = auth_data.id + + heat_url = jsonpath.jsonpath(auth_data.serviceCatalog, + "$[?(@.name == 'heat')].endpoints[0].publicURL")[0] + + self._heat_client = Client('1', heat_url, + token_only=True, token=scoped_token) def execute(self, command, callback, **kwargs): log.debug('Got command {0} on stack {1}'.format(command, self._stack)) diff --git a/conductor/conductor/config.py b/conductor/conductor/config.py index 1586918..a5caea7 100644 --- a/conductor/conductor/config.py +++ b/conductor/conductor/config.py @@ -46,8 +46,7 @@ rabbit_opts = [ ] heat_opts = [ - cfg.StrOpt('url'), - cfg.StrOpt('keystone') + cfg.StrOpt('auth_url'), ] CONF = cfg.CONF diff --git a/conductor/conductor/windows_agent.py b/conductor/conductor/windows_agent.py index e39fa37..e25b553 100644 --- a/conductor/conductor/windows_agent.py +++ b/conductor/conductor/windows_agent.py @@ -1,29 +1,29 @@ -import xml_code_engine - -from openstack.common import log as logging -log = logging.getLogger(__name__) - - -def send_command(engine, context, body, template, service, host, mappings=None, - result=None, **kwargs): - 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)) - if result is not None: - context[result] = result_value['Result'] - - success_handler = body.find('success') - if success_handler is not None: - engine.evaluate_content(success_handler, context) - - command_dispatcher.execute( - name='agent', template=template, mappings=mappings, - host=host, service=service, callback=callback) - - +import xml_code_engine + +from openstack.common import log as logging +log = logging.getLogger(__name__) + + +def send_command(engine, context, body, template, service, host, mappings=None, + result=None, **kwargs): + if not mappings: + mappings = {} + command_dispatcher = context['/commandDispatcher'] + + def callback(result_value): + log.info( + 'Received result from {2} for {0}: {1}'.format( + template, result_value, host)) + if result is not None: + context[result] = result_value['Result'] + + success_handler = body.find('success') + if success_handler is not None: + engine.evaluate_content(success_handler, context) + + command_dispatcher.execute( + name='agent', template=template, mappings=mappings, + host=host, service=service, callback=callback) + + xml_code_engine.XmlCodeEngine.register_function(send_command, "send-command") \ No newline at end of file diff --git a/conductor/data/workflows/AD.xml b/conductor/data/workflows/AD.xml index b350763..8ec809b 100644 --- a/conductor/data/workflows/AD.xml +++ b/conductor/data/workflows/AD.xml @@ -1,222 +1,222 @@ - - - - - Creating instance - - - - - - - - - keero-linux-keys - m1.medium - ws-2012-full - - - - - - Instance - - - - - - - - - - - - - - - - - - - Creating Primary Domain Controller on unit - - - - - - - - - - - - - - - - - - - - - - - - - /$.services.activeDirectories[?(@.domain == ' - - - - - - - - - - - - - - Unit - - - - - - - - - - - - - - - - - - - - - - - - - - - Domain + + + + + + + + + + + AD- + + + + + + created + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Primary Domain Controller created + + + + + + + + + + + + + + DNS IP = + + + ' and @.state.primaryDcIp)] + + + + + + + + + + + + + + + has joined domain + Creating Secondary Domain Controller on unit + + + + + + + Secondary Domain Controller created + + + created + + + + \ No newline at end of file diff --git a/conductor/data/workflows/IIS.xml b/conductor/data/workflows/IIS.xml index 8c4f8c5..9d2e52c 100644 --- a/conductor/data/workflows/IIS.xml +++ b/conductor/data/workflows/IIS.xml @@ -1,65 +1,65 @@ - - - - - Creating instance - - - - - - - - - keero-linux-keys - m1.medium - ws-2012-full - - - - - - Instance - Creating IIS Web Server on unit - - - - IIS + + + + + + + + + + + WS- + + + + + + created + + + + + + + + + + + + + + + + + has started + + + + \ No newline at end of file diff --git a/conductor/etc/conductor.conf b/conductor/etc/conductor.conf index 2b052ed..60f3202 100644 --- a/conductor/etc/conductor.conf +++ b/conductor/etc/conductor.conf @@ -4,8 +4,7 @@ debug=True verbose=True [heat] -url = http://172.18.124.101:8004/v1/16eb78cbb688459c8308d89678bcef50 -keystone = http://172.18.124.101:5000/v2.0 +auth_url = http://172.18.124.101:5000/v2.0 [rabbitmq] host = 172.18.124.101