From cad9d0fead222037c947479fdf4e053afb7a21e2 Mon Sep 17 00:00:00 2001 From: Feilong Wang Date: Fri, 6 Jul 2018 16:23:38 +1200 Subject: [PATCH] Add region support Now Heat is missing the region support for software deployment and so did os-collect-config. This patch fixes it but keeps the backward compatibility. For changes in Heat pls refer Iec6f3606c9fdf8474f393b0990356f34d38bcf75 and https://review.openstack.org/580470 For changes in Heat agents please refer I8e0518fa61e237ec055834dd4bebe0fc87cd6627 Story: 2002781 Change-Id: I88182a9a9af74e9760b2ec9b500971f06293f0b8 (cherry picked from commit 5bebbf1654f8eea8d74a4e403ac6bd3331a7fedf) --- os_collect_config/heat.py | 11 +++++++++-- os_collect_config/zaqar.py | 29 ++++++++++++++++++----------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/os_collect_config/heat.py b/os_collect_config/heat.py index 9161aca..f10d03b 100644 --- a/os_collect_config/heat.py +++ b/os_collect_config/heat.py @@ -37,6 +37,8 @@ opts = [ help='ID of the stack this deployment belongs to'), cfg.StrOpt('resource-name', help='Name of resource in the stack to be polled'), + cfg.StrOpt('region-name', + help='Region Name for extracting Heat endpoint'), ] name = 'heat' @@ -69,6 +71,8 @@ class Collector(object): if CONF.heat.resource_name is None: logger.info('No resource_name configured.') raise exc.HeatMetadataNotConfigured + # NOTE(flwang): To be compatible with old versions, we won't throw + # error here if there is no region name. try: ks = keystone.Keystone( @@ -78,8 +82,11 @@ class Collector(object): project_id=CONF.heat.project_id, keystoneclient=self.keystoneclient, discover_class=self.discover_class).client - endpoint = ks.service_catalog.url_for( - service_type='orchestration', endpoint_type='publicURL') + kwargs = {'service_type': 'orchestration', + 'endpoint_type': 'publicURL'} + if CONF.heat.region_name: + kwargs['region_name'] = CONF.heat.region_name + endpoint = ks.service_catalog.url_for(**kwargs) logger.debug('Fetching metadata from %s' % endpoint) heat = self.heatclient.Client( '1', endpoint, token=ks.auth_token) diff --git a/os_collect_config/zaqar.py b/os_collect_config/zaqar.py index 32f51a6..b05bf1e 100644 --- a/os_collect_config/zaqar.py +++ b/os_collect_config/zaqar.py @@ -43,6 +43,8 @@ opts = [ cfg.BoolOpt('use-websockets', default=False, help='Use the websocket transport to connect to Zaqar.'), + cfg.StrOpt('region-name', + help='Region Name for extracting Zaqar endpoint'), ] name = 'zaqar' @@ -59,23 +61,26 @@ class Collector(object): self.transport = transport def get_data_wsgi(self, ks, conf): + kwargs = {'service_type': 'messaging', 'endpoint_type': 'publicURL'} + if CONF.zaqar.region_name: + kwargs['region_name'] = CONF.zaqar.region_name + endpoint = ks.service_catalog.url_for(**kwargs) + logger.debug('Fetching metadata from %s' % endpoint) + zaqar = self.zaqarclient.Client(endpoint, conf=conf, version=1.1) - endpoint = ks.service_catalog.url_for( - service_type='messaging', endpoint_type='publicURL') - logger.debug('Fetching metadata from %s' % endpoint) - zaqar = self.zaqarclient.Client(endpoint, conf=conf, version=1.1) - - queue = zaqar.queue(CONF.zaqar.queue_id) - r = six.next(queue.pop()) - return r.body + queue = zaqar.queue(CONF.zaqar.queue_id) + r = six.next(queue.pop()) + return r.body def _create_req(self, endpoint, action, body): return request.Request(endpoint, action, content=json.dumps(body)) def get_data_websocket(self, ks, conf): - - endpoint = ks.service_catalog.url_for( - service_type='messaging-websocket', endpoint_type='publicURL') + kwargs = {'service_type': 'messaging-websocket', + 'endpoint_type': 'publicURL'} + if CONF.zaqar.region_name: + kwargs['region_name'] = CONF.zaqar.region_name + endpoint = ks.service_catalog.url_for(**kwargs) logger.debug('Fetching metadata from %s' % endpoint) @@ -129,6 +134,8 @@ class Collector(object): if CONF.zaqar.queue_id is None: logger.warn('No queue_id configured.') raise exc.ZaqarMetadataNotConfigured() + # NOTE(flwang): To be compatible with old versions, we won't throw + # error here if there is no region name. try: ks = keystone.Keystone(