rudy 0.4.0 → 0.6.0
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/CHANGES.txt +54 -30
- data/README.rdoc +100 -12
- data/Rakefile +103 -8
- data/Rudyfile +119 -0
- data/bin/ird +175 -0
- data/bin/rudy +259 -156
- data/bin/rudy-ec2 +228 -95
- data/bin/rudy-s3 +76 -0
- data/bin/rudy-sdb +67 -0
- data/lib/annoy.rb +270 -0
- data/lib/console.rb +30 -9
- data/lib/escape.rb +305 -0
- data/lib/rudy.rb +151 -182
- data/lib/rudy/aws.rb +56 -49
- data/lib/rudy/aws/ec2.rb +47 -292
- data/lib/rudy/aws/ec2/address.rb +157 -0
- data/lib/rudy/aws/ec2/group.rb +301 -0
- data/lib/rudy/aws/ec2/image.rb +168 -0
- data/lib/rudy/aws/ec2/instance.rb +434 -0
- data/lib/rudy/aws/ec2/keypair.rb +104 -0
- data/lib/rudy/aws/ec2/snapshot.rb +98 -0
- data/lib/rudy/aws/ec2/volume.rb +230 -0
- data/lib/rudy/aws/ec2/zone.rb +77 -0
- data/lib/rudy/aws/s3.rb +54 -0
- data/lib/rudy/aws/sdb.rb +298 -0
- data/lib/rudy/aws/sdb/error.rb +46 -0
- data/lib/rudy/{metadata/backup.rb → backup.rb} +26 -51
- data/lib/rudy/cli.rb +157 -0
- 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/candy.rb +8 -0
- data/lib/rudy/{command → cli}/config.rb +34 -24
- data/lib/rudy/cli/disks.rb +35 -0
- data/lib/rudy/cli/machines.rb +94 -0
- data/lib/rudy/cli/routines.rb +57 -0
- data/lib/rudy/config.rb +77 -72
- data/lib/rudy/config/objects.rb +29 -0
- data/lib/rudy/disks.rb +248 -0
- data/lib/rudy/global.rb +121 -0
- data/lib/rudy/huxtable.rb +340 -0
- data/lib/rudy/machines.rb +245 -0
- data/lib/rudy/metadata.rb +123 -13
- data/lib/rudy/routines.rb +47 -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 +34 -0
- data/lib/rudy/routines/shutdown.rb +57 -0
- data/lib/rudy/routines/startup.rb +58 -0
- data/lib/rudy/scm/svn.rb +1 -1
- data/lib/rudy/utils.rb +322 -4
- data/lib/storable.rb +26 -17
- data/lib/sysinfo.rb +274 -0
- data/lib/tryouts.rb +6 -13
- data/rudy.gemspec +128 -42
- data/support/randomize-root-password +45 -0
- data/support/rudy-ec2-startup +9 -9
- data/support/update-ec2-ami-tools +20 -0
- data/test/05_config/00_setup_test.rb +20 -0
- data/test/05_config/30_machines_test.rb +69 -0
- data/test/20_sdb/00_setup_test.rb +16 -0
- data/test/20_sdb/10_domains_test.rb +115 -0
- data/test/25_ec2/00_setup_test.rb +29 -0
- data/test/25_ec2/10_keypairs_test.rb +41 -0
- data/test/25_ec2/20_groups_test.rb +131 -0
- data/test/25_ec2/30_addresses_test.rb +38 -0
- data/test/25_ec2/40_volumes_test.rb +49 -0
- data/test/25_ec2/50_snapshots_test.rb +74 -0
- data/test/26_ec2_instances/00_setup_test.rb +28 -0
- data/test/26_ec2_instances/10_instances_test.rb +83 -0
- data/test/26_ec2_instances/50_images_test.rb +13 -0
- data/test/30_sdb_metadata/00_setup_test.rb +21 -0
- data/test/30_sdb_metadata/10_disks_test.rb +109 -0
- data/test/30_sdb_metadata/20_backups_test.rb +102 -0
- data/test/coverage.txt +51 -0
- data/test/helper.rb +36 -0
- 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.rb +758 -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/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 +141 -38
- data/lib/aws_sdb.rb +0 -3
- data/lib/aws_sdb/error.rb +0 -42
- data/lib/aws_sdb/service.rb +0 -215
- data/lib/rudy/aws/simpledb.rb +0 -53
- data/lib/rudy/command/addresses.rb +0 -46
- data/lib/rudy/command/backups.rb +0 -175
- data/lib/rudy/command/base.rb +0 -841
- data/lib/rudy/command/deploy.rb +0 -12
- data/lib/rudy/command/disks.rb +0 -213
- data/lib/rudy/command/environment.rb +0 -73
- data/lib/rudy/command/groups.rb +0 -61
- data/lib/rudy/command/images.rb +0 -91
- data/lib/rudy/command/instances.rb +0 -85
- data/lib/rudy/command/machines.rb +0 -161
- data/lib/rudy/command/metadata.rb +0 -41
- data/lib/rudy/command/release.rb +0 -174
- data/lib/rudy/command/volumes.rb +0 -66
- data/lib/rudy/metadata/disk.rb +0 -138
- data/tryouts/console_tryout.rb +0 -91
data/lib/rudy/global.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Rudy
|
4
|
+
|
5
|
+
# = Rudy::Global
|
6
|
+
#
|
7
|
+
# This global class is used by all Huxtable objects.
|
8
|
+
# When a new CLI global is added, the appropriate field must
|
9
|
+
# be added to this class (optional: a default value in initialize).
|
10
|
+
class Global < Storable
|
11
|
+
|
12
|
+
field :region
|
13
|
+
field :zone
|
14
|
+
field :environment
|
15
|
+
field :role
|
16
|
+
field :position
|
17
|
+
field :user
|
18
|
+
field :pkey
|
19
|
+
|
20
|
+
field :nocolor
|
21
|
+
field :quiet
|
22
|
+
field :verbose
|
23
|
+
field :format
|
24
|
+
field :print_header
|
25
|
+
field :yes
|
26
|
+
|
27
|
+
field :accesskey
|
28
|
+
field :secretkey
|
29
|
+
field :accountnum
|
30
|
+
field :accountname # TODO: use this. And accounttype (aws)
|
31
|
+
field :cert
|
32
|
+
field :privatekey
|
33
|
+
|
34
|
+
field :local_user
|
35
|
+
field :local_hostname
|
36
|
+
|
37
|
+
field :config => String
|
38
|
+
|
39
|
+
attr_accessor :print_header
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
postprocess
|
43
|
+
# These attributes MUST have values.
|
44
|
+
@verbose ||= 0
|
45
|
+
@nocolor ||= false
|
46
|
+
@quiet ||= false
|
47
|
+
@format ||= 'string' # as in, to_s
|
48
|
+
@print_header = true if @print_header == nil
|
49
|
+
@yes = false if @yes.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def apply_config(config)
|
53
|
+
return unless config.is_a?(Rudy::Config)
|
54
|
+
if config.defaults?
|
55
|
+
%w[region zone environment role position user nocolor quiet].each do |name|
|
56
|
+
val = config.defaults.send(name)
|
57
|
+
self.send("#{name}=", val) if val
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if config.accounts? && config.accounts.aws
|
62
|
+
%w[accesskey secretkey accountnum cert privatekey].each do |name|
|
63
|
+
val = config.accounts.aws.send(name)
|
64
|
+
self.send("#{name}=", val) if val
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
postprocess
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def update(ghash={})
|
73
|
+
ghash = ghash.marshal_dump if ghash.is_a?(OpenStruct)
|
74
|
+
|
75
|
+
if ghash.is_a?(Hash)
|
76
|
+
ghash.each_pair { |n,v| self.send("#{n}=", v) }
|
77
|
+
else
|
78
|
+
raise "Unexpected #{ghash.class.to_s}"
|
79
|
+
end
|
80
|
+
|
81
|
+
postprocess
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
|
88
|
+
def postprocess
|
89
|
+
apply_environment_variables
|
90
|
+
apply_system_defaults
|
91
|
+
|
92
|
+
@cert &&= File.expand_path(@cert)
|
93
|
+
@privatekey &&= File.expand_path(@privatekey)
|
94
|
+
@position &&= @position.to_s.rjust(2, '0')
|
95
|
+
|
96
|
+
String.disable_color if @nocolor
|
97
|
+
Rudy.enable_quiet if @quiet
|
98
|
+
Annoy.enable_skip if @yes
|
99
|
+
end
|
100
|
+
|
101
|
+
def apply_environment_variables
|
102
|
+
@accesskey ||= ENV['AWS_ACCESS_KEY']
|
103
|
+
@secretkey ||= ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY']
|
104
|
+
@accountnum ||= ENV['AWS_ACCOUNT_NUMBER']
|
105
|
+
@cert ||= ENV['EC2_CERT']
|
106
|
+
@privatekey ||= ENV['EC2_PRIVATE_KEY']
|
107
|
+
@local_user = ENV['USER'] || :rudy
|
108
|
+
@local_hostname = Socket.gethostname || :localhost
|
109
|
+
end
|
110
|
+
|
111
|
+
def apply_system_defaults
|
112
|
+
@region ||= Rudy::DEFAULT_REGION
|
113
|
+
@zone ||= Rudy::DEFAULT_ZONE
|
114
|
+
@environment ||= Rudy::DEFAULT_ENVIRONMENT
|
115
|
+
@role ||= Rudy::DEFAULT_ROLE
|
116
|
+
@position ||= Rudy::DEFAULT_POSITION
|
117
|
+
@user ||= Rudy::DEFAULT_USER
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,340 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
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
|
+
#
|
20
|
+
module Huxtable
|
21
|
+
|
22
|
+
# TODO: investigate @@debug bug. When this is true, Caesars.debug? returns true
|
23
|
+
# too. It's possible this is intentional but probably not.
|
24
|
+
@@debug = false
|
25
|
+
|
26
|
+
@@config = Rudy::Config.new
|
27
|
+
@@global = Rudy::Global.new
|
28
|
+
@@logger = StringIO.new # BUG: memory-leak for long-running apps
|
29
|
+
|
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)
|
43
|
+
end
|
44
|
+
|
45
|
+
update_config
|
46
|
+
|
47
|
+
def self.update_global(ghash={})
|
48
|
+
@@global.update(ghash)
|
49
|
+
end
|
50
|
+
|
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
|
67
|
+
end
|
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
|
+
|
75
|
+
def debug?; @@debug == true; end
|
76
|
+
|
77
|
+
def check_keys
|
78
|
+
raise "No EC2 .pem keys provided" unless has_pem_keys?
|
79
|
+
raise "No SSH key provided for #{current_user}!" unless has_keypair?
|
80
|
+
raise "No SSH key provided for root!" unless has_keypair?(:root)
|
81
|
+
end
|
82
|
+
|
83
|
+
def has_pem_keys?
|
84
|
+
(@@global.cert && File.exists?(@@global.cert) &&
|
85
|
+
@@global.privatekey && File.exists?(@@global.privatekey))
|
86
|
+
end
|
87
|
+
|
88
|
+
def has_keys?
|
89
|
+
(@@global.accesskey && !@@global.accesskey.empty? && @@global.secretkey && !@@global.secretkey.empty?)
|
90
|
+
end
|
91
|
+
|
92
|
+
def config_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
|
95
|
+
raise "Config directory doesn't exist #{base_dir}" unless File.exists?(base_dir)
|
96
|
+
base_dir
|
97
|
+
end
|
98
|
+
|
99
|
+
def has_keypair?(name=nil)
|
100
|
+
kp = user_keypairpath(name)
|
101
|
+
(!kp.nil? && File.exists?(kp))
|
102
|
+
end
|
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>
|
110
|
+
def user_keypairname(user)
|
111
|
+
kp = user_keypairpath(user)
|
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
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
def user_keypairpath(name)
|
125
|
+
raise "No user provided" unless name
|
126
|
+
raise "No configuration" unless @@config
|
127
|
+
raise "No machines configuration" unless @@config.machines
|
128
|
+
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
129
|
+
#Caesars.enable_debug
|
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])
|
133
|
+
|
134
|
+
# EC2 Keypairs that were created are intended for starting the machine instances.
|
135
|
+
# These are used as the root SSH keys. If we can find a user defined key, we'll
|
136
|
+
# check the config path for a generated one.
|
137
|
+
if !path && name.to_s == 'root'
|
138
|
+
path = File.join(self.config_dirname, "key-#{current_machine_group}")
|
139
|
+
end
|
140
|
+
path = File.expand_path(path) if path && File.exists?(path)
|
141
|
+
path
|
142
|
+
end
|
143
|
+
def root_keypairpath
|
144
|
+
user_keypairpath :root
|
145
|
+
end
|
146
|
+
|
147
|
+
def has_root_keypair?
|
148
|
+
path = user_keypairpath(:root)
|
149
|
+
(!path.nil? && !path.empty?)
|
150
|
+
end
|
151
|
+
|
152
|
+
def current_user
|
153
|
+
@@global.user
|
154
|
+
end
|
155
|
+
def current_user_keypairpath
|
156
|
+
user_keypairpath(current_user)
|
157
|
+
end
|
158
|
+
def current_machine_hostname(group=nil)
|
159
|
+
group ||= machine_group
|
160
|
+
find_machine(group)[:dns_name]
|
161
|
+
end
|
162
|
+
|
163
|
+
def current_machine_group
|
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
|
173
|
+
end
|
174
|
+
|
175
|
+
def current_machine_image
|
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'
|
189
|
+
end
|
190
|
+
|
191
|
+
def current_machine_address
|
192
|
+
raise "No configuration" unless @@config
|
193
|
+
raise "No machines configuration" unless @@config.machines
|
194
|
+
@@config.machines.find_deferred(@@global.environment, @@global.role, :address)
|
195
|
+
end
|
196
|
+
|
197
|
+
# TODO: fix machine_group to include zone
|
198
|
+
def current_machine_name
|
199
|
+
[@@global.zone, current_machine_group, @@global.position].join(Rudy::DELIM)
|
200
|
+
end
|
201
|
+
|
202
|
+
# +name+ the name of the remote user to use for the remainder of the command
|
203
|
+
# (or until switched again). If no name is provided, the user will be revert
|
204
|
+
# to whatever it was before the previous switch.
|
205
|
+
# TODO: deprecate
|
206
|
+
def switch_user(name=nil)
|
207
|
+
if name == nil && @switch_user_previous
|
208
|
+
@@global.user = @switch_user_previous
|
209
|
+
elsif @@global.user != name
|
210
|
+
raise "No root keypair defined for #{name}!" unless has_keypair?(name)
|
211
|
+
@@logger.puts "Remote commands will be run as #{name} user"
|
212
|
+
@switch_user_previous = @@global.user
|
213
|
+
@@global.user = name
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
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)
|
220
|
+
end
|
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
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
|
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
|
259
|
+
|
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
|
272
|
+
end
|
273
|
+
|
274
|
+
routine.disks[raction][path] = disk_defs[path].merge(props)
|
275
|
+
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
routine
|
280
|
+
end
|
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
|
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
|
337
|
+
|
338
|
+
|
339
|
+
end
|
340
|
+
end
|