solutious-rudy 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +19 -1
- data/README.rdoc +66 -35
- data/Rakefile +1 -0
- data/Rudyfile +97 -6
- data/bin/ird +7 -4
- data/bin/rudy +120 -212
- data/bin/rudy-ec2 +240 -0
- data/bin/rudy-s3 +76 -0
- data/bin/rudy-sdb +67 -0
- data/lib/annoy.rb +61 -18
- data/lib/console.rb +10 -5
- data/lib/rudy/aws/ec2/address.rb +76 -40
- data/lib/rudy/aws/ec2/group.rb +138 -78
- data/lib/rudy/aws/ec2/image.rb +134 -12
- data/lib/rudy/aws/ec2/instance.rb +116 -89
- data/lib/rudy/aws/ec2/keypair.rb +26 -14
- data/lib/rudy/aws/ec2/snapshot.rb +23 -12
- data/lib/rudy/aws/ec2/volume.rb +198 -202
- data/lib/rudy/aws/ec2/zone.rb +77 -0
- data/lib/rudy/aws/ec2.rb +56 -25
- data/lib/rudy/aws/s3.rb +54 -0
- data/lib/rudy/aws/sdb/error.rb +46 -0
- data/lib/rudy/aws/sdb.rb +298 -0
- data/lib/rudy/aws.rb +29 -57
- data/lib/rudy/{metadata/backup.rb → backup.rb} +8 -8
- data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
- data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
- data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
- data/lib/rudy/cli/aws/ec2/images.rb +196 -0
- data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
- data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
- data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
- data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
- data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
- data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
- data/lib/rudy/cli/aws/s3/store.rb +22 -0
- data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
- data/lib/rudy/cli/{deploy.rb → candy.rb} +2 -6
- data/lib/rudy/cli/config.rb +25 -20
- data/lib/rudy/cli/disks.rb +18 -108
- data/lib/rudy/cli/machines.rb +94 -0
- data/lib/rudy/cli/routines.rb +47 -70
- data/lib/rudy/cli.rb +104 -89
- data/lib/rudy/config/objects.rb +5 -43
- data/lib/rudy/config.rb +8 -24
- data/lib/rudy/disks.rb +248 -0
- data/lib/rudy/global.rb +121 -0
- data/lib/rudy/huxtable.rb +232 -147
- data/lib/rudy/machines.rb +245 -0
- data/lib/rudy/metadata.rb +136 -0
- data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
- data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
- data/lib/rudy/routines/release.rb +27 -8
- data/lib/rudy/routines/shutdown.rb +47 -32
- data/lib/rudy/routines/startup.rb +47 -37
- data/lib/rudy/routines.rb +30 -37
- data/lib/rudy/scm/svn.rb +1 -1
- data/lib/rudy/utils.rb +262 -4
- data/lib/rudy.rb +76 -248
- data/lib/storable.rb +19 -16
- data/lib/sysinfo.rb +1 -1
- data/rudy.gemspec +88 -68
- data/support/rudy-ec2-startup +5 -5
- data/test/05_config/00_setup_test.rb +3 -7
- data/test/20_sdb/00_setup_test.rb +2 -17
- data/test/20_sdb/10_domains_test.rb +18 -16
- data/test/25_ec2/00_setup_test.rb +5 -10
- data/test/25_ec2/10_keypairs_test.rb +13 -5
- data/test/25_ec2/20_groups_test.rb +48 -56
- data/test/25_ec2/30_addresses_test.rb +13 -10
- data/test/25_ec2/40_volumes_test.rb +11 -8
- data/test/25_ec2/50_snapshots_test.rb +17 -12
- data/test/26_ec2_instances/00_setup_test.rb +3 -8
- data/test/26_ec2_instances/10_instances_test.rb +21 -19
- data/test/30_sdb_metadata/00_setup_test.rb +2 -9
- data/test/30_sdb_metadata/10_disks_test.rb +47 -37
- data/test/30_sdb_metadata/20_backups_test.rb +9 -9
- data/test/helper.rb +5 -3
- data/vendor/highline-1.5.1/CHANGELOG +222 -0
- data/vendor/highline-1.5.1/INSTALL +35 -0
- data/vendor/highline-1.5.1/LICENSE +7 -0
- data/vendor/highline-1.5.1/README +63 -0
- data/vendor/highline-1.5.1/Rakefile +82 -0
- data/vendor/highline-1.5.1/TODO +6 -0
- data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
- data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
- data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
- data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
- data/vendor/highline-1.5.1/examples/limit.rb +12 -0
- data/vendor/highline-1.5.1/examples/menus.rb +65 -0
- data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
- data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
- data/vendor/highline-1.5.1/examples/password.rb +7 -0
- data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
- data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
- data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
- data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
- data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
- data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
- data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
- data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
- data/vendor/highline-1.5.1/lib/highline.rb +758 -0
- data/vendor/highline-1.5.1/setup.rb +1360 -0
- data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
- data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
- data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
- data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
- data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
- metadata +81 -69
- data/lib/aws_sdb/error.rb +0 -42
- data/lib/aws_sdb/service.rb +0 -215
- data/lib/aws_sdb.rb +0 -3
- data/lib/rudy/aws/simpledb.rb +0 -71
- data/lib/rudy/cli/addresses.rb +0 -85
- data/lib/rudy/cli/backups.rb +0 -175
- data/lib/rudy/cli/domains.rb +0 -17
- data/lib/rudy/cli/groups.rb +0 -77
- data/lib/rudy/cli/images.rb +0 -111
- data/lib/rudy/cli/instances.rb +0 -142
- data/lib/rudy/cli/keypairs.rb +0 -47
- data/lib/rudy/cli/manager.rb +0 -51
- data/lib/rudy/cli/release.rb +0 -174
- data/lib/rudy/cli/volumes.rb +0 -121
- data/lib/rudy/command/addresses.rb +0 -69
- data/lib/rudy/command/backups.rb +0 -65
- data/lib/rudy/command/disks-old.rb +0 -322
- data/lib/rudy/command/disks.rb +0 -9
- data/lib/rudy/command/domains.rb +0 -34
- data/lib/rudy/command/groups.rb +0 -118
- data/lib/rudy/command/instances.rb +0 -278
- data/lib/rudy/command/keypairs.rb +0 -149
- data/lib/rudy/command/manager.rb +0 -65
- data/lib/rudy/command/volumes.rb +0 -127
- data/lib/rudy/metadata/disk.rb +0 -149
- data/lib/rudy/metadata/machine.rb +0 -34
- data/lib/rudy/routines/disk_handler.rb +0 -190
- data/lib/rudy/routines/script_runner.rb +0 -65
- data/test/50_commands/00_setup_test.rb +0 -11
- data/test/50_commands/10_keypairs_test.rb +0 -79
- data/test/50_commands/20_groups_test.rb +0 -77
- data/test/50_commands/40_volumes_test.rb +0 -55
- data/test/50_commands/50_instances_test.rb +0 -110
- data/tryouts/console_tryout.rb +0 -91
- data/tryouts/disks.rb +0 -55
- data/tryouts/nested_methods.rb +0 -36
- data/tryouts/session_tryout.rb +0 -46
data/lib/rudy/huxtable.rb
CHANGED
@@ -2,96 +2,76 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
module Rudy
|
5
|
+
|
6
|
+
# = Rudy::Huxtable
|
7
|
+
#
|
8
|
+
# Huxtable gives access to instances for config, global, and logger to any
|
9
|
+
# class that includes it.
|
10
|
+
#
|
11
|
+
# class Rudy::Hello
|
12
|
+
# include Rudy::Huxtable
|
13
|
+
#
|
14
|
+
# def print_config
|
15
|
+
# p self.config.defaults
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# end
|
19
|
+
#
|
5
20
|
module Huxtable
|
6
|
-
include Rudy::AWS
|
7
21
|
|
8
22
|
# TODO: investigate @@debug bug. When this is true, Caesars.debug? returns true
|
9
|
-
# too. It's
|
23
|
+
# too. It's possible this is intentional but probably not.
|
10
24
|
@@debug = false
|
11
|
-
|
12
|
-
attr_accessor :config
|
13
|
-
attr_accessor :global
|
14
|
-
attr_accessor :logger
|
15
25
|
|
16
|
-
|
17
|
-
|
26
|
+
@@config = Rudy::Config.new
|
27
|
+
@@global = Rudy::Global.new
|
28
|
+
@@logger = StringIO.new # BUG: memory-leak for long-running apps
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@rbox = Rye::Box.new('localhost')
|
33
|
-
|
34
|
-
raise Rudy::NoConfig unless has_keys?
|
35
|
-
Rudy::AWS.set_access_identifiers(@global.accesskey, @global.secretkey, @logger)
|
36
|
-
|
30
|
+
@@sacred_params = [:accesskey, :secretkey, :cert, :privatekey]
|
31
|
+
|
32
|
+
# NOTE: These methods conflict with Drydock::Command classes. It's
|
33
|
+
# probably a good idea to not expose these anyway since it can be
|
34
|
+
# done via Rudy::Huxtable.update_global etc...
|
35
|
+
#def config; @@config; end
|
36
|
+
#def global; @@global; end
|
37
|
+
#def logger; @@logger; end
|
38
|
+
|
39
|
+
def self.update_config(path=nil)
|
40
|
+
# nil or otherwise bad paths send to look_and_load are ignored
|
41
|
+
@@config.look_and_load(path || nil)
|
42
|
+
@@global.apply_config(@@config)
|
37
43
|
end
|
38
44
|
|
45
|
+
update_config
|
39
46
|
|
47
|
+
def self.update_global(ghash={})
|
48
|
+
@@global.update(ghash)
|
49
|
+
end
|
40
50
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@global.quiet = @config.defaults.quiet
|
58
|
-
end
|
59
|
-
|
60
|
-
@global.region ||= DEFAULT_REGION
|
61
|
-
@global.zone ||= DEFAULT_ZONE
|
62
|
-
@global.environment ||= DEFAULT_ENVIRONMENT
|
63
|
-
@global.role ||= DEFAULT_ROLE
|
64
|
-
@global.position ||= DEFAULT_POSITION
|
65
|
-
@global.user ||= DEFAULT_USER
|
66
|
-
@global.nocolor = false
|
67
|
-
@global.quiet = false
|
68
|
-
|
69
|
-
@global.position &&= @global.position.to_s.rjust(2, '0')
|
70
|
-
|
71
|
-
if @config.accounts && @config.accounts.aws
|
72
|
-
@global.accesskey ||= @config.accounts.aws.accesskey
|
73
|
-
@global.secretkey ||= @config.accounts.aws.secretkey
|
74
|
-
@global.account ||= @config.accounts.aws.accountnum
|
75
|
-
|
76
|
-
@global.cert ||= @config.accounts.aws.cert
|
77
|
-
@global.privatekey ||= @config.accounts.aws.privatekey
|
78
|
-
end
|
79
|
-
|
80
|
-
@global.accesskey ||= ENV['AWS_ACCESS_KEY']
|
81
|
-
@global.secretkey ||= ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY']
|
82
|
-
@global.account ||= ENV['AWS_ACCOUNT_NUMBER']
|
83
|
-
|
84
|
-
@global.cert ||= ENV['EC2_CERT']
|
85
|
-
@global.privatekey ||= ENV['EC2_PRIVATE_KEY']
|
86
|
-
|
87
|
-
@global.local_user = ENV['USER'] || :rudy
|
88
|
-
@global.local_hostname = Socket.gethostname || :localhost
|
89
|
-
|
90
|
-
|
91
|
-
String.disable_color if @global.nocolor
|
92
|
-
Rudy.enable_quiet if @global.quiet
|
51
|
+
def self.update_logger(logger)
|
52
|
+
@@logger = logger
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.create_domain
|
56
|
+
@sdb = Rudy::AWS::SDB.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
57
|
+
@sdb.create_domain Rudy::DOMAIN
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.domain_exists?
|
61
|
+
@sdb = Rudy::AWS::SDB.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
62
|
+
(@sdb.list_domains || []).member? Rudy::DOMAIN
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.domain
|
66
|
+
Rudy::DOMAIN
|
93
67
|
end
|
94
68
|
|
69
|
+
def self.change_zone(v); @@global.zone = v; end
|
70
|
+
def self.change_role(v); @@global.role = v; end
|
71
|
+
def self.change_region(v); @@global.region = v; end
|
72
|
+
def self.change_environment(v); @@global.environment = v; end
|
73
|
+
def self.change_position(v); @@global.position = v; end
|
74
|
+
|
95
75
|
def debug?; @@debug == true; end
|
96
76
|
|
97
77
|
def check_keys
|
@@ -101,17 +81,17 @@ module Rudy
|
|
101
81
|
end
|
102
82
|
|
103
83
|
def has_pem_keys?
|
104
|
-
(
|
105
|
-
|
84
|
+
(@@global.cert && File.exists?(@@global.cert) &&
|
85
|
+
@@global.privatekey && File.exists?(@@global.privatekey))
|
106
86
|
end
|
107
87
|
|
108
88
|
def has_keys?
|
109
|
-
(
|
89
|
+
(@@global.accesskey && !@@global.accesskey.empty? && @@global.secretkey && !@@global.secretkey.empty?)
|
110
90
|
end
|
111
91
|
|
112
92
|
def config_dirname
|
113
|
-
raise "No config paths defined" unless
|
114
|
-
base_dir = File.dirname
|
93
|
+
raise "No config paths defined" unless @@config.is_a?(Rudy::Config) && @@config.paths.is_a?(Array)
|
94
|
+
base_dir = File.dirname @@config.paths.first
|
115
95
|
raise "Config directory doesn't exist #{base_dir}" unless File.exists?(base_dir)
|
116
96
|
base_dir
|
117
97
|
end
|
@@ -121,41 +101,56 @@ module Rudy
|
|
121
101
|
(!kp.nil? && File.exists?(kp))
|
122
102
|
end
|
123
103
|
|
104
|
+
# Returns the name of the current keypair for the given user.
|
105
|
+
# If there's a private key path in the config this will return
|
106
|
+
# the basename (it's assumed the Amazon KeyPair has the same
|
107
|
+
# name as the file). Otherwise this returns the Rudy style
|
108
|
+
# name: <tt>key-ENV-ROLE-USER</tt>. Or if this the user is
|
109
|
+
# root: <tt>key-ENV-ROLE</tt>
|
124
110
|
def user_keypairname(user)
|
125
111
|
kp = user_keypairpath(user)
|
126
|
-
|
127
|
-
|
112
|
+
if kp
|
113
|
+
kp = Huxtable.keypair_path_to_name(kp)
|
114
|
+
else
|
115
|
+
n = (user.to_s == 'root') ? '' : "-#{user}"
|
116
|
+
"key-%s%s" % [current_machine_group, n]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
def root_keypairname
|
120
|
+
user_keypairname :root
|
128
121
|
end
|
129
122
|
|
130
|
-
|
131
123
|
|
132
124
|
def user_keypairpath(name)
|
133
125
|
raise "No user provided" unless name
|
134
|
-
|
126
|
+
raise "No configuration" unless @@config
|
127
|
+
raise "No machines configuration" unless @@config.machines
|
128
|
+
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
135
129
|
#Caesars.enable_debug
|
136
|
-
|
137
|
-
|
138
|
-
|
130
|
+
path = @@config.machines.find_deferred(zon, env, rol, [:users, name, :keypair])
|
131
|
+
path ||= @@config.machines.find_deferred(env, rol, [:users, name, :keypair])
|
132
|
+
path ||= @@config.machines.find_deferred(rol, [:users, name, :keypair])
|
139
133
|
|
140
134
|
# EC2 Keypairs that were created are intended for starting the machine instances.
|
141
135
|
# These are used as the root SSH keys. If we can find a user defined key, we'll
|
142
136
|
# check the config path for a generated one.
|
143
|
-
if !
|
137
|
+
if !path && name.to_s == 'root'
|
144
138
|
path = File.join(self.config_dirname, "key-#{current_machine_group}")
|
145
|
-
kp = path if File.exists?(path)
|
146
139
|
end
|
147
|
-
|
148
|
-
|
149
|
-
kp
|
140
|
+
path = File.expand_path(path) if path && File.exists?(path)
|
141
|
+
path
|
150
142
|
end
|
151
|
-
|
143
|
+
def root_keypairpath
|
144
|
+
user_keypairpath :root
|
145
|
+
end
|
146
|
+
|
152
147
|
def has_root_keypair?
|
153
148
|
path = user_keypairpath(:root)
|
154
149
|
(!path.nil? && !path.empty?)
|
155
150
|
end
|
156
151
|
|
157
152
|
def current_user
|
158
|
-
|
153
|
+
@@global.user
|
159
154
|
end
|
160
155
|
def current_user_keypairpath
|
161
156
|
user_keypairpath(current_user)
|
@@ -166,90 +161,180 @@ module Rudy
|
|
166
161
|
end
|
167
162
|
|
168
163
|
def current_machine_group
|
169
|
-
[
|
164
|
+
[@@global.environment, @@global.role].join(Rudy::DELIM)
|
165
|
+
end
|
166
|
+
|
167
|
+
def current_group_name
|
168
|
+
"g-#{current_machine_group}"
|
169
|
+
end
|
170
|
+
|
171
|
+
def current_machine_count
|
172
|
+
fetch_machine_param(:positions) || 1
|
170
173
|
end
|
171
174
|
|
172
175
|
def current_machine_image
|
173
|
-
|
174
|
-
|
175
|
-
ami
|
176
|
-
ami
|
177
|
-
|
178
|
-
|
176
|
+
fetch_machine_param(:ami)
|
177
|
+
#zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
178
|
+
#ami = @@config.machines.find_deferred([zon, env, rol]) || {}
|
179
|
+
#ami.merge!(@@config.machines.find_deferred(env, rol, :ami))
|
180
|
+
#ami.merge!(@@config.machines.find_deferred(rol, :ami))
|
181
|
+
## I commented this out while cleaning (start of 0.6 branch) . It
|
182
|
+
## seems like a bad idea. I don't want Huxtables throwing exceptions.
|
183
|
+
##raise Rudy::NoMachineImage, current_machine_group unless ami
|
184
|
+
#ami
|
185
|
+
end
|
186
|
+
|
187
|
+
def current_machine_size
|
188
|
+
fetch_machine_param(:size) || 'm1.small'
|
179
189
|
end
|
180
190
|
|
181
191
|
def current_machine_address
|
182
|
-
|
192
|
+
raise "No configuration" unless @@config
|
193
|
+
raise "No machines configuration" unless @@config.machines
|
194
|
+
@@config.machines.find_deferred(@@global.environment, @@global.role, :address)
|
183
195
|
end
|
184
196
|
|
185
197
|
# TODO: fix machine_group to include zone
|
186
198
|
def current_machine_name
|
187
|
-
[
|
199
|
+
[@@global.zone, current_machine_group, @@global.position].join(Rudy::DELIM)
|
188
200
|
end
|
189
201
|
|
190
|
-
|
191
|
-
|
192
202
|
# +name+ the name of the remote user to use for the remainder of the command
|
193
203
|
# (or until switched again). If no name is provided, the user will be revert
|
194
204
|
# to whatever it was before the previous switch.
|
195
205
|
# TODO: deprecate
|
196
206
|
def switch_user(name=nil)
|
197
207
|
if name == nil && @switch_user_previous
|
198
|
-
|
199
|
-
elsif
|
208
|
+
@@global.user = @switch_user_previous
|
209
|
+
elsif @@global.user != name
|
200
210
|
raise "No root keypair defined for #{name}!" unless has_keypair?(name)
|
201
|
-
|
202
|
-
@switch_user_previous =
|
203
|
-
|
211
|
+
@@logger.puts "Remote commands will be run as #{name} user"
|
212
|
+
@switch_user_previous = @@global.user
|
213
|
+
@@global.user = name
|
204
214
|
end
|
205
215
|
end
|
206
216
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
find_machine(current_machine_group)
|
217
|
+
def group_metadata(env=@@global.environment, role=@@global.role)
|
218
|
+
query = "['environment' = '#{env}'] intersection ['role' = '#{role}']"
|
219
|
+
@sdb.query_with_attributes(Rudy::DOMAIN, query)
|
211
220
|
end
|
212
|
-
|
213
|
-
def
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
raise "The primary machine in #{group} is not in a running state" unless machine[:aws_state] == 'running'
|
218
|
-
machine
|
221
|
+
|
222
|
+
def self.keypair_path_to_name(kp)
|
223
|
+
return nil unless kp
|
224
|
+
name = File.basename kp
|
225
|
+
#name.gsub(/key-/, '') # We keep the key- now
|
219
226
|
end
|
220
227
|
|
221
|
-
|
228
|
+
private
|
222
229
|
|
223
|
-
def group_metadata(env=@global.environment, role=@global.role)
|
224
|
-
query = "['environment' = '#{env}'] intersection ['role' = '#{role}']"
|
225
|
-
@sdb.query_with_attributes(RUDY_DOMAIN, query)
|
226
|
-
end
|
227
230
|
|
228
|
-
#
|
229
|
-
#
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
231
|
+
# We grab the appropriate routines config and check the paths
|
232
|
+
# against those defined for the matching machine group.
|
233
|
+
# Disks that appear in a routine but not in a machine will be
|
234
|
+
# removed and a warning printed. Otherwise, the routines config
|
235
|
+
# is merged on top of the machine config and that's what we return.
|
236
|
+
#
|
237
|
+
# This means that all the disk info is returned so we know what
|
238
|
+
# size they are and stuff.
|
239
|
+
# Return a hash:
|
240
|
+
#
|
241
|
+
# :after:
|
242
|
+
# - :root: pwd
|
243
|
+
# - :rudy: pwd
|
244
|
+
# :disks:
|
245
|
+
# :create:
|
246
|
+
# /rudy/example1:
|
247
|
+
# :device: /dev/sdr
|
248
|
+
# :size: 2
|
249
|
+
# /rudy/example2:
|
250
|
+
# :device: /dev/sdm
|
251
|
+
# :size: 1
|
252
|
+
#
|
253
|
+
def fetch_routine_config(action)
|
254
|
+
raise "No configuration" unless @@config
|
255
|
+
raise "No routines configuration" unless @@config.routines
|
256
|
+
raise "No globals" unless @@global
|
257
|
+
|
258
|
+
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
234
259
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
260
|
+
disk_defs = fetch_machine_param(:disks)
|
261
|
+
|
262
|
+
routine = @@config.routines.find(@@global.environment, @@global.role, action)
|
263
|
+
return nil unless routine
|
264
|
+
|
265
|
+
routine.disks.each_pair do |raction,disks|
|
266
|
+
|
267
|
+
disks.each_pair do |path, props|
|
268
|
+
unless disk_defs.has_key?(path)
|
269
|
+
@logger.puts "#{path} is not defined. Check your #{action} routines config.".color(:red)
|
270
|
+
routine.disks[raction].delete(path)
|
271
|
+
next
|
244
272
|
end
|
245
|
-
|
273
|
+
|
274
|
+
routine.disks[raction][path] = disk_defs[path].merge(props)
|
275
|
+
|
246
276
|
end
|
247
277
|
end
|
278
|
+
|
279
|
+
routine
|
248
280
|
end
|
249
281
|
|
282
|
+
# Looks for ENV-ROLE configuration in machines. There must be
|
283
|
+
# at least one definition in the config for this to return true
|
284
|
+
# That's how Rudy knows the current group is defined.
|
285
|
+
def known_machine_group?
|
286
|
+
return false if !@@config && !@@global
|
287
|
+
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
288
|
+
conf = @@config.machines.find_deferred(@@global.region, zon, [env, rol])
|
289
|
+
conf ||= @@config.machines.find_deferred(zon, [env, rol])
|
290
|
+
!conf.nil?
|
291
|
+
end
|
250
292
|
|
293
|
+
def fetch_machine_param(parameter)
|
294
|
+
raise "No configuration" unless @@config
|
295
|
+
raise "No machines configuration" unless @@config.machines
|
296
|
+
raise "No globals" unless @@global
|
297
|
+
top_level = @@config.machines.find(parameter)
|
298
|
+
mc = fetch_machine_config
|
299
|
+
mc[parameter] || top_level || nil
|
300
|
+
end
|
301
|
+
|
302
|
+
def fetch_machine_config
|
303
|
+
raise "No configuration" unless @@config
|
304
|
+
raise "No machines configuration" unless @@config.machines
|
305
|
+
raise "No globals" unless @@global
|
306
|
+
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
307
|
+
hashes = []
|
308
|
+
hashes << @@config.machines.find(env, rol)
|
309
|
+
hashes << @@config.machines.find(zon, env, rol)
|
310
|
+
hashes << @@config.machines.find(zon, [env, rol])
|
311
|
+
hashes << @@config.machines.find(zon, env)
|
312
|
+
hashes << @@config.machines.find(env)
|
313
|
+
hashes << @@config.machines.find(zon)
|
314
|
+
compilation = {}
|
315
|
+
hashes.reverse.each do |conf|
|
316
|
+
compilation.merge! conf if conf
|
317
|
+
end
|
318
|
+
compilation = nil if compilation.empty?
|
319
|
+
compilation
|
320
|
+
end
|
321
|
+
|
322
|
+
# Returns the appropriate config block from the machines config.
|
323
|
+
# Also adds the following unless otherwise specified:
|
324
|
+
# :region, :zone, :environment, :role, :position
|
325
|
+
def fetch_script_config
|
326
|
+
sconf = fetch_machine_param :config
|
327
|
+
extras = {
|
328
|
+
:region => @@global.region,
|
329
|
+
:zone => @@global.zone,
|
330
|
+
:environment => @@global.environment,
|
331
|
+
:role => @@global.role,
|
332
|
+
:position => @@global.position
|
333
|
+
}
|
334
|
+
sconf.merge! extras
|
335
|
+
sconf
|
336
|
+
end
|
251
337
|
|
252
|
-
private
|
253
338
|
|
254
339
|
end
|
255
|
-
end
|
340
|
+
end
|