fog_tracker 0.3.3 → 0.3.4
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/lib/fog_tracker.rb +19 -0
- data/lib/fog_tracker/tracker.rb +17 -16
- data/lib/fog_tracker/version.rb +1 -1
- data/spec/lib/fog_tracker_spec.rb +41 -0
- metadata +20 -18
data/lib/fog_tracker.rb
CHANGED
@@ -21,4 +21,23 @@ module FogTracker
|
|
21
21
|
logger
|
22
22
|
end
|
23
23
|
|
24
|
+
# Performs validation and cleanup on an Array of account Hashes.
|
25
|
+
# Changes Strings to Symbols for all required keys.
|
26
|
+
# @param [Hash] account_array an Array of Hash objects.
|
27
|
+
# @return [Hash] the cleaned, validated Hash of account info.
|
28
|
+
def self.validate_accounts(account_hash)
|
29
|
+
account_hash.each do |name, account|
|
30
|
+
account.symbolize_keys
|
31
|
+
raise "Account #{name} defines no service" if not account[:service]
|
32
|
+
raise "Account #{name} defines no provider" if not account[:provider]
|
33
|
+
raise "Account #{name} defines no credentials" if not account[:credentials]
|
34
|
+
if account[:exclude_resources]
|
35
|
+
account[:exclude_resources] = account[:exclude_resources].map do |r|
|
36
|
+
r.to_sym
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
account_hash
|
41
|
+
end
|
42
|
+
|
24
43
|
end
|
data/lib/fog_tracker/tracker.rb
CHANGED
@@ -4,7 +4,7 @@ module FogTracker
|
|
4
4
|
class Tracker
|
5
5
|
|
6
6
|
#a Hash of account information (see accounts.yml.example)
|
7
|
-
|
7
|
+
attr_reader :accounts
|
8
8
|
|
9
9
|
# Creates an object for tracking multiple Fog accounts
|
10
10
|
# @param [Hash] accounts a Hash of account information
|
@@ -17,13 +17,12 @@ module FogTracker
|
|
17
17
|
# (should take a single Exception as its only required parameter)
|
18
18
|
# - :logger - a Ruby Logger-compatible object
|
19
19
|
def initialize(accounts = {}, options = {})
|
20
|
-
@accounts = accounts
|
21
20
|
@delay = options[:delay]
|
22
21
|
@callback = options[:callback]
|
23
22
|
@log = options[:logger] || FogTracker.default_logger
|
24
23
|
@error_proc = options[:error_callback]
|
25
24
|
@running = false
|
26
|
-
|
25
|
+
self.accounts= accounts
|
27
26
|
# Create a Hash that maps account names to AccountTrackers
|
28
27
|
create_trackers
|
29
28
|
end
|
@@ -103,6 +102,21 @@ module FogTracker
|
|
103
102
|
# Returns this tracker's logger, for changing logging dynamically
|
104
103
|
def logger ; @log end
|
105
104
|
|
105
|
+
# Sets the account information.
|
106
|
+
# If any account info has changed, all trackers are restarted.
|
107
|
+
# @param [Hash] accounts a Hash of account information
|
108
|
+
# (see accounts.yml.example)
|
109
|
+
def accounts=(new_accounts)
|
110
|
+
old_accounts = @accounts
|
111
|
+
@accounts = FogTracker.validate_accounts(new_accounts)
|
112
|
+
if (@accounts != old_accounts)
|
113
|
+
stop if (was_running = running?)
|
114
|
+
create_trackers
|
115
|
+
start if was_running
|
116
|
+
end
|
117
|
+
@accounts
|
118
|
+
end
|
119
|
+
|
106
120
|
private
|
107
121
|
|
108
122
|
# Creates a Hash of AccountTracker objects, indexed by account name
|
@@ -124,18 +138,5 @@ module FogTracker
|
|
124
138
|
end
|
125
139
|
end
|
126
140
|
|
127
|
-
# Changes Strings to Symbols in Account keys
|
128
|
-
def validate_accounts
|
129
|
-
@accounts.each do |name, account|
|
130
|
-
account.symbolize_keys
|
131
|
-
raise "Account #{name} defines no service" if not account[:service]
|
132
|
-
raise "Account #{name} defines no provider" if not account[:provider]
|
133
|
-
raise "Account #{name} defines no credentials" if not account[:credentials]
|
134
|
-
account[:exclude_resources] = account[:exclude_resources].map do |r|
|
135
|
-
r.to_sym
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
141
|
end
|
141
142
|
end
|
data/lib/fog_tracker/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module FogTracker
|
2
|
+
|
3
|
+
describe '#validate_accounts' do
|
4
|
+
it "should raise an exception when no service is specified" do
|
5
|
+
(Proc.new { FogTracker.validate_accounts(
|
6
|
+
FAKE_ACCOUNT_NAME => FAKE_ACCOUNT.merge({:service => nil})
|
7
|
+
)}).should raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should raise an exception when no provider is specified" do
|
11
|
+
(Proc.new { FogTracker.validate_accounts(
|
12
|
+
FAKE_ACCOUNT_NAME => FAKE_ACCOUNT.merge({:provider => nil})
|
13
|
+
)}).should raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise an exception when no credentials are specified" do
|
17
|
+
(Proc.new { FogTracker.validate_accounts(
|
18
|
+
FAKE_ACCOUNT_NAME => FAKE_ACCOUNT.merge({:credentials => nil})
|
19
|
+
)}).should raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should symbolize all account keys" do
|
23
|
+
validated_accounts = FogTracker.validate_accounts(
|
24
|
+
FAKE_ACCOUNT_NAME => {
|
25
|
+
'provider' => 'AWS',
|
26
|
+
'service' => 'Compute',
|
27
|
+
'delay' => 10,
|
28
|
+
'credentials' => {
|
29
|
+
'aws_access_key_id' => "fake user",
|
30
|
+
'aws_secret_access_key' => 'fake password'
|
31
|
+
}
|
32
|
+
}
|
33
|
+
)
|
34
|
+
validated_accounts.each do |name, account|
|
35
|
+
account.each do |account_key, account_value|
|
36
|
+
account_key.should be_a Symbol
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
16
|
-
requirement: &
|
16
|
+
requirement: &70164626570920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70164626570920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70164626569880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70164626569880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70164626569020 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70164626569020
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &70164626568500 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70164626568500
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70164626567940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70164626567940
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70164626567220 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70164626567220
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: ruby_gntp
|
82
|
-
requirement: &
|
82
|
+
requirement: &70164626564620 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70164626564620
|
91
91
|
description: This gem peridically polls mutiple cloud computing services using the
|
92
92
|
fog gem, asynchronously updating the state of the resulting collections of Fog Resources.
|
93
93
|
email:
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- spec/lib/fog_tracker/extensions/fog_model_spec.rb
|
123
123
|
- spec/lib/fog_tracker/query/query_processor_spec.rb
|
124
124
|
- spec/lib/fog_tracker/tracker_spec.rb
|
125
|
+
- spec/lib/fog_tracker_spec.rb
|
125
126
|
- spec/spec_helper.rb
|
126
127
|
- spec/support/_configure_logging.rb
|
127
128
|
- spec/support/_mocks.rb
|
@@ -140,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
141
|
version: '0'
|
141
142
|
segments:
|
142
143
|
- 0
|
143
|
-
hash:
|
144
|
+
hash: 358139871120298562
|
144
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
146
|
none: false
|
146
147
|
requirements:
|
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
version: '0'
|
150
151
|
segments:
|
151
152
|
- 0
|
152
|
-
hash:
|
153
|
+
hash: 358139871120298562
|
153
154
|
requirements: []
|
154
155
|
rubyforge_project: fog_tracker
|
155
156
|
rubygems_version: 1.8.15
|
@@ -163,6 +164,7 @@ test_files:
|
|
163
164
|
- spec/lib/fog_tracker/extensions/fog_model_spec.rb
|
164
165
|
- spec/lib/fog_tracker/query/query_processor_spec.rb
|
165
166
|
- spec/lib/fog_tracker/tracker_spec.rb
|
167
|
+
- spec/lib/fog_tracker_spec.rb
|
166
168
|
- spec/spec_helper.rb
|
167
169
|
- spec/support/_configure_logging.rb
|
168
170
|
- spec/support/_mocks.rb
|