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.rb
CHANGED
@@ -26,22 +26,18 @@ require 'net/ssh/multi'
|
|
26
26
|
require 'net/ssh/gateway'
|
27
27
|
|
28
28
|
|
29
|
+
require 'logger'
|
29
30
|
|
30
31
|
# = Rudy
|
31
32
|
#
|
32
33
|
# == About
|
33
34
|
#
|
34
35
|
# Rudy is a development and deployment tool for the Amazon Elastic Compute Cloud
|
35
|
-
# (EC2).
|
36
|
-
# You can use Rudy as a development tool to simply the management of instances,
|
37
|
-
# security groups, etc... on an ad-hoc basic. You can also define complex machine
|
38
|
-
# environments using a simple domain specific language (DSL) and use Rudy to build
|
39
|
-
# and deploy these environments.
|
40
|
-
#
|
36
|
+
# (EC2). See README.rdoc for more information.
|
41
37
|
#
|
42
38
|
# == Status: Alpha
|
43
39
|
#
|
44
|
-
# The current release (0.
|
40
|
+
# The current release (0.6) is not ready for general production use. Use it for
|
45
41
|
# exploring EC2 and operating your development / ad-hoc instances. We've put in
|
46
42
|
# a lot of effort to make sure Rudy plays safe, but it's possible we missed
|
47
43
|
# something. That's why we consider it alpha code.
|
@@ -51,42 +47,59 @@ require 'net/ssh/gateway'
|
|
51
47
|
# $ rudy -h
|
52
48
|
# $ rudy show-commands
|
53
49
|
#
|
50
|
+
# Also:
|
51
|
+
#
|
52
|
+
# $ rudy-ec2 -h
|
53
|
+
# $ rudy-ec2 show-commands
|
54
|
+
#
|
54
55
|
# And if you're feeling particularly saucey, try Rudy's REPL interface:
|
55
56
|
#
|
56
57
|
# $ ird
|
57
58
|
#
|
58
|
-
# == Next Release (0.6): May 2009.
|
59
|
-
#
|
60
|
-
# $ rudy slogan
|
61
|
-
# Rudy: Not your grandparent's deployment tool!
|
62
59
|
#
|
63
60
|
#
|
64
61
|
module Rudy
|
65
62
|
extend self
|
66
63
|
|
67
|
-
|
64
|
+
module VERSION #:nodoc:
|
65
|
+
unless defined?(MAJOR)
|
66
|
+
MAJOR = 0.freeze
|
67
|
+
MINOR = 6.freeze
|
68
|
+
TINY = 0.freeze
|
69
|
+
end
|
70
|
+
def self.to_s; [MAJOR, MINOR, TINY].join('.'); end
|
71
|
+
def self.to_f; self.to_s.to_f; end
|
72
|
+
end
|
73
|
+
|
74
|
+
unless defined?(Rudy::DOMAIN) # We can assume all constants are defined
|
68
75
|
# SimpleDB accepts dashes in the domain name on creation and with the query syntax.
|
69
76
|
# However, with select syntax it says: "The specified query expression syntax is not valid"
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
RUDY_CONFIG_DIR = File.join(ENV['HOME'] || ENV['USERPROFILE'], '.rudy').freeze
|
74
|
-
RUDY_CONFIG_FILE = File.join(RUDY_CONFIG_DIR, 'config').freeze
|
77
|
+
DOMAIN = "rudy_state".freeze
|
78
|
+
DELIM = '-'.freeze
|
75
79
|
|
80
|
+
CONFIG_DIR = File.join(ENV['HOME'] || ENV['USERPROFILE'], '.rudy').freeze
|
81
|
+
CONFIG_FILE = File.join(Rudy::CONFIG_DIR, 'config').freeze
|
82
|
+
|
76
83
|
DEFAULT_REGION = 'us-east-1'.freeze
|
77
84
|
DEFAULT_ZONE = 'us-east-1b'.freeze
|
78
85
|
DEFAULT_ENVIRONMENT = 'stage'.freeze
|
79
86
|
DEFAULT_ROLE = 'app'.freeze
|
80
87
|
DEFAULT_POSITION = '01'.freeze
|
81
|
-
|
88
|
+
|
82
89
|
DEFAULT_USER = 'rudy'.freeze
|
83
|
-
|
90
|
+
|
91
|
+
DEFAULT_EC2_HOST = "ec2.amazonaws.com"
|
92
|
+
DEFAULT_EC2_PORT = 443
|
93
|
+
|
94
|
+
MAX_INSTANCES = 3.freeze
|
95
|
+
|
84
96
|
SUPPORTED_SCM_NAMES = [:svn, :git].freeze
|
85
97
|
|
86
98
|
ID_MAP = {
|
87
99
|
:instance => 'i',
|
88
100
|
:disk => 'disk',
|
89
101
|
:backup => 'back',
|
102
|
+
:machine => 'm',
|
90
103
|
:volume => 'vol',
|
91
104
|
:snapshot => 'snap',
|
92
105
|
:kernel => 'aki',
|
@@ -94,257 +107,72 @@ module Rudy
|
|
94
107
|
:ram => 'ari',
|
95
108
|
:log => 'log',
|
96
109
|
:key => 'key',
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:reservation => 'r'
|
110
|
+
:awspk => 'pk',
|
111
|
+
:awscert => 'cert',
|
112
|
+
:reservation => 'r',
|
113
|
+
:dns_public => 'ec2',
|
114
|
+
:dns_private => 'domU',
|
100
115
|
}.freeze
|
101
116
|
|
117
|
+
@@quiet = false
|
118
|
+
@@debug = false
|
102
119
|
@@sysinfo = SystemInfo.new.freeze
|
120
|
+
|
103
121
|
end
|
104
122
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
MINOR = 5.freeze
|
109
|
-
TINY = 1.freeze
|
110
|
-
end
|
111
|
-
def self.to_s; [MAJOR, MINOR, TINY].join('.'); end
|
112
|
-
def self.to_f; self.to_s.to_f; end
|
113
|
-
end
|
114
|
-
|
115
|
-
@@quiet = false
|
123
|
+
def Rudy.debug?; @@debug == true; end
|
124
|
+
def Rudy.quiet?; @@quiet == true; end
|
125
|
+
def Rudy.enable_debug; @@debug = true; end
|
116
126
|
def Rudy.enable_quiet; @@quiet = true; end
|
127
|
+
def Rudy.disable_debug; @@debug = false; end
|
117
128
|
def Rudy.disable_quiet; @@quiet = false; end
|
118
|
-
|
129
|
+
|
119
130
|
def Rudy.sysinfo; @@sysinfo; end
|
120
131
|
def sysinfo; @@sysinfo; end
|
121
132
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
# file is written by /etc/init.d/rudy-ec2-startup.
|
126
|
-
# NOTE: Is there a way to know definitively that this is EC2?
|
127
|
-
# We could make a request to the metadata IP addresses.
|
128
|
-
def Rudy.in_situ?
|
129
|
-
File.exists?('/etc/ec2/instance-id')
|
133
|
+
class Error < RuntimeError
|
134
|
+
def initialize(obj); @obj = obj; end
|
135
|
+
def message; "#{self.class}: #{@obj}"; end
|
130
136
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
# * +logger+ IO object to print +dot+ to.
|
137
|
-
# * +dot+ the character to print after each attempt (default: .).
|
138
|
-
# Set to nil or false to keep the waiter silent.
|
139
|
-
# The block must return false while waiting. Once it returns true
|
140
|
-
# the waiter will return true too.
|
141
|
-
def Rudy.waiter(duration=2, max=120, logger=STDOUT, dot='.', &check)
|
142
|
-
# TODO: Move to Drydock
|
143
|
-
raise "The waiter needs a block!" unless check
|
144
|
-
duration = 1 if duration < 1
|
145
|
-
max = duration*2 if max < duration
|
146
|
-
success = false
|
147
|
-
begin
|
148
|
-
success = Timeout::timeout(max) do
|
149
|
-
while !check.call
|
150
|
-
logger.print dot if dot && logger.respond_to?(:print)
|
151
|
-
logger.flush if logger.respond_to?(:flush)
|
152
|
-
sleep duration
|
153
|
-
end
|
154
|
-
end
|
155
|
-
rescue Timeout::Error => ex
|
156
|
-
retry if Annoy.pose_question(" Keep waiting?\a ", /yes|y|ya|sure|you bet!/i, logger)
|
157
|
-
raise ex # We won't get here unless the question fails
|
137
|
+
class InsecureKeyPermissions < Rudy::Error
|
138
|
+
def message
|
139
|
+
lines = ["Insecure file permissions for #{@obj}"]
|
140
|
+
lines << "Try: chmod 600 #{@obj}"
|
141
|
+
lines.join($/)
|
158
142
|
end
|
159
|
-
success
|
160
143
|
end
|
161
|
-
|
162
|
-
|
163
|
-
def Rudy.bell(chimes=1, logger=nil)
|
164
|
-
return if @@quiet
|
165
|
-
chimed = chimes.to_i
|
166
|
-
logger.print "\a"*chimes if logger
|
167
|
-
true # be like Rudy.bug()
|
144
|
+
class NoConfig < Rudy::Error
|
145
|
+
def message; "No AWS credentials. Check your configs!"; end
|
168
146
|
end
|
169
|
-
|
170
|
-
|
171
|
-
def Rudy.bug(bugid, logger=STDERR)
|
172
|
-
logger.puts "You have found a bug! If you want, you can email".color(:red)
|
173
|
-
logger.puts 'rudy@solutious.com'.color(:red).bright << " about it. It's bug ##{bugid}.".color(:red)
|
174
|
-
logger.puts "Continuing...".color(:red)
|
175
|
-
true # so we can string it together like: bug('1') && next if ...
|
147
|
+
class ServiceUnavailable < Rudy::Error
|
148
|
+
def message; "#{@obj} is not available. Check your internets!"; end
|
176
149
|
end
|
177
|
-
|
178
|
-
|
179
|
-
# * +identifier+ is expected to be a key from ID_MAP
|
180
|
-
# * +str+ is a string you're investigating
|
181
|
-
def Rudy.is_id?(identifier, str)
|
182
|
-
return false unless identifier && str && Rudy.known_type?(identifier)
|
183
|
-
identifier &&= identifier.to_sym
|
184
|
-
str &&= str.to_s.strip
|
185
|
-
str.split('-').first == Rudy::ID_MAP[identifier].to_s
|
150
|
+
class MachineGroupAlreadyRunning < Rudy::Error
|
151
|
+
def message; "Machine group #{@obj} is already running."; end
|
186
152
|
end
|
187
|
-
|
188
|
-
|
189
|
-
# * +str+ is a string you're investigating
|
190
|
-
def Rudy.id_type(str)
|
191
|
-
return false unless str
|
192
|
-
str &&= str.to_s.strip
|
193
|
-
(Rudy::ID_MAP.detect { |n,v| v == str.split('-').first } || []).first
|
153
|
+
class MachineGroupNotRunning < Rudy::Error
|
154
|
+
def message; "Machine group #{@obj} is not running."; end
|
194
155
|
end
|
195
|
-
|
196
|
-
|
197
|
-
def Rudy.known_type?(key)
|
198
|
-
return false unless key
|
199
|
-
key &&= key.to_s.to_sym
|
200
|
-
Rudy::ID_MAP.has_key?(key)
|
201
|
-
end
|
202
|
-
|
203
|
-
# Returns the string identifier associated to this +key+
|
204
|
-
def Rudy.identifier(key)
|
205
|
-
key &&= key.to_sym
|
206
|
-
return unless Rudy::ID_MAP.has_key?(key)
|
207
|
-
Rudy::ID_MAP[key]
|
208
|
-
end
|
209
|
-
|
210
|
-
# Return a string ID without the identifier. i.e. key-stage-app-root => stage-app-root
|
211
|
-
def Rudy.strip_identifier(str)
|
212
|
-
el = str.split('-')
|
213
|
-
el.shift
|
214
|
-
el.join('-')
|
215
|
-
end
|
216
|
-
|
217
|
-
# +msg+ The message to return as a banner
|
218
|
-
# +size+ One of: :normal (default), :huge
|
219
|
-
# +colour+ a valid
|
220
|
-
# Returns a string with styling applying
|
221
|
-
def Rudy.banner(msg, size = :normal, colour = :black)
|
222
|
-
return unless msg
|
223
|
-
banners = {
|
224
|
-
:huge => Rudy::Utils.without_indent(%Q(
|
225
|
-
=======================================================
|
226
|
-
=======================================================
|
227
|
-
!!!!!!!!! %s !!!!!!!!!
|
228
|
-
=======================================================
|
229
|
-
=======================================================)),
|
230
|
-
:normal => %Q(============ %s ============)
|
231
|
-
}
|
232
|
-
size = :normal unless banners.has_key?(size)
|
233
|
-
colour = :black unless Console.valid_colour?(colour)
|
234
|
-
size, colour = size.to_sym, colour.to_sym
|
235
|
-
sprintf(banners[size], msg).colour(colour).bgcolour(:white).bright
|
236
|
-
end
|
237
|
-
|
238
|
-
# Run a block and trap common, known errors.
|
239
|
-
# * +default+ A default response value
|
240
|
-
# * +request+ A block which contains the AWS request
|
241
|
-
# Returns the return value from the request is returned untouched
|
242
|
-
# or the default value on error or if the request returned nil.
|
243
|
-
def trap_known_errors(default=nil, &request)
|
244
|
-
raise "No block provided" unless request
|
245
|
-
response = nil
|
246
|
-
begin
|
247
|
-
response = request.call
|
248
|
-
rescue => ex
|
249
|
-
STDERR.puts ex.message
|
250
|
-
ensure
|
251
|
-
response ||= default
|
252
|
-
end
|
253
|
-
response
|
156
|
+
class MachineGroupNotDefined < Rudy::Error
|
157
|
+
def message; "#{@obj} is not defined in machines config."; end
|
254
158
|
end
|
255
|
-
|
256
|
-
|
257
|
-
class NoConfig < RuntimeError
|
258
|
-
def message
|
259
|
-
"No AWS credentials. Check your configs!"
|
260
|
-
end
|
261
|
-
end
|
262
|
-
class NoMachineImage < RuntimeError
|
263
|
-
def initialize(group)
|
264
|
-
@group = group
|
265
|
-
end
|
266
|
-
def message
|
267
|
-
"There is no AMI configured for #{@group}"
|
268
|
-
end
|
159
|
+
class PrivateKeyFileExists < Rudy::Error
|
160
|
+
def message; "Private key #{@obj} already exists."; end
|
269
161
|
end
|
270
|
-
|
271
|
-
|
272
|
-
require 'rudy/aws'
|
273
|
-
require 'rudy/utils' # The
|
274
|
-
require 'rudy/config' # order
|
275
|
-
require 'rudy/huxtable' # of
|
276
|
-
require 'rudy/command/addresses' # require
|
277
|
-
require 'rudy/command/keypairs'
|
278
|
-
require 'rudy/command/instances' # statements
|
279
|
-
require 'rudy/command/manager' # is
|
280
|
-
require 'rudy/command/domains'
|
281
|
-
require 'rudy/command/backups' # important.
|
282
|
-
require 'rudy/command/volumes'
|
283
|
-
require 'rudy/command/groups'
|
284
|
-
require 'rudy/command/disks'
|
285
|
-
require 'rudy/routines'
|
286
|
-
|
287
|
-
|
288
|
-
# Require MetaData, Routines, and SCM classes
|
289
|
-
begin
|
290
|
-
# TODO: Use autoload
|
291
|
-
Dir.glob(File.join(RUDY_LIB, 'rudy', '{metadata,routines,scm}', "*.rb")).each do |path|
|
292
|
-
require path
|
162
|
+
class PrivateKeyNotFound < Rudy::Error
|
163
|
+
def message; "Private key file #{@obj} not found."; end
|
293
164
|
end
|
294
|
-
rescue LoadError => ex
|
295
|
-
puts "Error: #{ex.message}"
|
296
|
-
exit 1
|
297
|
-
end
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
# ---
|
302
|
-
# TODO: Find a home for these poor guys:
|
303
|
-
# +++
|
304
|
-
|
305
|
-
def sh(command, chdir=false, verbose=false)
|
306
|
-
prevdir = Dir.pwd
|
307
|
-
Dir.chdir chdir if chdir
|
308
|
-
puts command if verbose
|
309
|
-
system(command)
|
310
|
-
Dir.chdir prevdir if chdir
|
311
165
|
end
|
312
166
|
|
167
|
+
require 'rudy/utils' # The
|
168
|
+
require 'rudy/global' # order
|
169
|
+
require 'rudy/config' # of
|
170
|
+
require 'rudy/huxtable' # requires
|
171
|
+
require 'rudy/aws' # is
|
172
|
+
require 'rudy/metadata' # important
|
313
173
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
cmd += " '#{command}'" if command
|
318
|
-
puts cmd if verbose
|
319
|
-
return cmd if printonly
|
320
|
-
# backticks returns STDOUT
|
321
|
-
# exec replaces current process (it's just like running ssh)
|
322
|
-
# -- UPDATE -- Some problem with exec. "Operation not supported"
|
323
|
-
# using system (http://www.mail-archive.com/mongrel-users@rubyforge.org/msg02018.html)
|
324
|
-
(command) ? `#{cmd}` : Kernel.system(cmd)
|
325
|
-
end
|
326
|
-
|
174
|
+
require 'rudy/machines'
|
175
|
+
require 'rudy/disks'
|
176
|
+
require 'rudy/routines'
|
327
177
|
|
328
|
-
def scp_command(host, keypair, user, paths, to_path, to_local=false, verbose=false, printonly=false)
|
329
|
-
|
330
|
-
paths = [paths] unless paths.is_a?(Array)
|
331
|
-
from_paths = ""
|
332
|
-
if to_local
|
333
|
-
paths.each do |path|
|
334
|
-
from_paths << "#{user}@#{host}:#{path} "
|
335
|
-
end
|
336
|
-
puts "Copying FROM remote TO this machine", $/
|
337
|
-
|
338
|
-
else
|
339
|
-
to_path = "#{user}@#{host}:#{to_path}"
|
340
|
-
from_paths = paths.join(' ')
|
341
|
-
puts "Copying FROM this machine TO remote", $/
|
342
|
-
end
|
343
|
-
|
344
|
-
|
345
|
-
cmd = "scp -r -i #{keypair} #{from_paths} #{to_path}"
|
346
|
-
|
347
|
-
puts cmd if verbose
|
348
|
-
printonly ? (puts cmd) : system(cmd)
|
349
|
-
end
|
350
178
|
|
data/lib/storable.rb
CHANGED
@@ -13,10 +13,10 @@ require 'fileutils'
|
|
13
13
|
# Storable.field method which tells Storable the order and
|
14
14
|
# name.
|
15
15
|
class Storable
|
16
|
-
unless defined?(
|
17
|
-
VERSION =
|
16
|
+
unless defined?(SUPPORTED_FORMATS) # We can assume all are defined
|
17
|
+
VERSION = 5
|
18
18
|
NICE_TIME_FORMAT = "%Y-%m-%d@%H:%M:%S".freeze
|
19
|
-
SUPPORTED_FORMATS = %w{tsv csv yaml json}.freeze
|
19
|
+
SUPPORTED_FORMATS = %w{tsv csv yaml json s string}.freeze
|
20
20
|
end
|
21
21
|
|
22
22
|
# This value will be used as a default unless provided on-the-fly.
|
@@ -29,14 +29,11 @@ class Storable
|
|
29
29
|
@format = v
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
def init
|
35
|
-
# NOTE: I think this can be removed
|
36
|
-
self.class.send(:class_variable_set, :@@field_names, []) unless class_variable_defined?(:@@field_names)
|
37
|
-
self.class.send(:class_variable_set, :@@field_types, []) unless class_variable_defined?(:@@field_types)
|
32
|
+
def postprocess
|
38
33
|
end
|
39
34
|
|
35
|
+
# TODO: from_args([HASH or ordered params])
|
36
|
+
|
40
37
|
# Accepts field definitions in the one of the follow formats:
|
41
38
|
#
|
42
39
|
# field :product
|
@@ -70,7 +67,7 @@ class Storable
|
|
70
67
|
def self.field_names
|
71
68
|
class_variable_get(:@@field_names)
|
72
69
|
end
|
73
|
-
#
|
70
|
+
# Returns an array of field names defined by self.field
|
74
71
|
def field_names
|
75
72
|
self.class.send(:class_variable_get, :@@field_names)
|
76
73
|
end
|
@@ -79,18 +76,23 @@ class Storable
|
|
79
76
|
def self.field_types
|
80
77
|
class_variable_get(:@@field_types)
|
81
78
|
end
|
82
|
-
#
|
79
|
+
# Returns an array of field types defined by self.field. Fields that did
|
80
|
+
# not receive a type are set to nil.
|
83
81
|
def field_types
|
84
82
|
self.class.send(:class_variable_get, :@@field_types)
|
85
83
|
end
|
86
84
|
|
87
85
|
# Dump the object data to the given format.
|
88
|
-
def dump(format=nil, with_titles=
|
89
|
-
format ||=
|
86
|
+
def dump(format=nil, with_titles=false)
|
87
|
+
format ||= 's' # as in, to_s
|
90
88
|
raise "Format not defined (#{format})" unless SUPPORTED_FORMATS.member?(format)
|
91
89
|
send("to_#{format}", with_titles)
|
92
90
|
end
|
93
91
|
|
92
|
+
def to_string(*args)
|
93
|
+
to_s(*args)
|
94
|
+
end
|
95
|
+
|
94
96
|
# Create a new instance of the object using data from file.
|
95
97
|
def self.from_file(file_path, format='yaml')
|
96
98
|
raise "Cannot read file (#{file_path})" unless File.exists?(file_path)
|
@@ -110,10 +112,9 @@ class Storable
|
|
110
112
|
|
111
113
|
# Create a new instance of the object from a hash.
|
112
114
|
def self.from_hash(from={})
|
115
|
+
return nil if !from || from.empty?
|
113
116
|
me = self.new
|
114
|
-
|
115
|
-
return me if !from || from.empty?
|
116
|
-
|
117
|
+
|
117
118
|
fnames = field_names
|
118
119
|
fnames.each_with_index do |key,index|
|
119
120
|
|
@@ -151,6 +152,8 @@ class Storable
|
|
151
152
|
me.send("#{key}=", value) if self.method_defined?("#{key}=")
|
152
153
|
end
|
153
154
|
|
155
|
+
me.postprocess
|
156
|
+
|
154
157
|
me
|
155
158
|
end
|
156
159
|
# Return the object data as a hash
|
data/lib/sysinfo.rb
CHANGED
@@ -6,7 +6,7 @@ require 'socket'
|
|
6
6
|
# A container for the system platform information.
|
7
7
|
# Portions of this code is from Amazon's EC2 AMI tools, lib/platform.rb.
|
8
8
|
class SystemInfo < Storable
|
9
|
-
unless defined?(
|
9
|
+
unless defined?(IMPLEMENTATIONS)
|
10
10
|
VERSION = 2.freeze
|
11
11
|
IMPLEMENTATIONS = [
|
12
12
|
|