rightscale-ohai 0.3.3.1 → 0.3.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,19 +17,42 @@
17
17
  provides "cloud"
18
18
 
19
19
  require_plugin "ec2"
20
+ require_plugin "rackspace"
20
21
 
22
+ #
23
+ # EC2
24
+ #
21
25
  def on_ec2?
22
26
  ec2 != nil
23
27
  end
24
28
 
25
29
  def get_ec2_values
26
- cloud[:instance_id] = ec2['instance_id']
30
+ cloud[:instance_uid] = ec2['instance_id']
27
31
  cloud[:public_ip] = ec2['public_ipv4']
28
32
  cloud[:private_ip] = ec2['local_ipv4']
29
33
  cloud[:provider] = "ec2"
30
34
  end
31
35
 
36
+ #
37
+ # rackspace
38
+ #
39
+ def on_rackspace?
40
+ rackspace != nil
41
+ end
42
+
43
+ def get_rackspace_values
44
+ cloud[:instance_uid] = rackspace['instance_uid']
45
+ cloud[:public_ip] = rackspace['public_ip']
46
+ cloud[:private_ip] = rackspace['private_ip']
47
+ cloud[:provider] = "rackspace"
48
+ end
49
+
32
50
  if on_ec2?
33
51
  cloud Mash.new
34
52
  get_ec2_values
35
53
  end
54
+
55
+ if on_rackspace?
56
+ cloud Mash.new
57
+ get_rackspace_values
58
+ end
@@ -13,21 +13,20 @@
13
13
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
+
17
+ require 'json'
16
18
 
17
19
  provides "rightscale"
18
-
19
- require_plugin "ec2"
20
20
 
21
-
22
- def on_rightscale_platform?
23
- return false if (ec2 == nil || ec2[:userdata].match(/RS_/) == nil) # only ec2 supported
24
- true
21
+ class RightScale
22
+ MetaDataFile = "/var/spool/rackspace/user-data.txt"
25
23
  end
26
24
 
27
25
  # this is a hack to convert the RS_<server> tokens into something more
28
26
  # intuative. Hopefully this will be removed when we stop using EC2
29
27
  # userdata.
30
28
  def add_server(key, data)
