ridley 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,30 +18,34 @@ module Ridley
18
18
  attribute :override, default: HashWithIndifferentAccess.new
19
19
  attribute :run_list, default: Array.new
20
20
 
21
- # @param [Hash] hash
22
- def automatic=(hash)
23
- super(HashWithIndifferentAccess.new(hash))
24
- end
21
+ alias_method :normal_attributes, :normal
22
+ alias_method :automatic_attributes, :automatic
23
+ alias_method :default_attributes, :default
24
+ alias_method :override_attributes, :override
25
25
 
26
26
  # @param [Hash] hash
27
27
  def normal=(hash)
28
28
  super(HashWithIndifferentAccess.new(hash))
29
29
  end
30
+ alias_method :normal_attributes=, :normal=
30
31
 
31
32
  # @param [Hash] hash
32
- def default=(hash)
33
+ def automatic=(hash)
33
34
  super(HashWithIndifferentAccess.new(hash))
34
35
  end
36
+ alias_method :automatic_attributes=, :automatic=
35
37
 
36
38
  # @param [Hash] hash
37
- def override=(hash)
39
+ def default=(hash)
38
40
  super(HashWithIndifferentAccess.new(hash))
39
41
  end
42
+ alias_method :default_attributes=, :default=
40
43
 
41
44
  # @param [Hash] hash
42
- def normal=(hash)
45
+ def override=(hash)
43
46
  super(HashWithIndifferentAccess.new(hash))
44
47
  end
48
+ alias_method :override_attributes=, :override=
45
49
 
46
50
  # Set a node level normal attribute given the dotted path representation of the Chef
47
51
  # attribute and value.
@@ -52,7 +56,7 @@ module Ridley
52
56
  # @example setting and saving a node level normal attribute
53
57
  #
54
58
  # obj = node.find("jwinsor-1")
55
- # obj.set_normal_attribute("my_app.billing.enabled", false)
59
+ # obj.set_attribute("my_app.billing.enabled", false)
56
60
  # obj.save
57
61
  #
58
62
  # @param [String] key
@@ -64,12 +68,69 @@ module Ridley
64
68
  self.normal = self.normal.deep_merge(attr_hash)
65
69
  end
66
70
 
71
+ # Returns the public hostname of the instantiated node. This hostname should be used for
72
+ # public communications to the node.
73
+ #
74
+ # @example
75
+ # node.public_hostname => "reset.riotgames.com"
76
+ #
77
+ # @return [String]
78
+ def public_hostname
79
+ self.cloud? ? self.automatic[:cloud][:public_hostname] : self.automatic[:fqdn]
80
+ end
81
+
82
+ # Returns the public IPv4 address of the instantiated node. This ip address should be
83
+ # used for public communications to the node.
84
+ #
85
+ # @example
86
+ # node.public_ipv4 => "10.33.33.1"
87
+ #
88
+ # @return [String]
89
+ def public_ipv4
90
+ self.cloud? ? self.automatic[:cloud][:public_ipv4] : self.automatic[:ipaddress]
91
+ end
92
+ alias_method :public_ipaddress, :public_ipv4
93
+
94
+ # Returns the cloud provider of the instantiated node. If the node is not identified as
95
+ # a cloud node, then nil is returned.
96
+ #
97
+ # @example
98
+ # node_1.cloud_provider => "eucalyptus"
99
+ # node_2.cloud_provider => "ec2"
100
+ # node_3.cloud_provider => "rackspace"
101
+ # node_4.cloud_provider => nil
102
+ #
103
+ # @return [nil, String]
104
+ def cloud_provider
105
+ self.cloud? ? self.automatic[:cloud][:provider] : nil
106
+ end
107
+
108
+ # Returns true if the node is identified as a cloud node.
109
+ #
110
+ # @return [Boolean]
111
+ def cloud?
112
+ self.automatic.has_key?(:cloud)
113
+ end
114
+
115
+ # Returns true if the node is identified as a cloud node using the eucalyptus provider.
116
+ #
117
+ # @return [Boolean]
67
118
  def eucalyptus?
68
- self.automatic.has_key?(:eucalyptus)
119
+ self.cloud_provider == "eucalyptus"
69
120
  end
70
121
 
122
+ # Returns true if the node is identified as a cloud node using the ec2 provider.
123
+ #
124
+ # @return [Boolean]
71
125
  def ec2?
72
- self.automatic.has_key?(:ec2)
126
+ self.cloud_provider == "ec2"
127
+ end
128
+
129
+ # Returns true if the node is identified as a cloud node using the rackspace provider.
130
+ #
131
+ # @return [Boolean]
132
+ def rackspace?
133
+ self.cloud_provider == "rackspace"
73
134
  end
74
135
  end
75
136
 
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -85,35 +85,164 @@ describe Ridley::Node do
85
85
  end
86
86
  end
87
87
 
88
+ describe "#cloud?" do
89
+ it "returns true if the cloud automatic attribute is set" do
90
+ subject.automatic = {
91
+ "cloud" => Hash.new
92
+ }
93
+
94
+ subject.cloud?.should be_true
95
+ end
96
+
97
+ it "returns false if the cloud automatic attribute is not set" do
98
+ subject.automatic.delete(:cloud)
99
+
100
+ subject.cloud?.should be_false
101
+ end
102
+ end
103
+
88
104
  describe "#eucalyptus?" do
