From 23878ac32e8472bd28446eb9a664bbc0dfb04536 Mon Sep 17 00:00:00 2001 From: Alberto Murillo Date: Fri, 8 Jan 2016 12:08:41 -0600 Subject: [PATCH] Correctly find the current node ip based on the ips from answer file Templates that need the nodes ips where using util.get_ip() which returns the IP assosiated with the default gateway but might not be the desired IP in nodes with multiple nics. This change introduces util.find_my_ip_from_config() which a template that is expected to run on a compute node can use to identify which of the nodes ip does match with one from CONFIG_COMPUTE_HOSTS --- clearstack/common/util.py | 5 +++++ clearstack/modules/neutron.py | 4 ++-- clearstack/templates/neutron.py | 4 +++- clearstack/templates/neutron_compute.py | 4 +++- clearstack/templates/nova.py | 3 ++- clearstack/templates/nova_compute.py | 3 ++- clearstack/utils.py | 1 + 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/clearstack/common/util.py b/clearstack/common/util.py index 98b6194..ca1be02 100644 --- a/clearstack/common/util.py +++ b/clearstack/common/util.py @@ -190,6 +190,11 @@ def get_ip(): return netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr'] +def find_my_ip_from_config(config_ips): + ip = set(get_ips()) & set(config_ips) + return ip.pop() + + def is_localhost(host): return (host == "localhost" or host == socket.gethostname() or host in get_ips()) diff --git a/clearstack/modules/neutron.py b/clearstack/modules/neutron.py index dfe82c4..bd94c4b 100644 --- a/clearstack/modules/neutron.py +++ b/clearstack/modules/neutron.py @@ -83,13 +83,13 @@ class Neutron(OpenStackService): util.link_file('/etc/neutron/plugins/ml2/ml2_conf.ini', '/etc/neutron/plugin.ini') - def config_linux_bridge_agent(self): + def config_linux_bridge_agent(self, local_ip): config = \ "[linux_bridge]\n" + \ "physical_interface_mappings = %s\n" % bridge_mappings + \ "[vxlan]\n" + \ "enable_vxlan = True\n" + \ - "local_ip = %s\n" % util.get_ip() + \ + "local_ip = %s\n" % local_ip + \ "l2_population = True\n" + \ "[agent]\n" + \ "prevent_arp_spoofing = True\n" + \ diff --git a/clearstack/templates/neutron.py b/clearstack/templates/neutron.py index ad46a94..b418f6e 100644 --- a/clearstack/templates/neutron.py +++ b/clearstack/templates/neutron.py @@ -23,6 +23,8 @@ from common import util neutron = Neutron.get() config_file = "/etc/neutron/neutron.conf" +ip_list = CONF['CONFIG_CONTROLLER_HOST'].split(',') +local_ip = util.find_my_ip_from_config(ip_list) # Install neutron controller neutron.install() @@ -38,7 +40,7 @@ neutron.config_auth(config_file) neutron.config_nova(config_file) neutron.config_ml2_plugin() -neutron.config_linux_bridge_agent() +neutron.config_linux_bridge_agent(local_ip) neutron.config_l3_agent("/etc/neutron/l3_agent.ini") neutron.config_dhcp_agent("/etc/neutron/dhcp_agent.ini") neutron.config_metadata_agent("/etc/neutron/metadata_agent.ini") diff --git a/clearstack/templates/neutron_compute.py b/clearstack/templates/neutron_compute.py index a304514..ca14f5d 100644 --- a/clearstack/templates/neutron_compute.py +++ b/clearstack/templates/neutron_compute.py @@ -24,12 +24,14 @@ from common import util neutron = Neutron.get() config_file = "/etc/neutron/neutron.conf" services = ['nova-compute', 'neutron-linuxbridge-agent'] +ip_list = CONF['CONFIG_COMPUTE_HOSTS'].split(',') +local_ip = util.find_my_ip_from_config(ip_list) neutron.install() neutron.config_debug(config_file) neutron.config_rabbitmq(config_file) neutron.config_auth(config_file) -neutron.config_linux_bridge_agent() +neutron.config_linux_bridge_agent(local_ip) neutron.config_neutron_on_nova('/etc/nova/nova.conf') if util.str2bool(CONF['CONFIG_CEILOMETER_INSTALL']): diff --git a/clearstack/templates/nova.py b/clearstack/templates/nova.py index 3445e48..cdc98a9 100644 --- a/clearstack/templates/nova.py +++ b/clearstack/templates/nova.py @@ -23,7 +23,8 @@ from common import util nova = Nova.get() config_file = "/etc/nova/nova.conf" -my_ip = util.get_ip() +ip_list = CONF['CONFIG_CONTROLLER_HOST'].split(',') +my_ip = util.find_my_ip_from_config(ip_list) # Install nova controller nova.install() diff --git a/clearstack/templates/nova_compute.py b/clearstack/templates/nova_compute.py index a0ee5c6..1af52a1 100644 --- a/clearstack/templates/nova_compute.py +++ b/clearstack/templates/nova_compute.py @@ -28,7 +28,8 @@ from common import util nova = Nova.get() config_file = "/etc/nova/nova.conf" services = ['libvirtd.socket', 'nova-compute'] -my_ip = util.get_ip() +ip_list = CONF['CONFIG_COMPUTE_HOSTS'].split(',') +my_ip = util.find_my_ip_from_config(ip_list) if CONF['CONFIG_HTTP_SERVICE'] == 'nginx': services.extend(['nginx', 'uwsgi@nova-metadata.socket']) diff --git a/clearstack/utils.py b/clearstack/utils.py index 27e55d4..1790791 100644 --- a/clearstack/utils.py +++ b/clearstack/utils.py @@ -61,6 +61,7 @@ def run_recipe(recipe_file, recipe_src, hosts): _run_recipe_in_hosts(recipe_file, recipes_dir, hosts) return True + def _run_recipe_local(recipe_file): if recipe_file.endswith('.py'): util.run_command("python3 {0}".format(recipe_file))