Browse Source

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
Feilong Wang 9 months ago
parent
commit
5bebbf1654
2 changed files with 27 additions and 13 deletions
  1. 9
    2
      os_collect_config/heat.py
  2. 18
    11
      os_collect_config/zaqar.py

+ 9
- 2
os_collect_config/heat.py View File

@@ -37,6 +37,8 @@ opts = [
37 37
                help='ID of the stack this deployment belongs to'),
38 38
     cfg.StrOpt('resource-name',
39 39
                help='Name of resource in the stack to be polled'),
40
+    cfg.StrOpt('region-name',
41
+               help='Region Name for extracting Heat endpoint'),
40 42
 ]
41 43
 name = 'heat'
42 44
 
@@ -69,6 +71,8 @@ class Collector(object):
69 71
         if CONF.heat.resource_name is None:
70 72
             logger.info('No resource_name configured.')
71 73
             raise exc.HeatMetadataNotConfigured
74
+        # NOTE(flwang): To be compatible with old versions, we won't throw
75
+        # error here if there is no region name.
72 76
 
73 77
         try:
74 78
             ks = keystone.Keystone(
@@ -78,8 +82,11 @@ class Collector(object):
78 82
                 project_id=CONF.heat.project_id,
79 83
                 keystoneclient=self.keystoneclient,
80 84
                 discover_class=self.discover_class).client
81
-            endpoint = ks.service_catalog.url_for(
82
-                service_type='orchestration', endpoint_type='publicURL')
85
+            kwargs = {'service_type': 'orchestration',
86
+                      'endpoint_type': 'publicURL'}
87
+            if CONF.heat.region_name:
88
+                kwargs['region_name'] = CONF.heat.region_name
89
+            endpoint = ks.service_catalog.url_for(**kwargs)
83 90
             logger.debug('Fetching metadata from %s' % endpoint)
84 91
             heat = self.heatclient.Client(
85 92
                 '1', endpoint, token=ks.auth_token)

+ 18
- 11
os_collect_config/zaqar.py View File

@@ -43,6 +43,8 @@ opts = [
43 43
     cfg.BoolOpt('use-websockets',
44 44
                 default=False,
45 45
                 help='Use the websocket transport to connect to Zaqar.'),
46
+    cfg.StrOpt('region-name',
47
+               help='Region Name for extracting Zaqar endpoint'),
46 48
 ]
47 49
 name = 'zaqar'
48 50
 
@@ -59,23 +61,26 @@ class Collector(object):
59 61
         self.transport = transport
60 62
 
61 63
     def get_data_wsgi(self, ks, conf):
64
+        kwargs = {'service_type': 'messaging', 'endpoint_type': 'publicURL'}
65
+        if CONF.zaqar.region_name:
66
+            kwargs['region_name'] = CONF.zaqar.region_name
67
+        endpoint = ks.service_catalog.url_for(**kwargs)
68
+        logger.debug('Fetching metadata from %s' % endpoint)
69
+        zaqar = self.zaqarclient.Client(endpoint, conf=conf, version=1.1)
62 70
 
63
-            endpoint = ks.service_catalog.url_for(
64
-                service_type='messaging', endpoint_type='publicURL')
65
-            logger.debug('Fetching metadata from %s' % endpoint)
66
-            zaqar = self.zaqarclient.Client(endpoint, conf=conf, version=1.1)
67
-
68
-            queue = zaqar.queue(CONF.zaqar.queue_id)
69
-            r = six.next(queue.pop())
70
-            return r.body
71
+        queue = zaqar.queue(CONF.zaqar.queue_id)
72
+        r = six.next(queue.pop())
73
+        return r.body
71 74
 
72 75
     def _create_req(self, endpoint, action, body):
73 76
         return request.Request(endpoint, action, content=json.dumps(body))
74 77
 
75 78
     def get_data_websocket(self, ks, conf):
76
-
77
-        endpoint = ks.service_catalog.url_for(
78
-            service_type='messaging-websocket', endpoint_type='publicURL')
79
+        kwargs = {'service_type': 'messaging-websocket',
80
+                  'endpoint_type': 'publicURL'}
81
+        if CONF.zaqar.region_name:
82
+            kwargs['region_name'] = CONF.zaqar.region_name
83
+        endpoint = ks.service_catalog.url_for(**kwargs)
79 84
 
80 85
         logger.debug('Fetching metadata from %s' % endpoint)
81 86
 
@@ -129,6 +134,8 @@ class Collector(object):
129 134
         if CONF.zaqar.queue_id is None:
130 135
             logger.warn('No queue_id configured.')
131 136
             raise exc.ZaqarMetadataNotConfigured()
137
+        # NOTE(flwang): To be compatible with old versions, we won't throw
138
+        # error here if there is no region name.
132 139
 
133 140
         try:
134 141
             ks = keystone.Keystone(

Loading…
Cancel
Save