rudy 0.8.5 → 0.9.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 +110 -18
- data/README.rdoc +40 -44
- data/Rudyfile +35 -50
- data/bin/rudy +88 -57
- data/bin/rudy-ec2 +2 -16
- data/bin/rudy-s3 +0 -10
- data/bin/rudy-sdb +11 -12
- data/lib/rudy.rb +59 -91
- data/lib/rudy/aws.rb +4 -45
- data/lib/rudy/aws/ec2.rb +57 -20
- data/lib/rudy/aws/ec2/address.rb +10 -11
- data/lib/rudy/aws/ec2/group.rb +10 -9
- data/lib/rudy/aws/ec2/image.rb +8 -8
- data/lib/rudy/aws/ec2/instance.rb +18 -19
- data/lib/rudy/aws/ec2/keypair.rb +14 -19
- data/lib/rudy/aws/ec2/snapshot.rb +16 -9
- data/lib/rudy/aws/ec2/volume.rb +39 -26
- data/lib/rudy/aws/ec2/zone.rb +5 -4
- data/lib/rudy/aws/s3.rb +2 -1
- data/lib/rudy/aws/sdb.rb +35 -86
- data/lib/rudy/backups.rb +24 -0
- data/lib/rudy/cli.rb +5 -131
- data/lib/rudy/cli/aws/ec2/addresses.rb +19 -27
- data/lib/rudy/cli/aws/ec2/candy.rb +45 -20
- data/lib/rudy/cli/aws/ec2/groups.rb +9 -13
- data/lib/rudy/cli/aws/ec2/images.rb +5 -133
- data/lib/rudy/cli/aws/ec2/instances.rb +25 -25
- data/lib/rudy/cli/aws/ec2/keypairs.rb +7 -11
- data/lib/rudy/cli/aws/ec2/snapshots.rb +5 -9
- data/lib/rudy/cli/aws/ec2/volumes.rb +22 -23
- data/lib/rudy/cli/aws/ec2/zones.rb +2 -3
- data/lib/rudy/cli/aws/sdb/domains.rb +5 -6
- data/lib/rudy/cli/aws/sdb/objects.rb +33 -0
- data/lib/rudy/cli/aws/sdb/select.rb +23 -0
- data/lib/rudy/cli/backups.rb +38 -0
- data/lib/rudy/cli/base.rb +104 -0
- data/lib/rudy/cli/candy.rb +1 -2
- data/lib/rudy/cli/config.rb +20 -7
- data/lib/rudy/cli/disks.rb +7 -9
- data/lib/rudy/cli/execbase.rb +56 -0
- data/lib/rudy/cli/machines.rb +242 -45
- data/lib/rudy/cli/metadata.rb +24 -10
- data/lib/rudy/cli/networks.rb +34 -0
- data/lib/rudy/cli/routines.rb +32 -6
- data/lib/rudy/cli/status.rb +60 -0
- data/lib/rudy/config.rb +55 -32
- data/lib/rudy/config/objects.rb +44 -30
- data/lib/rudy/disks.rb +25 -0
- data/lib/rudy/exceptions.rb +99 -0
- data/lib/rudy/global.rb +67 -28
- data/lib/rudy/guidelines.rb +3 -2
- data/lib/rudy/huxtable.rb +67 -58
- data/lib/rudy/machines.rb +41 -263
- data/lib/rudy/metadata.rb +212 -38
- data/lib/rudy/metadata/backup.rb +123 -78
- data/lib/rudy/metadata/disk.rb +153 -170
- data/lib/rudy/metadata/machine.rb +179 -0
- data/lib/rudy/mixins.rb +2 -1
- data/lib/rudy/mixins/hash.rb +3 -1
- data/lib/rudy/mixins/symbol.rb +8 -0
- data/lib/rudy/routines.rb +127 -344
- data/lib/rudy/routines/base.rb +229 -0
- data/lib/rudy/routines/handlers/base.rb +48 -0
- data/lib/rudy/routines/handlers/depends.rb +49 -0
- data/lib/rudy/routines/handlers/disks.rb +249 -0
- data/lib/rudy/routines/handlers/group.rb +44 -0
- data/lib/rudy/routines/handlers/host.rb +70 -0
- data/lib/rudy/routines/handlers/keypair.rb +70 -0
- data/lib/rudy/routines/handlers/machines.rb +15 -0
- data/lib/rudy/routines/handlers/script.rb +85 -0
- data/lib/rudy/routines/handlers/user.rb +45 -0
- data/lib/rudy/routines/passthrough.rb +19 -23
- data/lib/rudy/routines/reboot.rb +98 -50
- data/lib/rudy/routines/shutdown.rb +65 -14
- data/lib/rudy/routines/startup.rb +112 -17
- data/lib/rudy/utils.rb +35 -68
- data/rudy.gemspec +82 -25
- data/tryouts/01_mixins/01_hash_tryouts.rb +20 -0
- data/tryouts/10_require_time/10_rudy_tryouts.rb +33 -0
- data/tryouts/10_require_time/15_global_tryouts.rb +58 -0
- data/tryouts/12_config/10_load_config_tryouts.rb +43 -0
- data/tryouts/12_config/20_defaults_tryouts.rb +16 -0
- data/tryouts/12_config/30_accounts_tryouts.rb +17 -0
- data/tryouts/12_config/40_machines_tryouts.rb +53 -0
- data/tryouts/12_config/50_commands_tryouts.rb +17 -0
- data/tryouts/12_config/60_routines_tryouts.rb +16 -0
- data/tryouts/15_huxtable/10_huxtable_tryouts.rb +47 -0
- data/tryouts/15_huxtable/20_user_tryouts.rb +47 -0
- data/tryouts/20_simpledb/10_domains_tryouts.rb +36 -0
- data/tryouts/20_simpledb/20_objects_tryouts.rb +56 -0
- data/tryouts/25_ec2/10_keypairs_tryouts.rb +54 -0
- data/tryouts/25_ec2/20_groups_tryouts.rb +56 -0
- data/tryouts/25_ec2/21_groups_authorize_address_tryouts.rb +53 -0
- data/tryouts/25_ec2/22_groups_authorize_account_tryouts.rb +54 -0
- data/tryouts/25_ec2/30_addresses_tryouts.rb +42 -0
- data/tryouts/25_ec2/40_volumes_tryouts.rb +53 -0
- data/tryouts/25_ec2/50_snapshots_tryouts.rb +75 -0
- data/tryouts/26_ec2_instances/10_instance_tryouts.rb +107 -0
- data/tryouts/26_ec2_instances/50_images_tryouts.rb +7 -0
- data/tryouts/30_metadata/10_include_tryouts.rb +45 -0
- data/tryouts/30_metadata/13_object_tryouts.rb +19 -0
- data/tryouts/30_metadata/50_disk_tryouts.rb +115 -0
- data/tryouts/30_metadata/51_disk_digest_tryouts.rb +24 -0
- data/tryouts/30_metadata/53_disk_list_tryouts.rb +35 -0
- data/tryouts/30_metadata/56_disk_volume_tryouts.rb +68 -0
- data/tryouts/30_metadata/60_backup_tryouts.rb +101 -0
- data/tryouts/30_metadata/63_backup_list_tryouts.rb +38 -0
- data/tryouts/30_metadata/64_backup_disk_tryouts.rb +65 -0
- data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +76 -0
- data/tryouts/30_metadata/70_machine_tryouts.rb +85 -0
- data/tryouts/30_metadata/73_machine_list_tryouts.rb +58 -0
- data/tryouts/30_metadata/76_machine_instance_tryouts.rb +64 -0
- data/tryouts/30_metadata/77_machines_tryouts.rb +45 -0
- data/tryouts/40_routines/10_keypair_handler_tryouts.rb +52 -0
- data/tryouts/40_routines/11_group_handler_tryouts.rb +36 -0
- data/tryouts/80_cli/10_rudyec2_tryouts.rb +8 -0
- data/tryouts/80_cli/60_rudy_tryouts.rb +41 -0
- data/tryouts/exploration/console.rb +91 -0
- data/tryouts/exploration/machine.rb +23 -0
- data/tryouts/failer +6 -0
- metadata +116 -32
- data/bin/ird +0 -153
- data/lib/rudy/metadata/backups.rb +0 -67
- data/lib/rudy/metadata/debug.rb +0 -38
- data/lib/rudy/metadata/disks.rb +0 -67
- data/lib/rudy/metadata/objectbase.rb +0 -108
- data/lib/rudy/routines/helper.rb +0 -76
- data/lib/rudy/routines/helpers/dependshelper.rb +0 -34
- data/lib/rudy/routines/helpers/diskhelper.rb +0 -403
- data/lib/rudy/routines/helpers/scripthelper.rb +0 -197
- data/lib/rudy/routines/helpers/userhelper.rb +0 -37
- data/support/rudy-ec2-startup +0 -200
data/lib/rudy/backups.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rudy
|
2
|
+
|
3
|
+
module Backups
|
4
|
+
RTYPE = 'back'.freeze
|
5
|
+
|
6
|
+
extend self
|
7
|
+
extend Rudy::Metadata::ClassMethods
|
8
|
+
include Rudy::Huxtable
|
9
|
+
extend Rudy::Huxtable
|
10
|
+
|
11
|
+
# Returns the most recent backup object for the given path
|
12
|
+
def get(path)
|
13
|
+
tmp = Rudy::Backup.new path
|
14
|
+
backups = Rudy::Backups.list :path => path
|
15
|
+
return nil unless backups.is_a?(Array) && !backups.empty?
|
16
|
+
backups.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def from_hash(h)
|
20
|
+
Rudy::Backup.from_hash h
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/rudy/cli.rb
CHANGED
@@ -10,6 +10,10 @@ module Rudy
|
|
10
10
|
# line interfaces. See the bin/ files if you're interested.
|
11
11
|
#
|
12
12
|
module CLI
|
13
|
+
|
14
|
+
require 'rudy/cli/execbase'
|
15
|
+
require 'rudy/cli/base'
|
16
|
+
|
13
17
|
class NoCred < RuntimeError #:nodoc
|
14
18
|
end
|
15
19
|
|
@@ -19,92 +23,7 @@ module Rudy
|
|
19
23
|
# Should print messages as they come
|
20
24
|
end
|
21
25
|
|
22
|
-
|
23
|
-
include Rudy::Huxtable
|
24
|
-
|
25
|
-
attr_reader :config
|
26
|
-
|
27
|
-
protected
|
28
|
-
def init
|
29
|
-
|
30
|
-
if Drydock.debug?
|
31
|
-
#Caesars.enable_debug
|
32
|
-
Rudy.enable_debug
|
33
|
-
end
|
34
|
-
|
35
|
-
# The CLI wants output!
|
36
|
-
Rudy::Huxtable.update_logger STDOUT
|
37
|
-
|
38
|
-
# Send The Huxtables the global values from the command-line
|
39
|
-
Rudy::Huxtable.update_global @global
|
40
|
-
|
41
|
-
# Reload configuration. This must come after update_global
|
42
|
-
# so it will catch the @@global.config path (if supplied).
|
43
|
-
begin
|
44
|
-
Rudy::Huxtable.update_config
|
45
|
-
rescue Caesars::SyntaxError => ex
|
46
|
-
STDERR.puts ex.message
|
47
|
-
STDERR.puts ex.backtrace if @@global.verbose > 0
|
48
|
-
exit 81
|
49
|
-
end
|
50
|
-
|
51
|
-
@@global.nocolor ? String.disable_color : String.enable_color
|
52
|
-
@@global.yes ? Annoy.enable_skip : Annoy.disable_skip
|
53
|
-
|
54
|
-
unless @@global.accesskey && @@global.secretkey
|
55
|
-
STDERR.puts "No AWS credentials. Check your configs!"
|
56
|
-
STDERR.puts "Try: rudy init"
|
57
|
-
exit 1
|
58
|
-
end
|
59
|
-
|
60
|
-
if @@global.environment =~ /^prod/ && Drydock.debug?
|
61
|
-
puts Rudy::Utils.banner("PRODUCTION ACCESS IS DISABLED IN DEBUG MODE")
|
62
|
-
exit 1
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def execute_action(emsg="Failed", &action)
|
68
|
-
begin
|
69
|
-
ret = action.call
|
70
|
-
raise emsg unless ret
|
71
|
-
ret
|
72
|
-
rescue Rudy::AWS::EC2::NoAMI => ex
|
73
|
-
raise Drydock::OptError.new('-a', @alias)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def execute_check(level=:medium)
|
78
|
-
ret = Annoy.are_you_sure?(level)
|
79
|
-
exit 0 unless ret
|
80
|
-
ret
|
81
|
-
end
|
82
|
-
|
83
|
-
# Print a default header to the screen for every command.
|
84
|
-
#
|
85
|
-
def print_header
|
86
|
-
|
87
|
-
# Send The Huxtables the global values again because they could be
|
88
|
-
# updated after initialization but before the command was executed
|
89
|
-
Rudy::Huxtable.update_global @global
|
90
|
-
|
91
|
-
puts Rudy::CLI.generate_header(@@global, @@config) if @@global.print_header
|
92
|
-
|
93
|
-
unless @@global.quiet
|
94
|
-
if @@global.environment == "prod"
|
95
|
-
msg = "YOU ARE PLAYING WITH PRODUCTION"
|
96
|
-
puts Rudy::Utils.banner(msg, :normal), $/
|
97
|
-
end
|
98
|
-
puts Rudy::Utils.banner("THIS IS EC2"), $/ if Rudy.in_situ?
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def machine_separator(name, awsid)
|
103
|
-
('%s %-50s awsid: %s ' % [$/, name, awsid]).att(:reverse)
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
26
|
+
|
108
27
|
def self.generate_header(global, config)
|
109
28
|
return "" if global.quiet
|
110
29
|
header = StringIO.new
|
@@ -128,52 +47,7 @@ module Rudy
|
|
128
47
|
end
|
129
48
|
|
130
49
|
|
131
|
-
# A base for all Drydock executables (bin/rudy etc...).
|
132
|
-
class Base
|
133
|
-
extend Drydock
|
134
|
-
|
135
|
-
before do |obj|
|
136
|
-
# Don't print Rudy header unless requested to
|
137
|
-
obj.global.print_header = false if (obj.global.verbose == 0)
|
138
|
-
@start = Time.now
|
139
|
-
end
|
140
|
-
|
141
|
-
after do |obj|
|
142
|
-
if obj.global.verbose > 0
|
143
|
-
puts
|
144
|
-
@elapsed = Time.now - @start
|
145
|
-
puts "Elapsed: %.2f seconds" % @elapsed.to_f if @elapsed > 0.1
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
# These globals are used by all bin/ executables
|
151
|
-
global :A, :accesskey, String, "AWS Access Key"
|
152
|
-
global :S, :secretkey, String, "AWS Secret Access Key"
|
153
|
-
global :R, :region, String, "Amazon service region (ie: #{Rudy::DEFAULT_REGION})"
|
154
|
-
global :z, :zone, String, "Amazon Availability zone (ie: #{Rudy::DEFAULT_ZONE})"
|
155
|
-
global :u, :user, String, "Provide a username (ie: #{Rudy::DEFAULT_USER})"
|
156
|
-
global :k, :pkey, String, "Path to the private SSH key"
|
157
|
-
global :f, :format, String, "Output format"
|
158
|
-
global :n, :nocolor, "Disable output colors"
|
159
|
-
global :C, :config, String, "Specify another configuration file to read (ie: #{Rudy::CONFIG_FILE})"
|
160
|
-
global :Y, :yes, "Assume a correct answer to confirmation questions"
|
161
|
-
global :q, :quiet, "Run with less output"
|
162
|
-
global :O, :offline, "Be cool about the internet being down"
|
163
|
-
global :v, :verbose, "Increase verbosity of output (i.e. -v or -vv or -vvv)" do
|
164
|
-
@verbose ||= 0
|
165
|
-
@verbose += 1
|
166
|
-
end
|
167
|
-
global :V, :version, "Display version number" do
|
168
|
-
puts "Rudy version: #{Rudy::VERSION}"
|
169
|
-
exit 0
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
50
|
end
|
176
|
-
|
177
51
|
end
|
178
52
|
|
179
53
|
Rudy::Utils.require_glob(RUDY_LIB, 'rudy', 'cli', '**', '*.rb')
|
@@ -6,26 +6,24 @@ module AWS; module EC2;
|
|
6
6
|
class Addresses < Rudy::CLI::CommandBase
|
7
7
|
|
8
8
|
def addresses_create
|
9
|
-
|
10
|
-
address = radd.create
|
9
|
+
address = Rudy::AWS::EC2::Addresses.create
|
11
10
|
puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
|
12
11
|
end
|
13
12
|
|
14
13
|
def addresses_destroy_valid?
|
15
14
|
raise Drydock::ArgError.new("IP address", @alias) unless @argv.ipaddress
|
16
|
-
@
|
17
|
-
raise "#{@argv.ipaddress} is
|
18
|
-
raise "#{@argv.ipaddress} is associated!" if @radd.associated?(@argv.ipaddress)
|
15
|
+
raise "#{@argv.ipaddress} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(@argv.ipaddress)
|
16
|
+
raise "#{@argv.ipaddress} is associated!" if Rudy::AWS::EC2::Addresses.associated?(@argv.ipaddress)
|
19
17
|
true
|
20
18
|
end
|
21
19
|
def addresses_destroy
|
22
|
-
address =
|
20
|
+
address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
|
23
21
|
raise "Could not fetch #{address.ipaddress}" unless address
|
24
22
|
|
25
23
|
puts "Destroying address: #{@argv.ipaddress}"
|
26
24
|
puts "NOTE: this IP address will become available to other EC2 customers.".bright
|
27
25
|
execute_check(:medium)
|
28
|
-
execute_action {
|
26
|
+
execute_action { Rudy::AWS::EC2::Addresses.destroy(@argv.ipaddress) }
|
29
27
|
self.addresses
|
30
28
|
end
|
31
29
|
|
@@ -35,24 +33,21 @@ module AWS; module EC2;
|
|
35
33
|
true
|
36
34
|
end
|
37
35
|
def associate_addresses
|
38
|
-
|
39
|
-
rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
40
|
-
|
41
|
-
raise "Instance #{@argv.instid} does not exist!" unless rinst.exists?(@option.instance)
|
36
|
+
raise "Instance #{@argv.instid} does not exist!" unless Rudy::AWS::EC2::Instances.exists?(@option.instance)
|
42
37
|
|
43
38
|
if @option.newaddress
|
44
39
|
print "Creating address... "
|
45
|
-
tmp =
|
40
|
+
tmp = Rudy::AWS::EC2::Addresses.create
|
46
41
|
puts "#{tmp.ipaddress}"
|
47
42
|
address = tmp.ipaddress
|
48
43
|
else
|
49
44
|
address = @argv.ipaddress
|
50
45
|
end
|
51
46
|
|
52
|
-
raise "#{address} is not allocated to you" unless
|
53
|
-
raise "#{address} is already associated!" if
|
47
|
+
raise "#{address} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(address)
|
48
|
+
raise "#{address} is already associated!" if Rudy::AWS::EC2::Addresses.associated?(address)
|
54
49
|
|
55
|
-
instance =
|
50
|
+
instance = Rudy::AWS::EC2::Instances.get(@option.instance)
|
56
51
|
|
57
52
|
# If an instance was recently disassoiciated, the dns_public may
|
58
53
|
# not be updated yet
|
@@ -61,8 +56,8 @@ module AWS; module EC2;
|
|
61
56
|
|
62
57
|
puts "Associating #{address} to #{instance_name} (#{instance.groups.join(', ')})"
|
63
58
|
execute_check(:low)
|
64
|
-
execute_action {
|
65
|
-
address =
|
59
|
+
execute_action { Rudy::AWS::EC2::Addresses.associate(address, instance.awsid) }
|
60
|
+
address = Rudy::AWS::EC2::Addresses.get(address)
|
66
61
|
puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
|
67
62
|
end
|
68
63
|
|
@@ -71,24 +66,21 @@ module AWS; module EC2;
|
|
71
66
|
true
|
72
67
|
end
|
73
68
|
def disassociate_addresses
|
74
|
-
|
75
|
-
|
76
|
-
raise "#{@argv.ipaddress} is not allocated to you" unless radd.exists?(@argv.ipaddress)
|
77
|
-
raise "#{@argv.ipaddress} is not associated!" unless radd.associated?(@argv.ipaddress)
|
69
|
+
raise "#{@argv.ipaddress} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(@argv.ipaddress)
|
70
|
+
raise "#{@argv.ipaddress} is not associated!" unless Rudy::AWS::EC2::Addresses.associated?(@argv.ipaddress)
|
78
71
|
|
79
|
-
address =
|
80
|
-
instance =
|
72
|
+
address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
|
73
|
+
instance = Rudy::AWS::EC2::Instances.get(address.instid)
|
81
74
|
|
82
75
|
puts "Disassociating #{address.ipaddress} from #{instance.awsid} (#{instance.groups.join(', ')})"
|
83
76
|
execute_check(:medium)
|
84
|
-
execute_action {
|
85
|
-
address =
|
77
|
+
execute_action { Rudy::AWS::EC2::Addresses.disassociate(@argv.ipaddress) }
|
78
|
+
address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
|
86
79
|
puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
|
87
80
|
end
|
88
81
|
|
89
82
|
def addresses
|
90
|
-
|
91
|
-
addresses = radd.list || []
|
83
|
+
addresses = Rudy::AWS::EC2::Addresses.list || []
|
92
84
|
|
93
85
|
addresses.each do |address|
|
94
86
|
puts @@global.verbose > 0 ? address.inspect : address.dump(@@global.format)
|
@@ -49,9 +49,8 @@ module AWS; module EC2;
|
|
49
49
|
raise "Insecure permissions for #{@@global.pkey}" unless (File.stat(@@global.pkey).mode & 600) == 0
|
50
50
|
end
|
51
51
|
if @option.group
|
52
|
-
rgroup = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
53
52
|
raise "Cannot supply group and instance ID" if @option.instid
|
54
|
-
raise "Group #{@option.group} does not exist" unless
|
53
|
+
raise "Group #{@option.group} does not exist" unless Rudy::AWS::EC2::Groups.exists?(@option.group)
|
55
54
|
end
|
56
55
|
if @option.instid && !Rudy::Utils.is_id?(:instance, @option.instid)
|
57
56
|
raise "#{@option.instid} is not an instance ID"
|
@@ -65,11 +64,11 @@ module AWS; module EC2;
|
|
65
64
|
opts[:id] = @option.instid if @option.instid
|
66
65
|
|
67
66
|
# Options to be sent to Rye::Box
|
68
|
-
|
67
|
+
rye_opts = { :user => @global.user || Rudy.sysinfo.user, :debug => nil }
|
69
68
|
if @@global.pkey
|
70
69
|
raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
|
71
70
|
raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
|
72
|
-
|
71
|
+
rye_opts[:keys] = @@global.pkey
|
73
72
|
end
|
74
73
|
|
75
74
|
|
@@ -85,25 +84,24 @@ module AWS; module EC2;
|
|
85
84
|
end
|
86
85
|
|
87
86
|
checked = false
|
88
|
-
|
89
|
-
lt = rudy.list_group(opts[:group], :running, opts[:id]) do |inst|
|
87
|
+
lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running, opts[:id]) do |inst|
|
90
88
|
|
91
89
|
# Print header
|
92
90
|
if @@global.quiet
|
93
|
-
print "You are #{
|
91
|
+
print "You are #{rye_opts[:user].bright}. " if !checked # only the 1st
|
94
92
|
else
|
95
|
-
print "Connecting #{
|
93
|
+
print "Connecting #{rye_opts[:user].bright}@#{inst.dns_public} "
|
96
94
|
puts "(#{inst.awsid}, groups: #{inst.groups.join(', ')})"
|
97
95
|
end
|
98
96
|
|
99
97
|
# Make sure we want to run this command on all instances
|
100
98
|
if !checked && command != :interactive_ssh
|
101
|
-
execute_check(:medium) if
|
99
|
+
execute_check(:medium) if rye_opts[:user] == "root"
|
102
100
|
checked = true
|
103
101
|
end
|
104
102
|
|
105
103
|
# Open the connection and run the command
|
106
|
-
rbox = Rye::Box.new(inst.dns_public,
|
104
|
+
rbox = Rye::Box.new(inst.dns_public, rye_opts)
|
107
105
|
ret = rbox.send(command, command_args)
|
108
106
|
puts ret unless command == :interactive_ssh
|
109
107
|
end
|
@@ -125,11 +123,11 @@ module AWS; module EC2;
|
|
125
123
|
opts[:id] &&= [opts[:id]].flatten
|
126
124
|
|
127
125
|
# Options to be sent to Net::SSH
|
128
|
-
|
126
|
+
rye_opts = { :user => @global.user || Rudy.sysinfo.user, :debug => nil }
|
129
127
|
if @@global.pkey
|
130
128
|
raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
|
131
129
|
raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
|
132
|
-
|
130
|
+
rye_opts[:keys] = @@global.pkey
|
133
131
|
end
|
134
132
|
|
135
133
|
opts[:paths] = @argv
|
@@ -143,28 +141,27 @@ module AWS; module EC2;
|
|
143
141
|
|
144
142
|
# Options to be sent to Rye::Box
|
145
143
|
info = @@global.quiet ? nil : STDERR
|
146
|
-
|
144
|
+
rye_opts = { :user => @global.user || Rudy.sysinfo.user, :info => info }
|
147
145
|
if @@global.pkey
|
148
146
|
raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
|
149
147
|
raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
|
150
|
-
|
148
|
+
rye_opts[:keys] = @@global.pkey
|
151
149
|
end
|
152
150
|
|
153
151
|
|
154
152
|
checked = false
|
155
|
-
|
156
|
-
lt = rudy.list_group(opts[:group], :running, opts[:id]) do |inst|
|
153
|
+
lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running, opts[:id]) do |inst|
|
157
154
|
|
158
155
|
if @option.print
|
159
|
-
|
156
|
+
scp_command inst.dns_public, @@global.pkey, opts[:user], opts[:paths], opts[:dest], (opts[:task] == :download), false, @option.print
|
160
157
|
next
|
161
158
|
end
|
162
159
|
|
163
160
|
# Print header
|
164
161
|
if @@global.quiet
|
165
|
-
print "You are #{
|
162
|
+
print "You are #{rye_opts[:user].bright}. " if !checked # only the 1st
|
166
163
|
else
|
167
|
-
print "Connecting #{
|
164
|
+
print "Connecting #{rye_opts[:user].bright}@#{inst.dns_public} "
|
168
165
|
puts "(#{inst.awsid}, groups: #{inst.groups.join(', ')})"
|
169
166
|
end
|
170
167
|
|
@@ -175,7 +172,7 @@ module AWS; module EC2;
|
|
175
172
|
end
|
176
173
|
|
177
174
|
# Open the connection and run the command
|
178
|
-
rbox = Rye::Box.new(inst.dns_public,
|
175
|
+
rbox = Rye::Box.new(inst.dns_public, rye_opts)
|
179
176
|
rbox.send(opts[:task], opts[:paths], opts[:dest])
|
180
177
|
end
|
181
178
|
|
@@ -183,6 +180,34 @@ module AWS; module EC2;
|
|
183
180
|
|
184
181
|
|
185
182
|
|
183
|
+
private
|
184
|
+
|
185
|
+
def scp_command(host, keypair, user, paths, to_path, to_local=false, verbose=false, printonly=false)
|
186
|
+
|
187
|
+
paths = [paths] unless paths.is_a?(Array)
|
188
|
+
from_paths = ""
|
189
|
+
if to_local
|
190
|
+
paths.each do |path|
|
191
|
+
from_paths << "#{user}@#{host}:#{path} "
|
192
|
+
end
|
193
|
+
#puts "Copying FROM remote TO this machine", $/
|
194
|
+
|
195
|
+
else
|
196
|
+
to_path = "#{user}@#{host}:#{to_path}"
|
197
|
+
from_paths = paths.join(' ')
|
198
|
+
#puts "Copying FROM this machine TO remote", $/
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
cmd = "scp -r "
|
203
|
+
cmd << "-i #{keypair}" if keypair
|
204
|
+
cmd << " #{from_paths} #{to_path}"
|
205
|
+
|
206
|
+
puts cmd if verbose
|
207
|
+
printonly ? (puts cmd) : system(cmd)
|
208
|
+
end
|
209
|
+
|
210
|
+
|
186
211
|
|
187
212
|
end
|
188
213
|
|
@@ -7,33 +7,31 @@ module AWS; module EC2;
|
|
7
7
|
|
8
8
|
|
9
9
|
def create_groups_valid?
|
10
|
-
@rgroups = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
11
10
|
raise Drydock::ArgError.new('group name', @alias) unless @argv.name
|
12
|
-
raise "Group #{@argv.name} alread exists" if
|
11
|
+
raise "Group #{@argv.name} alread exists" if Rudy::AWS::EC2::Groups.exists?(@argv.name)
|
13
12
|
true
|
14
13
|
end
|
15
14
|
def create_groups
|
16
15
|
opts = check_options
|
17
16
|
execute_action {
|
18
|
-
|
17
|
+
Rudy::AWS::EC2::Groups.create(@argv.name, @option.description, opts[:addresses], opts[:ports], opts[:protocols])
|
19
18
|
}
|
20
|
-
|
19
|
+
Rudy::AWS::EC2::Groups.list(@argv.name) do |group|
|
21
20
|
puts @@global.verbose > 0 ? group.inspect : group.dump(@@global.format)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
24
|
|
26
25
|
def destroy_groups_valid?
|
27
|
-
@rgroups = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
28
26
|
raise Drydock::ArgError.new('group name', @alias) unless @argv.name
|
29
|
-
raise "Group #{@argv.name} does not exist" unless
|
27
|
+
raise "Group #{@argv.name} does not exist" unless Rudy::AWS::EC2::Groups.exists?(@argv.name)
|
30
28
|
true
|
31
29
|
end
|
32
30
|
|
33
31
|
def destroy_groups
|
34
32
|
puts "Destroying group: #{@argv.name}"
|
35
33
|
execute_check(:medium)
|
36
|
-
execute_action {
|
34
|
+
execute_action { Rudy::AWS::EC2::Groups.destroy(@argv.name) }
|
37
35
|
@argv.clear # so groups will print all other groups
|
38
36
|
groups
|
39
37
|
end
|
@@ -47,8 +45,7 @@ module AWS; module EC2;
|
|
47
45
|
def groups
|
48
46
|
opts = {}
|
49
47
|
name = @option.all ? nil : @argv.name
|
50
|
-
|
51
|
-
rgroups.list(name).each do |group|
|
48
|
+
Rudy::AWS::EC2::Groups.list(name).each do |group|
|
52
49
|
puts @@global.verbose > 0 ? group.inspect : group.dump(@@global.format)
|
53
50
|
end
|
54
51
|
end
|
@@ -69,7 +66,7 @@ module AWS; module EC2;
|
|
69
66
|
end
|
70
67
|
|
71
68
|
raise Drydock::ArgError.new('group name', @alias) unless @argv.name
|
72
|
-
|
69
|
+
true
|
73
70
|
end
|
74
71
|
|
75
72
|
def modify_group(action)
|
@@ -83,13 +80,12 @@ module AWS; module EC2;
|
|
83
80
|
print "on #{opts[:protocols].join(', ').bright} "
|
84
81
|
puts "ports: #{opts[:ports].map { |p| "#{p.join(' to ').bright}" }.join(', ')}"
|
85
82
|
end
|
86
|
-
rgroups = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
|
87
83
|
execute_check(:medium)
|
88
84
|
execute_action {
|
89
85
|
if (@option.group || @option.owner)
|
90
|
-
|
86
|
+
Rudy::AWS::EC2::Groups.send("#{action.to_s}_group", @argv.name, opts[:group], opts[:owner])
|
91
87
|
else
|
92
|
-
|
88
|
+
Rudy::AWS::EC2::Groups.send(action, @argv.name, opts[:addresses], opts[:ports], opts[:protocols])
|
93
89
|
end
|
94
90
|
}
|
95
91
|
groups # prints on the modified group b/c of @argv.name
|