rubix 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -38,7 +38,7 @@ module Rubix
|
|
38
38
|
# script.
|
39
39
|
class ClusterMonitor < ChefMonitor
|
40
40
|
|
41
|
-
attr_reader :private_ips_by_cluster, :nodes_by_cluster
|
41
|
+
attr_reader :all_private_ips_by_cluster, :private_ips_by_cluster, :all_nodes_by_cluster, :nodes_by_cluster
|
42
42
|
|
43
43
|
def initialize settings
|
44
44
|
super(settings)
|
@@ -54,14 +54,23 @@ module Rubix
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def group_nodes_by_cluster
|
57
|
-
@
|
58
|
-
@
|
57
|
+
@all_private_ips_by_cluster = {}
|
58
|
+
@private_ips_by_cluster = {}
|
59
|
+
@all_nodes_by_cluster = {}
|
60
|
+
@nodes_by_cluster = {}
|
59
61
|
matching_chef_nodes.first.each do |node|
|
60
|
-
@
|
61
|
-
@nodes_by_cluster[node['cluster_name']]
|
62
|
+
@all_nodes_by_cluster[node['cluster_name']] ||= []
|
63
|
+
@nodes_by_cluster[node['cluster_name']] ||= []
|
62
64
|
|
63
|
-
@
|
64
|
-
@
|
65
|
+
@all_nodes_by_cluster[node['cluster_name']] << node
|
66
|
+
@nodes_by_cluster[node['cluster_name']] << node unless %w[stopped].include?(node['state'])
|
67
|
+
|
68
|
+
|
69
|
+
@all_private_ips_by_cluster[node['cluster_name']] ||= []
|
70
|
+
@private_ips_by_cluster[node['cluster_name']] ||= []
|
71
|
+
|
72
|
+
@all_private_ips_by_cluster[node['cluster_name']] << node['ipaddress']
|
73
|
+
@private_ips_by_cluster[node['cluster_name']] << node['ipaddress'] unless %w[stopped].include?(node['state'])
|
65
74
|
end
|
66
75
|
end
|
67
76
|
|
@@ -2,9 +2,33 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Rubix::ClusterMonitor do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
def mock_chef_query nodes
|
6
|
+
query = mock("Chef::Search::Query")
|
7
|
+
require 'chef'
|
8
|
+
::Chef::Search::Query.should_receive(:new).and_return(query)
|
9
|
+
query.should_receive(:search).and_return([nodes, nodes.size])
|
7
10
|
end
|
8
11
|
|
12
|
+
it "should correctly carve up a group of nodes into clusters" do
|
13
|
+
mock_chef_query([
|
14
|
+
{ 'cluster_name' => 'foo', 'state' => 'started', 'ipaddress' => '123' },
|
15
|
+
{ 'cluster_name' => 'foo', 'state' => 'stopped', 'ipaddress' => '456' },
|
16
|
+
{ 'cluster_name' => 'bar', 'state' => 'started', 'ipaddress' => '789' },
|
17
|
+
{ 'cluster_name' => 'bar', 'state' => 'stopped', 'ipaddress' => '321' }
|
18
|
+
])
|
19
|
+
cm = Rubix::ClusterMonitor.new({})
|
20
|
+
cm.clusters.should include('foo', 'bar')
|
21
|
+
cm.private_ips_by_cluster.should == { 'foo' => ['123'], 'bar' => ['789'] }
|
22
|
+
cm.all_private_ips_by_cluster.should == { 'foo' => ['123', '456'], 'bar' => ['789', '321'] }
|
23
|
+
|
24
|
+
cm.nodes_by_cluster['foo'].size.should == 1
|
25
|
+
cm.nodes_by_cluster['bar'].size.should == 1
|
26
|
+
|
27
|
+
cm.all_nodes_by_cluster['foo'].size.should == 2
|
28
|
+
cm.all_nodes_by_cluster['bar'].size.should == 2
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
9
33
|
end
|
10
34
|
|