From 997a2165e7d64d295de0b92d8261cde3fa5ac53f Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Thu, 25 Oct 2012 14:30:31 +0100 Subject: [PATCH] heat metadata : remove metadata_url logic Remove logic where the heat-metadata server registers a URL on startup with the engine. The instance metadata is now served via the CFN api, so we just have a config-file option specifying the URL of the CFN API. We don't want to preserve the "register on startup" logic, because we need the engine to have access to this information even if it is restarted independent of some other service (avoid reliance on services coming up in a particular order) Change-Id: I690170977227ec96451d2a2fd25f7e507370b604 Signed-off-by: Steven Hardy --- bin/heat-metadata | 21 --------------------- docs/GettingStarted.rst | 18 +++++++++++++++++- etc/heat/heat-engine.conf | 9 ++++++++- heat/engine/manager.py | 3 --- heat/engine/resources/instance.py | 8 ++++---- heat/engine/resources/resource.py | 11 ----------- heat/engine/resources/wait_condition.py | 4 +++- 7 files changed, 32 insertions(+), 42 deletions(-) diff --git a/bin/heat-metadata b/bin/heat-metadata index 6c6fe4d6e9..bb1ea63e4c 100755 --- a/bin/heat-metadata +++ b/bin/heat-metadata @@ -33,10 +33,8 @@ if os.path.exists(os.path.join(possible_topdir, 'heat', '__init__.py')): gettext.install('heat', unicode=1) -from heat.openstack.common import rpc from heat.common import config from heat.common import wsgi -from heat.common import context from heat.openstack.common import log as logging from heat.openstack.common import cfg @@ -44,24 +42,6 @@ from heat.openstack.common import cfg LOG = logging.getLogger('heat.metadata') -def send_address_to_engine(host, port): - con = context.get_admin_context() - timeout = 2 - while True: - try: - resp = rpc.call(con, 'engine', - {'method': 'metadata_register_address', - 'args': {'url': 'http://%s:%s' % (host, port)}}, - timeout=timeout) - except rpc.common.Timeout: - LOG.info('Could not connect to the engine, retrying...') - if timeout < 30: - timeout *= 2 - else: - LOG.info('registered the hostname and port with the engine.') - return - - if __name__ == '__main__': try: cfg.CONF(project='heat', prog='heat-metadata') @@ -73,7 +53,6 @@ if __name__ == '__main__': port = cfg.CONF.bind_port host = cfg.CONF.bind_host - send_address_to_engine(host, port) LOG.info(('Starting Heat Metadata on %s:%s') % (host, port)) server = wsgi.Server() server.start(app, cfg.CONF, default_port=port) diff --git a/docs/GettingStarted.rst b/docs/GettingStarted.rst index 3db719c1a8..4fb45d0e1a 100644 --- a/docs/GettingStarted.rst +++ b/docs/GettingStarted.rst @@ -183,6 +183,17 @@ Check that there is a ``F17-x86_64-cfntools`` JEOS in glance: ) $GLANCE_INDEX | grep -q "F17-x86_64-cfntools" +Update heat engine configuration file +------------------------------------- + +The heat engine configuration file should be updated with the address of the bridge device (demonetbr0), however this device is not created by nova-network until the first instance is launched, so we assume that $BRIDGE_IP is 10.0.0.1 if $SUBNET is 10.0.0.0/24 as in the instructions above: + +.. + BRIDGE_IP=`echo $SUBNET | awk -F'[./]' '{printf "%d.%d.%d.%d", $1, $2, $3, or($4, 1)}'` + +:: + sudo sed -i -e "/heat_metadata_server_url/ s/127\.0\.0\.1/${BRIDGE_IP}/" /etc/heat/heat-engine.conf + Launch the Heat services ------------------------ @@ -315,7 +326,12 @@ Open up port 8002 so that the guests can communicate with the heat-metadata serv :: sudo iptables -I INPUT -p tcp --dport 8002 -j ACCEPT -i demonetbr0 -Note the above rule will not persist across reboot, so you may wish to add it to /etc/sysconfig/iptables +Note Instance/resource metadata is actually now served via the cloudformation API, so it is necessary to also open up port 8000 so that the guests can communicate with the heat-api-cfn server: + +:: + sudo iptables -I INPUT -p tcp --dport 8000 -j ACCEPT -i demonetbr0 + +Note the above rules will not persist across reboot, so you may wish to add them to /etc/sysconfig/iptables Configure Heat Cloudwatch server -------------------------------- diff --git a/etc/heat/heat-engine.conf b/etc/heat/heat-engine.conf index 1a99585040..f7c2405cd9 100644 --- a/etc/heat/heat-engine.conf +++ b/etc/heat/heat-engine.conf @@ -14,7 +14,14 @@ bind_port = 8001 # Keystone role for heat template-defined users heat_stack_user_role = heat_stack_user -# Log to this file. Make sure the user running heat-engine has +# URL for instances to connect for metadata +# ie the IP of the bridge device connecting the +# instances with the host and the bind_port of +# the CFN API +# NOTE : change this from 127.0.0.1 !! +heat_metadata_server_url = http://127.0.0.1:8000 + +# Log to this file. Make sure the user running heat-api has # permissions to write to this file! log_file = /var/log/heat/engine.log diff --git a/heat/engine/manager.py b/heat/engine/manager.py index 9d16b3e215..a34f692de6 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -378,9 +378,6 @@ class EngineManager(manager.Manager): return [api.format_stack_resource(resource) for resource in stack if resource.id is not None] - def metadata_register_address(self, context, url): - cfg.CONF.heat_metadata_server_url = url - def metadata_list_stacks(self, context): """ Return the names of the stacks registered with Heat. diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index 865d154891..076d681456 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -25,6 +25,8 @@ import heat from heat.engine.resources import resource from heat.common import exception +from heat.openstack.common import cfg + from heat.openstack.common import log as logging logger = logging.getLogger('heat.engine.instance') @@ -176,10 +178,8 @@ class Instance(resource.Resource): attachments.append((json.dumps(self.metadata), 'cfn-init-data', 'x-cfninitdata')) - metadata_server = resource.Metadata.server() - if metadata_server is not None: - attachments.append((metadata_server, - 'cfn-metadata-server', 'x-cfninitdata')) + attachments.append((cfg.CONF.heat_metadata_server_url, + 'cfn-metadata-server', 'x-cfninitdata')) subparts = [make_subpart(*args) for args in attachments] mime_blob = MIMEMultipart(_subparts=subparts) diff --git a/heat/engine/resources/resource.py b/heat/engine/resources/resource.py index 7555f0a3ed..712f42b1ce 100644 --- a/heat/engine/resources/resource.py +++ b/heat/engine/resources/resource.py @@ -62,17 +62,6 @@ class Metadata(object): rs = db_api.resource_get(resource.stack.context, resource.id) rs.update_and_save({'rsrc_metadata': metadata}) - @staticmethod - def server(): - ''' - Get the address of the currently registered metadata server. Return - None if no server is registered. - ''' - try: - return cfg.CONF.heat_metadata_server_url - except AttributeError: - return None - class Resource(object): # Status strings diff --git a/heat/engine/resources/wait_condition.py b/heat/engine/resources/wait_condition.py index 13b541e1d9..66eba75f8f 100644 --- a/heat/engine/resources/wait_condition.py +++ b/heat/engine/resources/wait_condition.py @@ -20,6 +20,8 @@ from heat.engine.resources import resource from heat.openstack.common import log as logging +from heat.openstack.common import cfg + logger = logging.getLogger('heat.engine.wait_condition') @@ -38,7 +40,7 @@ class WaitConditionHandle(resource.Resource): def handle_create(self): self.instance_id = '%s/stacks/%s/resources/%s' % \ - (resource.Metadata.server(), + (cfg.CONF.heat_metadata_server_url, self.stack.id, self.name)