From 14a75b84c46b0be5fe556503cea401019d1b355b Mon Sep 17 00:00:00 2001 From: mattray Date: Fri, 27 Jul 2012 14:43:52 -0500 Subject: [PATCH] synced to osops-utils 1.0.3 from rcbops --- cookbooks/osops-utils/README.md | 13 ++++ .../osops-utils/libraries/ip_location.rb | 63 ++++++++++++++----- cookbooks/osops-utils/metadata.rb | 2 +- cookbooks/osops-utils/recipes/default.rb | 2 +- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/cookbooks/osops-utils/README.md b/cookbooks/osops-utils/README.md index 4eb271b..2485f4c 100644 --- a/cookbooks/osops-utils/README.md +++ b/cookbooks/osops-utils/README.md @@ -4,6 +4,7 @@ Description Miscellaneous library functions for OpenStack. This currently includes: * ip address location + * simple /etc/hosts manipulation Requirements ============ @@ -26,6 +27,18 @@ ip = get_ip_for_net("localnet") # returns 127.0.0.1 ip = get_ip_for_net("management") # returns the address on management, or error +autoetchosts + +Attributes +========== + +none + +Usage +===== + +include_recipe "osops::autoetchosts" + License and Author ================== diff --git a/cookbooks/osops-utils/libraries/ip_location.rb b/cookbooks/osops-utils/libraries/ip_location.rb index ed1c0a1..1f8ffd7 100644 --- a/cookbooks/osops-utils/libraries/ip_location.rb +++ b/cookbooks/osops-utils/libraries/ip_location.rb @@ -1,5 +1,24 @@ #!/usr/bin/env ruby +# +# Cookbook Name:: osops-utils +# library:: ip_location +# +# Copyright 2012, Rackspace Hosting, 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. +# + require "chef/search/query" require "ipaddr" require "uri" @@ -92,15 +111,15 @@ module RCB raise error end - def get_bind_endpoint(server, service, nodeish=nil) + def get_config_endpoint(server, service, nodeish=nil, partial = false) retval = {} nodeish = node unless nodeish - if svc = rcb_safe_deref(nodeish, "#{server}.services.#{service}") + retval["network"] = svc["network"] retval["path"] = svc["path"] || "/" retval["scheme"] = svc["scheme"] || "http" retval["port"] = svc["port"] || "80" - + # if we have an endpoint, we'll just parse the pieces if svc.has_key?("uri") uri = URI(svc["uri"]) @@ -111,13 +130,23 @@ module RCB retval["host"] = svc["host"] retval["uri"] = "#{retval['scheme']}://#{retval['host']}:#{retval['port']}" retval["uri"] += retval["path"] - else - # we'll get the network from the osops network - retval["host"] = Chef::Recipe::IPManagement.get_ip_for_net(svc["network"], nodeish) - retval["uri"] = "#{retval['scheme']}://#{retval['host']}:#{retval['port']}" - retval["uri"] += retval["path"] end + else + Chef::Log.info("No configured endpoint for #{server}/#{service}") + retval = nil unless partial + end + retval + end + + def get_bind_endpoint(server, service, nodeish=nil) + nodeish = node unless nodeish + retval = get_config_endpoint(server, service, nodeish, partial=true) + if not retval.empty? + # we'll get the network from the osops network + retval["host"] = Chef::Recipe::IPManagement.get_ip_for_net(retval["network"], nodeish) + retval["uri"] = "#{retval['scheme']}://#{retval['host']}:#{retval['port']}" + retval["uri"] += retval["path"] retval else Chef::Log.warn("Cannot find server/service #{server}/#{service}") @@ -224,7 +253,11 @@ module RCB end def get_lb_endpoint(server, service) - rcb_exit_error("LB endpoints not yet defined") + if retval = get_config_endpoint(server,service) + retval + else + rcb_exit_error("No valid explicit configuration found for #{server}/#{service}") + end end end @@ -258,11 +291,13 @@ class Chef::Recipe::IPManagement net = IPAddr.new(node["osops_networks"][network]) node["network"]["interfaces"].each do |interface| - interface[1]["addresses"].each do |k,v| - if v["family"] == "inet6" or v["family"] == "inet" then - addr=IPAddr.new(k) - if net.include?(addr) then - return k + if interface[1].has_key?("addresses") then + interface[1]["addresses"].each do |k,v| + if v["family"] == "inet6" or v["family"] == "inet" then + addr=IPAddr.new(k) + if net.include?(addr) then + return k + end end end end diff --git a/cookbooks/osops-utils/metadata.rb b/cookbooks/osops-utils/metadata.rb index 5ef12f4..7853560 100644 --- a/cookbooks/osops-utils/metadata.rb +++ b/cookbooks/osops-utils/metadata.rb @@ -3,4 +3,4 @@ maintainer_email "osops@lists.launchpad.net" license "Apache 2.0" description "Installs/Configures osops-utils" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "1.0.2" +version "1.0.3" diff --git a/cookbooks/osops-utils/recipes/default.rb b/cookbooks/osops-utils/recipes/default.rb index 2607a73..5b3c5f2 100644 --- a/cookbooks/osops-utils/recipes/default.rb +++ b/cookbooks/osops-utils/recipes/default.rb @@ -2,7 +2,7 @@ # Cookbook Name:: osops-utils # Recipe:: default # -# Copyright 2012, Rackspace Hosting +# Copyright 2012, Rackspace Hosting, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.