29
+ rightscale[:server] = Mash.new unless rightscale.has_key?(:server)
31
30
  server_names = {
32
31
  "RS_sketchy" => "sketchy",
33
32
  "RS_syslog" => "syslog",
@@ -37,9 +36,18 @@ def add_server(key, data)
37
36
  rightscale[:server][server_names[key]] = data unless (server_names[key] == nil)
38
37
  end
39
38
 
39
+ #
40
+ # EC2
41
+ #
42
+ require_plugin "ec2"
43
+
44
+ def on_rightscale_ec2_platform?
45
+ return false if (ec2 == nil || ec2[:userdata].match(/RS_/) == nil) # only ec2 supported
46
+ true
47
+ end
48
+
40
49
  # add all 'RS_' tokens in userdata, but perform translation for server names
41
- def get_data
42
- rightscale[:server] = Mash.new
50
+ def get_data_from_ec2_user_date
43
51
  data_array = ec2[:userdata].split('&')
44
52
  data_array.each do |d|
45
53
  key, data = d.split('=')
@@ -47,7 +55,39 @@ def get_data
47
55
  end
48
56
  end
49
57
 
58
+ if on_rightscale_ec2_platform?
59
+ rightscale Mash.new
60
+ get_data_from_ec2_user_date
61
+ end
62
+
63
+
64
+ #
65
+ # Generic cloud
66
+ #
67
+ def on_rightscale_platform?
68
+ File.exists?(RightScale::MetaDataFile)
69
+ end
70
+
71
+ # TODO: future
72
+ # def get_data_json
73
+ # file = File.open(RightScale::MetaDataFile)
74
+ # json = ""
75
+ # file.each { |line| json << line }
76
+ # data = JSON.parse(json)
77
+ # data["rightscale"].each { |key, data| rightscale[key] = data }
78
+ # end
79
+
80
+ def get_data
81
+ data_array = File.open(RightScale::MetaDataFile)
82
+ data_array.each do |d|
83
+ key, data = d.split('=')
84
+ key.strip!
85
+ data.strip!
86
+ rightscale[key.sub(/RS_/,'')] = data unless add_server(key,data)
87
+ end
88
+ end
89
+
50
90
  if on_rightscale_platform?
51
91
  rightscale Mash.new
52
- get_data
53
- end
92
+ get_data
93
+ end
@@ -40,7 +40,7 @@ describe Ohai::System, "plugin cloud" do
40
40
  @ohai[:ec2]['instance_id'] = "i-05714c6c"
41
41
  @ohai._require_plugin("cloud")
42
42
  @ohai[:cloud].should_not be_nil
43
- @ohai[:cloud][:instance_id].should == @ohai[:ec2]['instance_id']
43
+ @ohai[:cloud][:instance_uid].should == @ohai[:ec2]['instance_id']
44
44
  end
45
45
 
46
46
  it "should populate cloud public ip" do
@@ -61,4 +61,34 @@ describe Ohai::System, "plugin cloud" do
61
61
  end
62
62
  end
63
63
 
64
+ describe "with rackspace" do
65
+ before(:each) do
66
+ @ohai[:rackspace] = Mash.new()
67
+ end
68
+
69
+ it "should populate cloud id" do
70
+ @ohai[:rackspace]['instance_uid'] = "i-05714c6c"
71
+ @ohai._require_plugin("cloud")
72
+ @ohai[:cloud].should_not be_nil
73
+ @ohai[:cloud][:instance_uid].should == @ohai[:rackspace][:instance_uid]
74
+ end
75
+
76
+ it "should populate cloud public ip" do
77
+ @ohai[:rackspace]['public_ipv4'] = "174.129.150.8"
78
+ @ohai._require_plugin("cloud")
79
+ @ohai[:cloud][:public_ip].should == @ohai[:rackspace][:public_ip]
80
+ end
81
+
82
+ it "should populate cloud private ip" do
83
+ @ohai[:rackspace]['local_ipv4'] = "10.252.42.149"
84
+ @ohai._require_plugin("cloud")
85
+ @ohai[:cloud][:private_ip].should == @ohai[:rackspace][:private_ip]
86
+ end
87
+
88
+ it "should populate cloud provider" do
89
+ @ohai._require_plugin("cloud")
90
+ @ohai[:cloud][:provider].should == "rackspace"
91
+ end
92
+ end
93
+
64
94
  end
@@ -16,6 +16,7 @@
16
16
  #
17
17
 
18
18
  require File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb')
19
+ require 'flexmock'
19
20
 
20
21
  describe Ohai::System, "plugin rightscale" do
21
22
  before(:each) do
@@ -23,6 +24,9 @@ describe Ohai::System, "plugin rightscale" do
23
24
  @ohai.stub!(:require_plugin).and_return(true)
24
25
  end
25
26
 
27
+ #
28
+ # EC2 Cloud Support
29
+ #
26
30
  describe "ec2 with RightScale platform" do
27
31
  before(:each) do
28
32
  @ohai[:ec2] = Mash.new()
@@ -68,4 +72,81 @@ describe Ohai::System, "plugin rightscale" do
68
72
  end
69
73
  end
70
74
 
75
+ #
76
+ # Generic Cloud Support
77
+ #
78
+ describe "cloud without rightscale" do
79
+ before(:each) do
80
+ @ohai[:cloud] = Mash.new()
81
+ end
82
+
83
+ it "should NOT populate the rightscale data" do
84
+ @ohai._require_plugin("rightscale")
85
+ @ohai[:rightscale].should be_nil
86
+ end
87
+ end
88
+
89
+ describe "cloud with RightScale platform" do
90
+ before(:each) do
91
+ @ohai[:cloud] = Mash.new()
92
+ @ohai[:cloud][:provider] = "rackspace"
93
+ File.stub!(:exists?).and_return(true)
94
+ @mock_file = mock("datafile")
95
+ @mock_file.stub!(:each).
96
+ # json input file (future?)
97
+ #and_yield('{"rightscale":{"token":"8bd736d4a8de91b143bcebbb3e513f5f","server":{"syslog":"syslog.rightscale.com","sketchy":"sketchy1-11.rightscale.com","core":"my.rightscale.com","lumberjack":"lumberjack.rightscale.com"},"api_url":"https:\/\/my.rightscale.com\/api\/inst\/ec2_instances\/40e9d3956ad2e059f9f4054c6272ce2a38155273"}}')
98
+ and_yield('RS_syslog=syslog.rightscale.com').
99
+ and_yield('RS_sketchy=sketchy1-11.rightscale.com').
100
+ and_yield('RS_server=my.rightscale.com').
101
+ and_yield('RS_lumberjack=lumberjack.rightscale.com').
102
+ and_yield('RS_src=dobedobedo').
103
+ and_yield('RS_token=8bd736d4a8de91b143bcebbb3e513f5f').
104
+ and_yield('RS_api_url=https://my.rightscale.com/api/inst/ec2_instances/40e9d3956ad2e059f9f4054c6272ce2a38155273').
105
+ and_yield('RS_token_id=blabla').
106
+ and_yield('RS_amqp_url=yakityyakyak')
107
+ File.stub!(:open).and_return(@mock_file)
108
+ end
109
+
110
+ it "should create rightscale mash" do
111
+ @ohai._require_plugin("rightscale")
112
+ @ohai[:rightscale].should_not be_nil
113
+ end
114
+
115
+ it "should create rightscale server mash" do
116
+ @ohai._require_plugin("rightscale")
117
+ @ohai[:rightscale][:server].should_not be_nil
118
+ end
119
+
120
+ it "should populate sketchy server attribute" do
121
+ @ohai._require_plugin("rightscale")
122
+ @ohai[:rightscale][:server][:sketchy].should == "sketchy1-11.rightscale.com"
123
+ end
124
+
125
+ it "should populate core server attribute" do
126
+ @ohai._require_plugin("rightscale")
127
+ @ohai[:rightscale][:server][:core].should == "my.rightscale.com"
128
+ end
129
+
130
+ it "should populate syslog server attribute" do
131
+ @ohai._require_plugin("rightscale")
132
+ @ohai[:rightscale][:server][:syslog].should == "syslog.rightscale.com"
133
+ end
134
+
135
+ it "should populate lumberjack server attribute" do
136
+ @ohai._require_plugin("rightscale")
137
+ @ohai[:rightscale][:server][:lumberjack].should == "lumberjack.rightscale.com"
138
+ end
139
+
140
+ it "should populate token attribute" do
141
+ @ohai._require_plugin("rightscale")
142
+ @ohai[:rightscale][:token].should == "8bd736d4a8de91b143bcebbb3e513f5f"
143
+ end
144
+
145
+ it "should populate api_url attribute" do
146
+ @ohai._require_plugin("rightscale")
147
+ @ohai[:rightscale][:api_url].should == "https://my.rightscale.com/api/inst/ec2_instances/40e9d3956ad2e059f9f4054c6272ce2a38155273"
148
+ end
149
+
150
+ end
151
+
71
152
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightscale-ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3.1
4
+ version: 0.3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob