Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

rackspace private network discovery #284

Merged
merged 1 commit into from

3 participants

@paulczar paulczar referenced this pull request
Closed

Rackspace networks #273

@sersut sersut merged commit 78fa9d0 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 27, 2014
  1. @arborlab
This page is out of date. Refresh to see the latest.
Showing with 95 additions and 6 deletions.
  1. +25 −0 lib/ohai/plugins/rackspace.rb
  2. +70 −6 spec/unit/plugins/rackspace_spec.rb
View
25 lib/ohai/plugins/rackspace.rb
@@ -93,6 +93,28 @@ def get_region()
Ohai::Log.debug("Unable to find xenstore-ls, cannot capture region information for Rackspace cloud")
end
+ # Get the rackspace private networks
+ #
+ def get_private_networks()
+ so = shell_out('xenstore-ls vm-data/networking')
+ if so.exitstatus == 0
+ networks = []
+ so.stdout.split("\n").map{|l| l.split('=').first.strip }.map do |item|
+ _so = shell_out("xenstore-read vm-data/networking/#{item}")
+ if _so.exitstatus == 0
+ networks.push(Yajl::Parser.new.parse(_so.stdout))
+ else
+ raise Ohai::Exceptions::Exec
+ end
+ end
+ # these networks are already known to ohai, and are not 'private networks'
+ networks.delete_if { |hash| hash['label'] == 'private' }
+ networks.delete_if { |hash| hash['label'] == 'public' }
+ end
+ rescue Ohai::Exceptions::Exec
+ Ohai::Log.debug('Unable to capture custom private networking information for Rackspace cloud')
+ end
+
collect_data do
# Adds rackspace Mash
if looks_like_rackspace?
@@ -109,6 +131,9 @@ def get_region()
rackspace[:local_ipv4] = rackspace[:private_ip]
get_global_ipv6_address(:local_ipv6, :eth1)
rackspace[:local_hostname] = hostname
+ private_networks = get_private_networks
+ rackspace[:private_networks] = private_networks if private_networks
end
end
+
end
View
76 spec/unit/plugins/rackspace_spec.rb
@@ -58,7 +58,7 @@
"40:40:F5:AB:28:36" => {
"family"=> "lladdr"
}
- }}
+ }}
# In olden days we could detect rackspace by a -rscloud suffix on the kernel
# This is here to make #has_rackspace_kernel? fail until we remove that check
@@ -133,7 +133,7 @@
describe 'with no public interfaces (empty eth0)' do
before do
# unset public (eth0) addresses
- @plugin[:network][:interfaces][:eth0]['addresses'] = {}
+ @plugin[:network][:interfaces][:eth0]['addresses'] = {}
end
it "should have all required attributes" do
@@ -149,7 +149,7 @@
@plugin[:rackspace][:local_ipv6].should be_nil
@plugin[:rackspace][:local_hostname].should_not be_nil
end
-
+
it "should have correct values for all attributes" do
@plugin.run
@plugin[:rackspace][:private_ip].should == "5.6.7.8"
@@ -161,16 +161,16 @@
describe "without cloud file" do
it_should_behave_like "!rackspace"
-
+
before(:each) do
File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
end
end
-
+
describe "with ec2 cloud file" do
it_should_behave_like "!rackspace"
-
+
before(:each) do
File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
@@ -199,4 +199,68 @@
@plugin.stub(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
end
end
+
+ describe "does not have private networks" do
+ before do
+ stdout = 'BC764E20422B = "{"label": "public"}"\n'
+ @plugin.stub(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
+ stdout = '{"label": "public", "broadcast": "9.10.11.255", "ips": [{"ip": "9.10.11.12", "netmask": "255.255.255.0", "enabled": "1", "gateway": null}], "mac": "BC:76:4E:20:42:2B", "dns": ["69.20.0.164", "69.20.0.196"], "gateway": null}'
+ @plugin.stub(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
+
+ File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
+ File.stub(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
+ File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
+ File.stub(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
+ end
+
+ it "should not have private_networks object" do
+ @plugin.run
+ @plugin[:rackspace][:private_networks].should == []
+ end
+ end
+
+ describe "has private networks" do
+ before do
+ @plugin[:network][:interfaces][:eth2] = {:addresses => {
+ "fe80::be76:4eff:fe20:422b" => {
+ "scope"=> "Link",
+ "prefixlen"=> "64",
+ "family"=> "inet6"
+ },
+ "9.10.11.12"=> {
+ "broadcast"=> "9.10.11.255",
+ "netmask"=> "255.255.255.0",
+ "family"=> "inet"
+ },
+ "BC:76:4E:20:42:2B" => {
+ "family"=> "lladdr"
+ }
+ }}
+ stdout = 'BC764E20422B = "{"label": "private-network"}"\n'
+ @plugin.stub(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
+ stdout = '{"label": "private-network", "broadcast": "9.10.11.255", "ips": [{"ip": "9.10.11.12", "netmask": "255.255.255.0", "enabled": "1", "gateway": null}], "mac": "BC:76:4E:20:42:2B", "dns": ["69.20.0.164", "69.20.0.196"], "gateway": null}'
+ @plugin.stub(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
+
+ File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
+ File.stub(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
+ File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
+ File.stub(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
+ end
+
+ it "should private_networks object" do
+ @plugin.run
+ @plugin[:rackspace][:private_networks].should_not be_nil
+ end
+
+ it "should have correct values for all attributes" do
+ @plugin.run
+ @plugin[:rackspace][:private_networks][0][:label].should == "private-network"
+ @plugin[:rackspace][:private_networks][0][:broadcast].should == "9.10.11.255"
+ @plugin[:rackspace][:private_networks][0][:mac].should == "BC:76:4E:20:42:2B"
+ end
+
+ end
+
+
+
end
Something went wrong with that request. Please try again.