rubix 0.0.1 → 0.0.2
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 +1 -1
- data/lib/rubix.rb +9 -16
- data/lib/rubix/associations.rb +14 -0
- data/lib/rubix/associations/belongs_to_host.rb +32 -0
- data/lib/rubix/associations/has_many_applications.rb +32 -0
- data/lib/rubix/associations/has_many_host_groups.rb +37 -0
- data/lib/rubix/associations/has_many_hosts.rb +32 -0
- data/lib/rubix/associations/has_many_templates.rb +37 -0
- data/lib/rubix/associations/has_many_user_macros.rb +37 -0
- data/lib/rubix/log.rb +31 -18
- data/lib/rubix/models.rb +9 -0
- data/lib/rubix/models/application.rb +44 -50
- data/lib/rubix/models/host.rb +70 -74
- data/lib/rubix/models/host_group.rb +40 -51
- data/lib/rubix/models/item.rb +80 -69
- data/lib/rubix/models/model.rb +126 -0
- data/lib/rubix/models/template.rb +57 -55
- data/lib/rubix/models/user_macro.rb +84 -0
- data/lib/rubix/monitors.rb +5 -0
- data/lib/rubix/{monitor.rb → monitors/monitor.rb} +0 -0
- data/spec/requests/application_request_spec.rb +45 -0
- data/spec/requests/host_group_request_spec.rb +23 -0
- data/spec/requests/host_request_spec.rb +70 -0
- data/spec/requests/item_request_spec.rb +68 -0
- data/spec/requests/template_request_spec.rb +52 -0
- data/spec/requests/user_macro_request_spec.rb +36 -0
- data/spec/rubix/{monitor_spec.rb → monitors/monitor_spec.rb} +0 -0
- data/spec/spec_helper.rb +16 -1
- data/spec/support/integration_helper.rb +9 -0
- data/spec/test.yml +5 -0
- metadata +25 -8
- data/lib/rubix/model.rb +0 -56
- data/spec/rubix/models/host_group_spec.rb +0 -56
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "CRUD for items" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@hg1 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1')
|
7
|
+
@hg1.save
|
8
|
+
|
9
|
+
@h1 = Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@hg1])
|
10
|
+
@h1.save
|
11
|
+
|
12
|
+
@h2 = Rubix::Host.new(:name => 'rubix_spec_host_2', :host_groups => [@hg1])
|
13
|
+
@h2.save
|
14
|
+
|
15
|
+
@a1 = Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @h1.id)
|
16
|
+
@a1.save
|
17
|
+
|
18
|
+
@a2 = Rubix::Application.new(:name => 'rubix_spec_app_1', :host_id => @h2.id)
|
19
|
+
@a2.save
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
@a1.destroy
|
25
|
+
@a2.destroy
|
26
|
+
@h1.destroy
|
27
|
+
@h2.destroy
|
28
|
+
@hg1.destroy
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be able to create, update, and destroy an item" do
|
32
|
+
integration_test
|
33
|
+
|
34
|
+
Rubix::Item.find(:key => 'rubix.spec1', :host_id => @h1.id).should be_nil
|
35
|
+
|
36
|
+
item = Rubix::Item.new(:key => 'rubix.spec1', :description => 'rubix item description 1', :host_id => @h1.id, :value_type => :character, :applications => [@a1])
|
37
|
+
item.save
|
38
|
+
|
39
|
+
new_i = Rubix::Item.find(:key => 'rubix.spec1', :host_id => @h1.id)
|
40
|
+
new_i.should_not be_nil
|
41
|
+
new_i.host.name.should == @h1.name
|
42
|
+
new_i.key.should == 'rubix.spec1'
|
43
|
+
new_i.description.should == 'rubix item description 1'
|
44
|
+
new_i.value_type.should == :character
|
45
|
+
new_i.application_ids.should include(@a1.id)
|
46
|
+
|
47
|
+
id = item.id
|
48
|
+
id.should_not be_nil
|
49
|
+
|
50
|
+
item.key = 'rubix.spec2'
|
51
|
+
item.description = 'rubix item description 2'
|
52
|
+
item.value_type = :unsigned_int
|
53
|
+
item.host_id = @h2.id
|
54
|
+
item.applications = [@a2]
|
55
|
+
item.update
|
56
|
+
|
57
|
+
new_i = Rubix::Item.find(:key => 'rubix.spec2', :host_id => @h2.id)
|
58
|
+
new_i.should_not be_nil
|
59
|
+
new_i.host.name.should == @h2.name
|
60
|
+
new_i.key.should == 'rubix.spec2'
|
61
|
+
new_i.description.should == 'rubix item description 2'
|
62
|
+
new_i.value_type.should == :unsigned_int
|
63
|
+
new_i.application_ids.should include(@a2.id)
|
64
|
+
|
65
|
+
item.destroy
|
66
|
+
Rubix::Item.find(:id => id, :host_id => @h1.id).should be_nil
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "CRUD for templates" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@hg1 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1')
|
7
|
+
@hg1.save
|
8
|
+
|
9
|
+
@hg2 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_2')
|
10
|
+
@hg2.save
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
@hg1.destroy
|
16
|
+
@hg2.destroy
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be able to create, update, and destroy a template" do
|
20
|
+
integration_test
|
21
|
+
|
22
|
+
Rubix::Template.find(:name => 'rubix_spec_template_1').should be_nil
|
23
|
+
|
24
|
+
t = Rubix::Template.new(:name => 'rubix_spec_template_1', :host_groups => [@hg1])
|
25
|
+
t.save
|
26
|
+
|
27
|
+
new_t = Rubix::Template.find(:name => 'rubix_spec_template_1')
|
28
|
+
new_t.should_not be_nil
|
29
|
+
new_t.id.should == t.id
|
30
|
+
new_t.host_group_ids.should include(@hg1.id)
|
31
|
+
id = t.id
|
32
|
+
id.should_not be_nil
|
33
|
+
|
34
|
+
t.name = 'rubix_spec_template_2'
|
35
|
+
t.host_groups = [@hg2]
|
36
|
+
t.update
|
37
|
+
|
38
|
+
new_t = Rubix::Template.find(:id => id)
|
39
|
+
new_t.name.should == 'rubix_spec_template_2'
|
40
|
+
new_t.host_group_ids.should_not include(@hg1.id)
|
41
|
+
new_t.host_group_ids.should include(@hg2.id)
|
42
|
+
|
43
|
+
t.destroy
|
44
|
+
Rubix::Template.find(:id => id).should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be able to import and export a template" do
|
48
|
+
integration_test
|
49
|
+
pending "Learning how to import/export XML via the API"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "CRUD for user macros" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@hg1 = Rubix::HostGroup.new(:name => 'rubix_spec_host_group_1')
|
7
|
+
@hg1.save
|
8
|
+
|
9
|
+
@h1 = Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@hg1])
|
10
|
+
@h1.save
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
@h1.destroy
|
15
|
+
@hg1.destroy
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to create, update, and destroy a host" do
|
19
|
+
integration_test
|
20
|
+
|
21
|
+
Rubix::UserMacro.find(:name => 'rubix_spec_macro_1', :host_id => @h1.id).should be_nil
|
22
|
+
|
23
|
+
um = Rubix::UserMacro.new(:name => 'rubix_spec_macro_1', :value => 'rubix_spec_value_1', :host_id => @h1.id)
|
24
|
+
um.save
|
25
|
+
Rubix::UserMacro.find(:name => 'rubix_spec_macro_1', :host_id => @h1.id).should_not be_nil
|
26
|
+
id = um.id
|
27
|
+
id.should_not be_nil
|
28
|
+
|
29
|
+
um.value = 'rubix_spec_value_2'
|
30
|
+
um.update
|
31
|
+
Rubix::UserMacro.find(:name => 'rubix_spec_macro_1', :host_id => @h1.id).value.should == 'rubix_spec_value_2'
|
32
|
+
|
33
|
+
um.destroy
|
34
|
+
Rubix::UserMacro.find(:name => 'rubix_spec_macro_2', :host_id => @h1.id).should be_nil
|
35
|
+
end
|
36
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -4,11 +4,26 @@ RUBIX_ROOT = File.expand_path(__FILE__, '../../lib')
|
|
4
4
|
$: << RUBIX_ROOT unless $:.include?(RUBIX_ROOT)
|
5
5
|
require 'rubix'
|
6
6
|
|
7
|
-
Rubix.logger = false
|
7
|
+
Rubix.logger = false unless ENV["RUBIX_LOG_LEVEL"] || ENV["RUBIX_LOG_PATH"]
|
8
8
|
|
9
9
|
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |path| require path }
|
10
10
|
|
11
11
|
RSpec.configure do |config|
|
12
12
|
config.mock_with :rspec
|
13
13
|
config.include Rubix::ResponseSpecs
|
14
|
+
config.include Rubix::IntegrationHelper
|
15
|
+
|
16
|
+
test_yml_path = File.expand_path('../test.yml', __FILE__)
|
17
|
+
if File.exist?(test_yml_path)
|
18
|
+
require 'yaml'
|
19
|
+
test_data = YAML.load(open(test_yml_path))
|
20
|
+
if test_data['disable_integration_tests']
|
21
|
+
$RUBIX_INTEGRATION_TEST = false
|
22
|
+
else
|
23
|
+
Rubix.connect(test_data['url'], test_data['username'], test_data['password'])
|
24
|
+
$RUBIX_INTEGRATION_TEST = true
|
25
|
+
end
|
26
|
+
else
|
27
|
+
$RUBIX_INTEGRATION_TEST = false
|
28
|
+
end
|
14
29
|
end
|
data/spec/test.yml
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dhruv Bansal
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-21 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -76,29 +76,46 @@ files:
|
|
76
76
|
- bin/zabbix_pipe
|
77
77
|
- lib/rubix.rb
|
78
78
|
- lib/rubix/models/template.rb
|
79
|
+
- lib/rubix/models/user_macro.rb
|
79
80
|
- lib/rubix/models/item.rb
|
80
81
|
- lib/rubix/models/host.rb
|
81
82
|
- lib/rubix/models/host_group.rb
|
83
|
+
- lib/rubix/models/model.rb
|
82
84
|
- lib/rubix/models/application.rb
|
83
85
|
- lib/rubix/examples/es_monitor.rb
|
84
86
|
- lib/rubix/examples/mongo_monitor.rb
|
85
87
|
- lib/rubix/examples/hbase_monitor.rb
|
86
88
|
- lib/rubix/sender.rb
|
87
89
|
- lib/rubix/log.rb
|
90
|
+
- lib/rubix/models.rb
|
91
|
+
- lib/rubix/monitors.rb
|
88
92
|
- lib/rubix/response.rb
|
89
|
-
- lib/rubix/
|
90
|
-
- lib/rubix/
|
93
|
+
- lib/rubix/associations/has_many_hosts.rb
|
94
|
+
- lib/rubix/associations/has_many_applications.rb
|
95
|
+
- lib/rubix/associations/has_many_host_groups.rb
|
96
|
+
- lib/rubix/associations/belongs_to_host.rb
|
97
|
+
- lib/rubix/associations/has_many_templates.rb
|
98
|
+
- lib/rubix/associations/has_many_user_macros.rb
|
91
99
|
- lib/rubix/monitors/chef_monitor.rb
|
92
100
|
- lib/rubix/monitors/cluster_monitor.rb
|
101
|
+
- lib/rubix/monitors/monitor.rb
|
93
102
|
- lib/rubix/connection.rb
|
94
|
-
-
|
95
|
-
- spec/
|
103
|
+
- lib/rubix/associations.rb
|
104
|
+
- spec/test.yml
|
105
|
+
- spec/rubix/monitors/monitor_spec.rb
|
96
106
|
- spec/rubix/monitors/chef_monitor_spec.rb
|
97
107
|
- spec/rubix/monitors/cluster_monitor_spec.rb
|
98
108
|
- spec/rubix/response_spec.rb
|
99
109
|
- spec/rubix/sender_spec.rb
|
100
110
|
- spec/rubix/connection_spec.rb
|
111
|
+
- spec/requests/item_request_spec.rb
|
112
|
+
- spec/requests/host_group_request_spec.rb
|
113
|
+
- spec/requests/user_macro_request_spec.rb
|
114
|
+
- spec/requests/template_request_spec.rb
|
115
|
+
- spec/requests/host_request_spec.rb
|
116
|
+
- spec/requests/application_request_spec.rb
|
101
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/support/integration_helper.rb
|
102
119
|
- spec/support/response_helper.rb
|
103
120
|
- LICENSE
|
104
121
|
- README.rdoc
|
data/lib/rubix/model.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'rubix/log'
|
2
|
-
|
3
|
-
module Rubix
|
4
|
-
|
5
|
-
# It might be worth using ActiveModel -- but maybe not. The goal is
|
6
|
-
# to keep dependencies low while still retaining expressiveness.
|
7
|
-
class Model
|
8
|
-
|
9
|
-
attr_accessor :properties, :id
|
10
|
-
|
11
|
-
include Logs
|
12
|
-
|
13
|
-
def initialize properties={}
|
14
|
-
@properties = properties
|
15
|
-
@id = properties[:id]
|
16
|
-
@log_name = self.class.to_s.split('::').last
|
17
|
-
end
|
18
|
-
|
19
|
-
def loaded?
|
20
|
-
@loaded
|
21
|
-
end
|
22
|
-
|
23
|
-
def load
|
24
|
-
raise NotImplementedError.new("Override the 'load' method in a subclass.")
|
25
|
-
end
|
26
|
-
|
27
|
-
def exists?
|
28
|
-
load unless loaded?
|
29
|
-
@exists
|
30
|
-
end
|
31
|
-
|
32
|
-
def register
|
33
|
-
exists? ? update : create
|
34
|
-
end
|
35
|
-
|
36
|
-
def unregister
|
37
|
-
destroy if exists?
|
38
|
-
end
|
39
|
-
|
40
|
-
def request method, params
|
41
|
-
Rubix.connection && Rubix.connection.request(method, params)
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.find_by_id id
|
45
|
-
instance = new(:id => id)
|
46
|
-
instance if instance.exists?
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.find_by_name name
|
50
|
-
instance = new(:name => name)
|
51
|
-
instance if instance.exists?
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Rubix::HostGroup do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@name = 'foobar'
|
7
|
-
@id = 100
|
8
|
-
@group = Rubix::HostGroup.new(:name => @name)
|
9
|
-
|
10
|
-
@successful_get_response = mock_response([{'groupid' => @id, 'name' => @name, 'hosts' => [{'hostid' => 1}, {'hostid' => 2}]}])
|
11
|
-
@successful_create_response = mock_response({'groupids' => [@id]})
|
12
|
-
@empty_response = mock_response
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'loading' do
|
16
|
-
it "should retrieve properties for an existing host group" do
|
17
|
-
@group.should_receive(:request).with('hostgroup.get', kind_of(Hash)).and_return(@successful_get_response)
|
18
|
-
@group.exists?.should be_true
|
19
|
-
@group.name.should == @name
|
20
|
-
@group.id.should == @id
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should recognize a host group does not exist" do
|
24
|
-
@group.should_receive(:request).with('hostgroup.get', kind_of(Hash)).and_return(@empty_response)
|
25
|
-
@group.exists?.should be_false
|
26
|
-
@group.name.should == @name
|
27
|
-
@group.id.should be_nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'creating' do
|
32
|
-
|
33
|
-
it "can successfully create a new host group" do
|
34
|
-
@group.should_receive(:request).with('hostgroup.create', kind_of(Array)).and_return(@successful_create_response)
|
35
|
-
@group.create
|
36
|
-
@group.exists?.should be_true
|
37
|
-
@group.id.should == @id
|
38
|
-
end
|
39
|
-
|
40
|
-
it "can handle an error" do
|
41
|
-
@group.should_receive(:request).with('hostgroup.get', kind_of(Hash)).and_return(@empty_response)
|
42
|
-
@group.should_receive(:request).with('hostgroup.create', kind_of(Array)).and_return(@empty_response)
|
43
|
-
@group.create
|
44
|
-
@group.exists?.should be_false
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'updating' do
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'destroying' do
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|