diff --git a/heat/engine/clients/os/heat_plugin.py b/heat/engine/clients/os/heat_plugin.py index e2de270711..a9a7750671 100644 --- a/heat/engine/clients/os/heat_plugin.py +++ b/heat/engine/clients/os/heat_plugin.py @@ -12,6 +12,7 @@ # under the License. from oslo_config import cfg +import six from heatclient import client as hc from heatclient import exc @@ -96,3 +97,12 @@ class HeatClientPlugin(client_plugin.ClientPlugin): if config_url and config_url[-1] != "/": config_url += '/' return config_url + + def get_watch_server_url(self): + cfn_url = self.get_heat_cfn_url() + url_parts = cfn_url.split(':') + port_and_version = url_parts[-1].split('/') + port_and_version[0] = ( + six.text_type(cfg.CONF.heat_api_cloudwatch.bind_port)) + url_parts[-1] = '/'.join(port_and_version) + return ':'.join(url_parts) diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index a2e0ded8a2..bab6d9d084 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -372,11 +372,14 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers attachments.append((jsonutils.dumps(metadata), 'cfn-init-data', 'x-cfninitdata')) - attachments.append((cfg.CONF.heat_watch_server_url, - 'cfn-watch-server', 'x-cfninitdata')) + heat_client_plugin = self.context.clients.client_plugin('heat') + watch_url = cfg.CONF.heat_watch_server_url + if not watch_url: + watch_url = heat_client_plugin.get_watch_server_url() + + attachments.append((watch_url, 'cfn-watch-server', 'x-cfninitdata')) if is_cfntools: - heat_client_plugin = self.context.clients.client_plugin('heat') cfn_md_url = heat_client_plugin.get_cfn_metadata_server_url() attachments.append((cfn_md_url, 'cfn-metadata-server', 'x-cfninitdata')) @@ -384,7 +387,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers # Create a boto config which the cfntools on the host use to know # where the cfn and cw API's are to be accessed cfn_url = urlparse.urlparse(cfn_md_url) - cw_url = urlparse.urlparse(cfg.CONF.heat_watch_server_url) + cw_url = urlparse.urlparse(watch_url) is_secure = cfg.CONF.instance_connection_is_secure vcerts = cfg.CONF.instance_connection_https_validate_certificates boto_cfg = "\n".join(["[Boto]", diff --git a/heat/tests/clients/test_clients.py b/heat/tests/clients/test_clients.py index 9174569b7b..5ad5d33ea1 100644 --- a/heat/tests/clients/test_clients.py +++ b/heat/tests/clients/test_clients.py @@ -89,6 +89,10 @@ class ClientsTest(common.HeatTestCase): obj = self._client_cfn_url() self.assertEqual("http://0.0.0.0:8000/v1/", obj.get_heat_cfn_url()) + def test_clients_get_watch_server_url(self): + obj = self._client_cfn_url() + self.assertEqual("http://0.0.0.0:8003/v1/", obj.get_watch_server_url()) + def test_clients_get_heat_cfn_metadata_url(self): obj = self._client_cfn_url() self.assertEqual("http://0.0.0.0:8000/v1/",