cookbook-openstack-common/recipes/set_endpoints_by_interface.rb
Chris Dearborn f6da45d11f Add ability to specify IP for service
The problem that this change addresses is that the address_for method
will not work correctly if there are multiple IP address associated
with the specified interface.

The approach to solving this problem and moving towards the overall
goal of having one place where service networking information is
stored is to convert address_for calls into endpoints, and add a
address() method to the endpoints interface for IP address resolution.

The address() method has the following behavior: if the
bind_interface of an endpoint is set, then the IP is looked up on
the interface.  Otherwise, the IP specified in the host attribute is
returned.  This allows the caller to choose either method of
determining what IP a service will be bound to.

This initial change switches both the openstack-ops-database and
openstack-ops-messaging cookbooks over to use endpoints instead of
address_for.  The other cookbooks will be switched over time.

blueprint increase-ip-binding-flexibility

Change-Id: I527e4e734f3c1eea9ac2567e0a90524d78ee867e
2014-03-06 08:38:41 -05:00

32 lines
1.1 KiB
Ruby

# encoding: UTF-8
#
# Cookbook Name:: openstack-common
# recipe:: set_endpoints_by_interface
#
# Copyright 2013, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
class ::Chef::Recipe # rubocop:disable Documentation
include ::Openstack
end
# iterate over the endpoints, look for bind_interface to set the host
node['openstack']['endpoints'].keys.each do |component|
unless node['openstack']['endpoints'][component]['bind_interface'].nil?
ip_address = address node['openstack']['endpoints'][component]
node.default['openstack']['endpoints'][component]['host'] = ip_address
end
end