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
@@ -3,28 +3,47 @@
|
|
3
3
|
|
4
4
|
module Rudy::AWS
|
5
5
|
class EC2::Instance < Storable
|
6
|
+
@@sformat = " -> %10s; %10s; %12s; %10s; groups: %s"
|
6
7
|
field :aki
|
7
8
|
field :ari
|
8
9
|
field :launch_index => Time
|
9
10
|
field :launch_time
|
10
11
|
field :keyname
|
11
|
-
field :
|
12
|
+
field :size
|
12
13
|
field :ami
|
13
|
-
field :
|
14
|
-
field :
|
14
|
+
field :dns_private
|
15
|
+
field :dns_public
|
15
16
|
field :awsid
|
16
17
|
field :state
|
17
18
|
field :zone
|
18
19
|
field :reason
|
19
20
|
field :groups => Array
|
20
21
|
|
22
|
+
# Groups aren't returned when creating an instance so this
|
23
|
+
# method returns an empty Array if +@groups+ is not set.
|
21
24
|
def groups
|
22
25
|
@groups || []
|
23
26
|
end
|
24
27
|
|
25
|
-
|
26
|
-
|
28
|
+
def liner_note
|
29
|
+
info = self.running? ? self.dns_public : self.state
|
30
|
+
"%s %s" % [self.awsid.bright, info]
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s(with_title=false)
|
27
34
|
lines = []
|
35
|
+
lines << "%s (%s)" % [liner_note, @groups.join(', ')]
|
36
|
+
#if self.running?
|
37
|
+
# k, g = @keyname || 'no-keypair', self.groups.join(', ')
|
38
|
+
# lines << @@sformat % %w{zone size ami keyname groups} if with_title
|
39
|
+
# lines << @@sformat % [@zone, @size, @ami, k, g]
|
40
|
+
#end
|
41
|
+
lines.join($/)
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
lines = []
|
46
|
+
lines << liner_note
|
28
47
|
field_names.each do |key|
|
29
48
|
next unless self.respond_to?(key)
|
30
49
|
val = self.send(key)
|
@@ -33,92 +52,94 @@ module Rudy::AWS
|
|
33
52
|
lines.join($/)
|
34
53
|
end
|
35
54
|
|
36
|
-
def running
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def
|
41
|
-
self.state && self.state == 'pending'
|
42
|
-
end
|
43
|
-
|
44
|
-
def terminated?
|
45
|
-
self.state && self.state == 'terminated'
|
46
|
-
end
|
47
|
-
|
48
|
-
def shutting_down?
|
49
|
-
self.state && self.state == 'shutting-down'
|
50
|
-
end
|
55
|
+
def running?; self.state && self.state == 'running'; end
|
56
|
+
def pending?; self.state && self.state == 'pending'; end
|
57
|
+
def terminated?; self.state && self.state == 'terminated'; end
|
58
|
+
def degraded?; self.state && self.state == 'degraded'; end
|
59
|
+
def shutting_down?; self.state && self.state == 'shutting-down'; end
|
51
60
|
|
52
61
|
end
|
53
62
|
|
54
63
|
|
55
|
-
|
64
|
+
module EC2
|
56
65
|
class Instances
|
57
66
|
include Rudy::AWS::ObjectBase
|
67
|
+
include Rudy::AWS::EC2::Base
|
68
|
+
|
58
69
|
unless defined?(KNOWN_STATES)
|
59
|
-
KNOWN_STATES = [:running, :pending, :shutting_down, :terminated].freeze
|
70
|
+
KNOWN_STATES = [:running, :pending, :shutting_down, :terminated, :degraded].freeze
|
60
71
|
end
|
61
72
|
|
62
73
|
# Return an Array of Instance objects. Note: These objects will not have
|
63
74
|
# DNS data because they will still be in pending state. The DNS info becomes
|
64
75
|
# available once the instance enters the running state.
|
65
|
-
|
76
|
+
#
|
77
|
+
# +opts+ supports the following parameters:
|
78
|
+
#
|
79
|
+
# * +:ami+
|
80
|
+
# * +:group+
|
81
|
+
# * +:size+
|
82
|
+
# * +:keypair+
|
83
|
+
# * +:address+
|
84
|
+
# * +:private+ true or false (default)
|
85
|
+
# * +:machine_data+
|
86
|
+
# * +:min+ count
|
87
|
+
# * +:max+ count
|
88
|
+
#
|
89
|
+
def create(opts={}, &each_inst)
|
90
|
+
raise NoAMI unless opts[:ami]
|
91
|
+
raise NoGroup unless opts[:group]
|
92
|
+
|
66
93
|
opts = {
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
94
|
+
:size => 'm1.small',
|
95
|
+
:min => 1,
|
96
|
+
:max => nil
|
97
|
+
}.merge(opts)
|
98
|
+
|
99
|
+
old_opts = {
|
100
|
+
:image_id => opts[:ami].to_s,
|
101
|
+
:min_count => opts[:min],
|
102
|
+
:max_count => opts[:max] || opts[:min],
|
103
|
+
:key_name => (opts[:keypair] || '').to_s,
|
104
|
+
:group_id => [opts[:group]].flatten.compact,
|
105
|
+
#:user_data => opts[:machine_data], # Error: Invalid BASE64 encoding of user data ??
|
106
|
+
:availability_zone => opts[:zone].to_s,
|
107
|
+
:addressing_type => opts[:private] ? 'private' : 'public',
|
108
|
+
:instance_type => opts[:size].to_s,
|
76
109
|
:kernel_id => nil
|
77
110
|
}
|
78
|
-
|
79
|
-
|
111
|
+
#p opts[:machine_data]
|
112
|
+
#exit
|
80
113
|
|
81
|
-
|
82
|
-
|
83
|
-
# item:
|
84
|
-
# - groupId: default
|
85
|
-
# requestId: a4de33de-6da1-4f43-a3f5-f987f5f1f1cf
|
86
|
-
# instancesSet:
|
87
|
-
# item:
|
88
|
-
# ... # see Instances.from_hash
|
89
|
-
raise "The request failed to return instance data" unless response['instancesSet'].is_a?(Hash)
|
114
|
+
response = execute_request({}) { @ec2.run_instances(old_opts) }
|
115
|
+
return nil unless response['instancesSet'].is_a?(Hash)
|
90
116
|
instances = response['instancesSet']['item'].collect do |inst|
|
91
117
|
self.class.from_hash(inst)
|
92
118
|
end
|
93
|
-
|
119
|
+
instances.each { |inst|
|
120
|
+
each_inst.call(inst)
|
121
|
+
} if each_inst
|
94
122
|
instances
|
95
123
|
end
|
96
124
|
|
97
|
-
def restart(inst_ids=[],
|
98
|
-
|
99
|
-
|
100
|
-
raise "No matching running instances found" if instances.empty?
|
101
|
-
end
|
102
|
-
|
125
|
+
def restart(inst_ids=[], &each_inst)
|
126
|
+
instances = list(:running, inst_ids, &each_inst) || []
|
127
|
+
raise NoRunningInstances if instances.empty?
|
103
128
|
inst_ids = objects_to_instance_ids(inst_ids)
|
104
|
-
|
105
129
|
response = execute_request({}) {
|
106
|
-
@
|
130
|
+
@ec2.reboot_instances(:instance_id => inst_ids)
|
107
131
|
}
|
108
|
-
|
109
132
|
response['return'] == 'true'
|
110
133
|
end
|
111
134
|
|
112
|
-
def destroy(inst_ids=[],
|
113
|
-
|
114
|
-
|
115
|
-
raise "No matching running instances found" if instances.empty?
|
116
|
-
end
|
135
|
+
def destroy(inst_ids=[], &each_inst)
|
136
|
+
instances = list(:running, inst_ids, &each_inst) || []
|
137
|
+
raise NoRunningInstances if instances.empty?
|
117
138
|
|
118
139
|
inst_ids = objects_to_instance_ids(inst_ids)
|
119
140
|
|
120
141
|
response = execute_request({}) {
|
121
|
-
@
|
142
|
+
@ec2.terminate_instances(:instance_id => inst_ids)
|
122
143
|
}
|
123
144
|
|
124
145
|
#instancesSet:
|
@@ -131,25 +152,24 @@ module Rudy::AWS
|
|
131
152
|
# code: "48"
|
132
153
|
# name: terminated
|
133
154
|
|
134
|
-
raise
|
155
|
+
raise MalformedResponse unless response['instancesSet'].is_a?(Hash)
|
135
156
|
instances_shutdown = []
|
136
157
|
response['instancesSet']['item'].collect do |inst|
|
137
158
|
next unless inst['shutdownState'].is_a?(Hash) && inst['shutdownState']['name'] == 'shutting-down'
|
138
159
|
instances_shutdown << inst['instanceId']
|
139
160
|
end
|
140
161
|
success = instances_shutdown.size == inst_ids.size
|
141
|
-
#puts "SUC: #{success} #{instances_shutdown.size} #{inst_ids.size}"
|
142
162
|
success
|
143
163
|
end
|
144
164
|
|
145
|
-
def restart_group(group)
|
146
|
-
instances = list_group(group, :running) || []
|
165
|
+
def restart_group(group, &each_inst)
|
166
|
+
instances = list_group(group, :running, &each_inst) || []
|
147
167
|
inst_ids = objects_to_instance_ids(instances)
|
148
168
|
restart(inst_ids, :skip_check)
|
149
169
|
end
|
150
170
|
|
151
|
-
def destroy_group(group)
|
152
|
-
instances = list_group(group, :running) || []
|
171
|
+
def destroy_group(group, &each_inst)
|
172
|
+
instances = list_group(group, :running, &each_inst) || []
|
153
173
|
inst_ids = objects_to_instance_ids(instances)
|
154
174
|
destroy(inst_ids, :skip_check)
|
155
175
|
end
|
@@ -157,8 +177,8 @@ module Rudy::AWS
|
|
157
177
|
# * +state+ is an optional instance state. If specified, must be one of: running (default), pending, terminated.
|
158
178
|
# * +inst_ids+ is an Array of instance IDs.
|
159
179
|
# Returns an Array of Rudy::AWS::EC2::Instance objects.
|
160
|
-
def list(state=nil, inst_ids=[])
|
161
|
-
instances = list_as_hash(state, inst_ids)
|
180
|
+
def list(state=nil, inst_ids=[], &each_inst)
|
181
|
+
instances = list_as_hash(state, inst_ids, &each_inst)
|
162
182
|
instances &&= instances.values
|
163
183
|
instances = nil if instances && instances.empty? # Don't return an empty hash
|
164
184
|
instances
|
@@ -167,9 +187,8 @@ module Rudy::AWS
|
|
167
187
|
# * +group+ is a security group name.
|
168
188
|
# * +state+ is an optional instance state. If specified, must be one of: running (default), pending, terminated.
|
169
189
|
# * +inst_ids+ is an Array of instance IDs.
|
170
|
-
def list_group(group=nil, state=nil, inst_ids=[])
|
171
|
-
|
172
|
-
instances = list_group_as_hash(group, state, inst_ids)
|
190
|
+
def list_group(group=nil, state=nil, inst_ids=[], &each_inst)
|
191
|
+
instances = list_group_as_hash(group, state, inst_ids, &each_inst)
|
173
192
|
instances &&= instances.values
|
174
193
|
instances = nil if instances && instances.empty? # Don't return an empty hash
|
175
194
|
instances
|
@@ -179,11 +198,13 @@ module Rudy::AWS
|
|
179
198
|
# * +group+ is a security group name.
|
180
199
|
# * +state+ is an optional instance state. If specified, must be one of: running (default), pending, terminated.
|
181
200
|
# * +inst_ids+ is an Array of instance IDs.
|
182
|
-
def list_group_as_hash(group=nil, state=nil, inst_ids=[])
|
183
|
-
raise "No group specified" unless group
|
201
|
+
def list_group_as_hash(group=nil, state=nil, inst_ids=[], &each_inst)
|
184
202
|
instances = list_as_hash(state, inst_ids)
|
185
203
|
# Remove instances that are not in the specified group
|
186
|
-
|
204
|
+
if instances
|
205
|
+
instances = instances.reject { |id,inst| !inst.groups.member?(group) } if group
|
206
|
+
instances.each_value { |inst| each_inst.call(inst) } if each_inst
|
207
|
+
end
|
187
208
|
instances = nil if instances && instances.empty? # Don't return an empty hash
|
188
209
|
instances
|
189
210
|
end
|
@@ -192,7 +213,8 @@ module Rudy::AWS
|
|
192
213
|
# one of: running (default), pending, terminated, any
|
193
214
|
# * +inst_ids+ is an Array of instance IDs or Rudy::AWS::EC2::Instance objects.
|
194
215
|
# Returns a Hash of Rudy::AWS::EC2::Instance objects. The key is the instance ID.
|
195
|
-
|
216
|
+
# * +each_inst+ a block to execute for every instance in the list.
|
217
|
+
def list_as_hash(state=nil, inst_ids=[], &each_inst)
|
196
218
|
state &&= state.to_sym
|
197
219
|
state = nil if state == :any
|
198
220
|
raise "Unknown state: #{state}" if state && !Instances.known_state?(state)
|
@@ -203,7 +225,7 @@ module Rudy::AWS
|
|
203
225
|
inst_ids = objects_to_instance_ids(inst_ids)
|
204
226
|
|
205
227
|
response = execute_request({}) {
|
206
|
-
@
|
228
|
+
@ec2.describe_instances(:instance_id => inst_ids)
|
207
229
|
}
|
208
230
|
|
209
231
|
# requestId: c16878ac-28e4-4859-9878-ef93af45789c
|
@@ -225,14 +247,16 @@ module Rudy::AWS
|
|
225
247
|
# And each reservation can have 1 or more instances
|
226
248
|
next unless res['instancesSet'].is_a?(Hash)
|
227
249
|
res['instancesSet']['item'].each do |props|
|
228
|
-
inst =
|
250
|
+
inst = Instances.from_hash(props)
|
229
251
|
next if state && inst.state != state.to_s
|
230
252
|
inst.groups = groups
|
231
253
|
#puts "STATE: #{inst.state} #{state}"
|
232
254
|
instances[inst.awsid] = inst
|
233
255
|
end
|
234
256
|
end
|
235
|
-
|
257
|
+
|
258
|
+
instances.each_value { |inst| each_inst.call(inst) } if each_inst
|
259
|
+
|
236
260
|
instances = nil if instances.empty? # Don't return an empty hash
|
237
261
|
instances
|
238
262
|
end
|
@@ -250,10 +274,10 @@ module Rudy::AWS
|
|
250
274
|
# require 'base64'
|
251
275
|
# Base64.decode64(output)
|
252
276
|
#
|
253
|
-
def
|
277
|
+
def console(inst_id, &each_inst)
|
254
278
|
inst_ids = objects_to_instance_ids([inst_id])
|
255
279
|
response = execute_request({}) {
|
256
|
-
@
|
280
|
+
@ec2.get_console_output(:instance_id => inst_ids.first)
|
257
281
|
}
|
258
282
|
response['output']
|
259
283
|
end
|
@@ -267,8 +291,10 @@ module Rudy::AWS
|
|
267
291
|
end
|
268
292
|
|
269
293
|
def volumes(id)
|
270
|
-
|
271
|
-
|
294
|
+
rvol = Rudy::AWS::EC2::Volumes.new
|
295
|
+
rvol.ec2 = @ec2
|
296
|
+
rvol.list || []
|
297
|
+
list.select { |v| v.attached? && v.instid === id }
|
272
298
|
end
|
273
299
|
|
274
300
|
def device_volume(id, device)
|
@@ -279,9 +305,9 @@ module Rudy::AWS
|
|
279
305
|
# Returns an Instance object
|
280
306
|
def get(inst_id)
|
281
307
|
inst_id = inst_id.awsid if inst_id.is_a?(Rudy::AWS::EC2::Instance)
|
282
|
-
inst = list(:any, inst_id)
|
283
|
-
|
284
|
-
inst
|
308
|
+
inst = list(:any, inst_id)
|
309
|
+
inst &&= inst.first
|
310
|
+
inst
|
285
311
|
end
|
286
312
|
|
287
313
|
def any?(state=:any, inst_ids=[])
|
@@ -348,9 +374,9 @@ module Rudy::AWS
|
|
348
374
|
inst.launch_time = h['launchTime']
|
349
375
|
inst.keyname = h['keyName']
|
350
376
|
inst.launch_index = h['amiLaunchIndex']
|
351
|
-
inst.
|
352
|
-
inst.
|
353
|
-
inst.
|
377
|
+
inst.size = h['instanceType']
|
378
|
+
inst.dns_private = h['privateDnsName']
|
379
|
+
inst.dns_public = h['dnsName']
|
354
380
|
inst.reason = h['reason']
|
355
381
|
inst.zone = h['placement']['availabilityZone']
|
356
382
|
inst.awsid = h['instanceId']
|
@@ -394,7 +420,7 @@ module Rudy::AWS
|
|
394
420
|
inst_ids = [inst_ids].flatten # Make sure it's an Array
|
395
421
|
inst_ids = inst_ids.collect do |inst|
|
396
422
|
next if inst.nil? || inst.to_s.empty?
|
397
|
-
if !inst.is_a?(Rudy::AWS::EC2::Instance) && !Rudy.is_id?(:instance, inst)
|
423
|
+
if !inst.is_a?(Rudy::AWS::EC2::Instance) && !Rudy::Utils.is_id?(:instance, inst)
|
398
424
|
raise %Q("#{inst}" is not an instance ID or object)
|
399
425
|
end
|
400
426
|
inst.is_a?(Rudy::AWS::EC2::Instance) ? inst.awsid : inst
|
@@ -404,4 +430,5 @@ module Rudy::AWS
|
|
404
430
|
|
405
431
|
end
|
406
432
|
end
|
407
|
-
end
|
433
|
+
end
|
434
|
+
|
data/lib/rudy/aws/ec2/keypair.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
require 'rye'
|
2
1
|
|
3
2
|
module Rudy::AWS
|
4
|
-
|
3
|
+
module EC2
|
5
4
|
|
6
5
|
class KeyPair < Storable
|
7
|
-
attr_accessor :private_key # not a storable field
|
8
6
|
|
9
7
|
field :name
|
10
8
|
field :fingerprint
|
9
|
+
field :private_key
|
11
10
|
|
12
|
-
def
|
13
|
-
"%-20s %s" % [self.name, self.fingerprint]
|
11
|
+
def liner_note
|
12
|
+
"%-20s %s" % [self.name.bright, self.fingerprint]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s(titles=false)
|
16
|
+
str = titles ? "%-20s %s#{$/}" % ['name', 'fingerprint'] : ""
|
17
|
+
str << liner_note
|
14
18
|
end
|
15
19
|
|
16
20
|
def public_key
|
@@ -23,17 +27,18 @@ module Rudy::AWS
|
|
23
27
|
|
24
28
|
class KeyPairs
|
25
29
|
include Rudy::AWS::ObjectBase
|
30
|
+
include Rudy::AWS::EC2::Base
|
26
31
|
|
27
32
|
def create(name)
|
28
33
|
raise "No name provided" unless name
|
29
|
-
ret = @
|
34
|
+
ret = @ec2.create_keypair(:key_name => name)
|
30
35
|
self.class.from_hash(ret)
|
31
36
|
end
|
32
37
|
|
33
38
|
def destroy(name)
|
34
39
|
name = name.name if name.is_a?(Rudy::AWS::EC2::KeyPair)
|
35
40
|
raise "No name provided" unless name.is_a?(String)
|
36
|
-
ret = @
|
41
|
+
ret = @ec2.delete_keypair(:key_name => name)
|
37
42
|
(ret && ret['return'] == 'true') # BUG? Always returns true
|
38
43
|
end
|
39
44
|
|
@@ -45,7 +50,7 @@ module Rudy::AWS
|
|
45
50
|
|
46
51
|
def list_as_hash(*names)
|
47
52
|
names = names.flatten
|
48
|
-
klist = @
|
53
|
+
klist = @ec2.describe_keypairs(:key_name => names)
|
49
54
|
return unless klist['keySet'].is_a?(Hash)
|
50
55
|
keypairs = {}
|
51
56
|
klist['keySet']['item'].each do |oldkp|
|
@@ -80,13 +85,20 @@ module Rudy::AWS
|
|
80
85
|
end
|
81
86
|
|
82
87
|
def exists?(name)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
88
|
+
return false unless name
|
89
|
+
kp = get(name) rescue nil
|
90
|
+
!kp.nil?
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
class Keypairs
|
96
|
+
def initialize(*args)
|
97
|
+
raise "Oops! The correct class uses a capital 'P': Rudy::AWS::EC2::KeyPairs"
|
89
98
|
end
|
90
99
|
end
|
100
|
+
|
91
101
|
end
|
92
102
|
end
|
103
|
+
|
104
|
+
|
@@ -1,16 +1,24 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
module Rudy::AWS
|
4
|
-
|
4
|
+
module EC2
|
5
5
|
class Snapshot < Storable
|
6
|
+
@@sformat = "%s <- %10s; %s"
|
7
|
+
|
6
8
|
field :awsid
|
7
9
|
field :progress
|
8
10
|
field :created
|
9
11
|
field :volid
|
10
12
|
field :status
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
+
def liner_note
|
15
|
+
t = Time.parse(@created)
|
16
|
+
info = t.strftime("%Y-%m-%d %H:%M:%S")
|
17
|
+
"%s (%s)" % [(self.awsid || '').bright, info]
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s(with_title=false)
|
21
|
+
@@sformat % [liner_note, @volid, @status]
|
14
22
|
end
|
15
23
|
|
16
24
|
def completed?
|
@@ -21,16 +29,18 @@ module Rudy::AWS
|
|
21
29
|
|
22
30
|
class Snapshots
|
23
31
|
include Rudy::AWS::ObjectBase
|
24
|
-
|
32
|
+
include Rudy::AWS::EC2::Base
|
25
33
|
|
26
|
-
def list(
|
34
|
+
def list(snap_id=[])
|
27
35
|
snapshots = list_as_hash(snap_id)
|
28
|
-
|
36
|
+
if snapshots
|
37
|
+
snapshots = snapshots.values.sort { |a,b| a.created <=> b.created }
|
38
|
+
end
|
29
39
|
snapshots
|
30
40
|
end
|
31
|
-
def list_as_hash(
|
32
|
-
snap_id = snap_id.flatten
|
33
|
-
slist = @
|
41
|
+
def list_as_hash(snap_id=[])
|
42
|
+
snap_id = [snap_id].flatten.compact
|
43
|
+
slist = @ec2.describe_snapshots(:snapshot_id => snap_id)
|
34
44
|
return unless slist['snapshotSet'].is_a?(Hash)
|
35
45
|
snapshots = {}
|
36
46
|
slist['snapshotSet']['item'].each do |snap|
|
@@ -42,12 +52,13 @@ module Rudy::AWS
|
|
42
52
|
|
43
53
|
def create(vol_id)
|
44
54
|
vol_id = (vol_id.is_a?(Rudy::AWS::EC2::Volume)) ? vol_id.awsid : vol_id
|
45
|
-
|
46
|
-
|
55
|
+
shash = @ec2.create_snapshot(:volume_id => vol_id)
|
56
|
+
snap = Snapshots.from_hash(shash)
|
57
|
+
snap
|
47
58
|
end
|
48
59
|
|
49
60
|
def destroy(snap_id)
|
50
|
-
ret = @
|
61
|
+
ret = @ec2.delete_snapshot(:snapshot_id => snap_id)
|
51
62
|
(ret && ret['return'] == 'true')
|
52
63
|
end
|
53
64
|
|