89
- it "returns true if the eucalyptus automatic attribute is set" do
105
+ it "returns true if the node is a cloud node using the eucalyptus provider" do
90
106
  subject.automatic = {
91
- "eucalyptus" => Hash.new
107
+ "cloud" => {
108
+ "provider" => "eucalyptus"
109
+ }
92
110
  }
93
111
 
94
112
  subject.eucalyptus?.should be_true
95
113
  end
96
114
 
97
- it "returns false if the eucalyptus automatic attribute is not set" do
98
- subject.automatic.delete(:eucalyptus)
115
+ it "returns false if the node is not a cloud node" do
116
+ subject.automatic.delete(:cloud)
117
+
118
+ subject.eucalyptus?.should be_false
119
+ end
120
+
121
+ it "returns false if the node is a cloud node but not using the eucalyptus provider" do
122
+ subject.automatic = {
123
+ "cloud" => {
124
+ "provider" => "ec2"
125
+ }
126
+ }
99
127
 
100
128
  subject.eucalyptus?.should be_false
101
129
  end
102
130
  end
103
131
 
104
132
  describe "#ec2?" do
105
- it "returns true if the ec2 automatic attribute is set" do
133
+ it "returns true if the node is a cloud node using the ec2 provider" do
106
134
  subject.automatic = {
107
- "ec2" => Hash.new
135
+ "cloud" => {
136
+ "provider" => "ec2"
137
+ }
108
138
  }
109
139
 
110
140
  subject.ec2?.should be_true
111
141
  end
112
142
 
113
- it "returns false if the ec2 automatic attribute is not set" do
114
- subject.automatic.delete(:ec2)
143
+ it "returns false if the node is not a cloud node" do
144
+ subject.automatic.delete(:cloud)
145
+
146
+ subject.ec2?.should be_false
147
+ end
148
+
149
+ it "returns false if the node is a cloud node but not using the ec2 provider" do
150
+ subject.automatic = {
151
+ "cloud" => {
152
+ "provider" => "rackspace"
153
+ }
154
+ }
115
155
 
116
156
  subject.ec2?.should be_false
117
157
  end
118
158
  end
159
+
160
+ describe "#rackspace?" do
161
+ it "returns true if the node is a cloud node using the rackspace provider" do
162
+ subject.automatic = {
163
+ "cloud" => {
164
+ "provider" => "rackspace"
165
+ }
166
+ }
167
+
168
+ subject.rackspace?.should be_true
169
+ end
170
+
171
+ it "returns false if the node is not a cloud node" do
172
+ subject.automatic.delete(:cloud)
173
+
174
+ subject.rackspace?.should be_false
175
+ end
176
+
177
+ it "returns false if the node is a cloud node but not using the rackspace provider" do
178
+ subject.automatic = {
179
+ "cloud" => {
180
+ "provider" => "ec2"
181
+ }
182
+ }
183
+
184
+ subject.rackspace?.should be_false
185
+ end
186
+ end
187
+
188
+ describe "#cloud_provider" do
189
+ it "returns the cloud provider if the node is a cloud node" do
190
+ subject.automatic = {
191
+ "cloud" => {
192
+ "provider" => "ec2"
193
+ }
194
+ }
195
+
196
+ subject.cloud_provider.should eql("ec2")
197
+ end
198
+
199
+ it "returns nil if the node is not a cloud node" do
200
+ subject.automatic.delete(:cloud)
201
+
202
+ subject.cloud_provider.should be_nil
203
+ end
204
+ end
205
+
206
+ describe "#public_ipv4" do
207
+ it "returns the public ipv4 address if the node is a cloud node" do
208
+ subject.automatic = {
209
+ "cloud" => {
210
+ "provider" => "ec2",
211
+ "public_ipv4" => "10.0.0.1"
212
+ }
213
+ }
214
+
215
+ subject.public_ipv4.should eql("10.0.0.1")
216
+ end
217
+
218
+ it "returns the ipaddress if the node is not a cloud node" do
219
+ subject.automatic = {
220
+ "ipaddress" => "192.168.1.1"
221
+ }
222
+ subject.automatic.delete(:cloud)
223
+
224
+ subject.public_ipv4.should eql("192.168.1.1")
225
+ end
226
+ end
227
+
228
+ describe "#public_hostname" do
229
+ it "returns the public hostname if the node is a cloud node" do
230
+ subject.automatic = {
231
+ "cloud" => {
232
+ "public_hostname" => "reset.cloud.riotgames.com"
233
+ }
234
+ }
235
+
236
+ subject.public_hostname.should eql("reset.cloud.riotgames.com")
237
+ end
238
+
239
+ it "returns the FQDN if the node is not a cloud node" do
240
+ subject.automatic = {
241
+ "fqdn" => "reset.internal.riotgames.com"
242
+ }
243
+ subject.automatic.delete(:cloud)
244
+
245
+ subject.public_hostname.should eql("reset.internal.riotgames.com")
246
+ end
247
+ end
119
248
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-19 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chozo
@@ -450,7 +450,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
450
450
  version: '0'
451
451
  segments:
452
452
  - 0
453
- hash: 900476655936176139
453
+ hash: 2735262975561486812
454
454
  requirements: []
455
455
  rubyforge_project:
456
456
  rubygems_version: 1.8.23