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 5bebbf1654)
This commit is contained in:
Feilong Wang 2018-07-06 16:23:38 +12:00
parent 08bb3bd58f
commit cad9d0fead
2 changed files with 27 additions and 13 deletions

View File

@ -37,6 +37,8 @@ opts = [
help='ID of the stack this deployment belongs to'), help='ID of the stack this deployment belongs to'),
cfg.StrOpt('resource-name', cfg.StrOpt('resource-name',
help='Name of resource in the stack to be polled'), help='Name of resource in the stack to be polled'),
cfg.StrOpt('region-name',
help='Region Name for extracting Heat endpoint'),
] ]
name = 'heat' name = 'heat'
@ -69,6 +71,8 @@ class Collector(object):
if CONF.heat.resource_name is None: if CONF.heat.resource_name is None:
logger.info('No resource_name configured.') logger.info('No resource_name configured.')
raise exc.HeatMetadataNotConfigured raise exc.HeatMetadataNotConfigured
# NOTE(flwang): To be compatible with old versions, we won't throw
# error here if there is no region name.
try: try:
ks = keystone.Keystone( ks = keystone.Keystone(
@ -78,8 +82,11 @@ class Collector(object):
project_id=CONF.heat.project_id, project_id=CONF.heat.project_id,
keystoneclient=self.keystoneclient, keystoneclient=self.keystoneclient,
discover_class=self.discover_class).client discover_class=self.discover_class).client
endpoint = ks.service_catalog.url_for( kwargs = {'service_type': 'orchestration',
service_type='orchestration', endpoint_type='publicURL') '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) logger.debug('Fetching metadata from %s' % endpoint)
heat = self.heatclient.Client( heat = self.heatclient.Client(
'1', endpoint, token=ks.auth_token) '1', endpoint, token=ks.auth_token)

View File

@ -43,6 +43,8 @@ opts = [
cfg.BoolOpt('use-websockets', cfg.BoolOpt('use-websockets',
default=False, default=False,
help='Use the websocket transport to connect to Zaqar.'), help='Use the websocket transport to connect to Zaqar.'),
cfg.StrOpt('region-name',
help='Region Name for extracting Zaqar endpoint'),
] ]
name = 'zaqar' name = 'zaqar'
@ -59,23 +61,26 @@ class Collector(object):
self.transport = transport self.transport = transport
def get_data_wsgi(self, ks, conf): 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( queue = zaqar.queue(CONF.zaqar.queue_id)
service_type='messaging', endpoint_type='publicURL') r = six.next(queue.pop())
logger.debug('Fetching metadata from %s' % endpoint) return r.body
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
def _create_req(self, endpoint, action, body): def _create_req(self, endpoint, action, body):
return request.Request(endpoint, action, content=json.dumps(body)) return request.Request(endpoint, action, content=json.dumps(body))
def get_data_websocket(self, ks, conf): def get_data_websocket(self, ks, conf):
kwargs = {'service_type': 'messaging-websocket',
endpoint = ks.service_catalog.url_for( 'endpoint_type': 'publicURL'}
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) logger.debug('Fetching metadata from %s' % endpoint)
@ -129,6 +134,8 @@ class Collector(object):
if CONF.zaqar.queue_id is None: if CONF.zaqar.queue_id is None:
logger.warn('No queue_id configured.') logger.warn('No queue_id configured.')
raise exc.ZaqarMetadataNotConfigured() raise exc.ZaqarMetadataNotConfigured()
# NOTE(flwang): To be compatible with old versions, we won't throw
# error here if there is no region name.
try: try:
ks = keystone.Keystone( ks = keystone.Keystone(