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/bin/rudy
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
|
3
4
|
# = Rudy
|
4
5
|
#
|
5
6
|
# === Not your granparent's deployment tool
|
@@ -8,172 +9,81 @@
|
|
8
9
|
#
|
9
10
|
|
10
11
|
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib') # Put our local lib in first place
|
12
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'highline-1.5.1', 'lib')
|
13
|
+
#%w{amazon-ec2 rye}.each { |dir| $:.unshift File.join(File.dirname(__FILE__), '..', '..', dir, 'lib') }
|
14
|
+
#require 'rubygems'
|
15
|
+
|
16
|
+
#$SAFE = 1 # require is unsafe in Ruby 1.9??
|
11
17
|
|
12
|
-
require 'date'
|
13
18
|
require 'drydock'
|
14
19
|
require 'rudy'
|
15
20
|
require 'rudy/cli'
|
16
21
|
|
17
|
-
# Is there a bug in Ruby 1.9 open-uri?
|
18
|
-
#$ /usr/local/bin/ruby bin/rudy myaddress
|
19
|
-
#/usr/local/lib/ruby/1.9.1/open-uri.rb:260:in `require': Insecure operation - require (SecurityError)
|
20
|
-
#$SAFE = 2
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
# Command-line interface for /bin/rudy
|
24
|
+
class RudyCLI < Rudy::CLI::Base
|
25
|
+
|
26
|
+
# ------------------------------------------ RUDY GLOBALS --------
|
27
|
+
# ------------------------------------------------------------------
|
25
28
|
|
26
|
-
global :A, :accesskey, String, "AWS Access Key"
|
27
|
-
global :S, :secretkey, String, "AWS Secret Access Key"
|
28
|
-
#global :R, :region, String, "Connect to a specific EC2 region (ie: #{Rudy::DEFAULT_REGION})"
|
29
|
-
global :n, :nocolor, "Disable output colors"
|
30
|
-
global :f, :config, String, "Specify another configuration file to read (ie: #{Rudy::RUDY_CONFIG_FILE})"
|
31
|
-
global :z, :zone, String, "Connect to a specific EC2 zone (ie: #{Rudy::DEFAULT_ZONE})"
|
32
29
|
global :e, :environment, String, "Connect to the specified environment (ie: #{Rudy::DEFAULT_ENVIRONMENT})"
|
33
30
|
global :r, :role, String, "Connect to a machine with the specified role (ie: #{Rudy::DEFAULT_ROLE})"
|
34
31
|
global :p, :position, String, "Position in the machine in its group (ie: #{Rudy::DEFAULT_POSITION})"
|
35
|
-
|
36
|
-
|
37
|
-
global :v, :verbose, "Increase verbosity of output (i.e. -v or -vv or -vvv)" do
|
38
|
-
@verbose ||= 0
|
39
|
-
@verbose += 1
|
40
|
-
end
|
41
|
-
global :V, :version, "Display version number" do
|
42
|
-
puts "Rudy version: #{Rudy::VERSION}"
|
43
|
-
exit 0
|
44
|
-
end
|
45
|
-
|
32
|
+
|
33
|
+
|
46
34
|
|
47
35
|
# --------------------------------- RUDY MACHINE COMMANDS --------
|
48
36
|
# ------------------------------------------------------------------
|
49
37
|
|
50
38
|
|
51
|
-
desc "Machine Status"
|
52
|
-
usage "rudy [global options] status [-g group-name] [-s state] [--all] [instance-ID]"
|
53
|
-
option :g, :group, String, "A security group name"
|
54
|
-
option :s, :state, String, "Machine state. One of: running (default), pending, terminated"
|
55
|
-
option :l, :all, "Show all machines in this group, regardless of state."
|
56
|
-
argv :awsid
|
57
|
-
command :status => Rudy::CLI::
|
58
|
-
|
59
|
-
usage "rudy [global options] connect [-g group-name] [-i instance-ID] [cmd]"
|
60
|
-
desc "Open an SSH connection"
|
61
|
-
option :print, "Only print the SSH command, don't connect"
|
62
|
-
option :g, :group, String, "A security group name"
|
63
|
-
option :i, :awsid, String, "An instance ID"
|
64
|
-
argv :cmd
|
65
|
-
command :connect => Rudy::CLI::
|
66
|
-
command_alias :connect, :ssh
|
67
|
-
|
68
|
-
usage "rudy [global options] copy [-p] [-r] source target"
|
69
|
-
desc "Copy files to or from machines. NOTE: You must use quotes when using a tilda for your remote dir ('~/')."
|
70
|
-
option :r, :recursive, "Recursively copy entire directories"
|
71
|
-
option :p, :preserve, "Preserve atimes and ctimes."
|
72
|
-
option :d, :download, "Download FROM the remote machine to the local machine"
|
73
|
-
option :print, "Only print the SSH command, don't connect"
|
74
|
-
option :g, :group, String, "A security group name"
|
75
|
-
option :i, :awsid, String, "An instance ID"
|
76
|
-
command :copy => Rudy::CLI::
|
77
|
-
command_alias :copy, :scp
|
78
|
-
command_alias :copy, :upload
|
79
|
-
command_alias :copy, :download
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
# ----------------------------------- AMAZON EC2 COMMANDS --------
|
84
|
-
# ------------------------------------------------------------------
|
39
|
+
#desc "Machine Status"
|
40
|
+
#usage "rudy [global options] status [-g group-name] [-s state] [--all] [instance-ID]"
|
41
|
+
#option :g, :group, String, "A security group name"
|
42
|
+
#option :s, :state, String, "Machine state. One of: running (default), pending, terminated"
|
43
|
+
#option :l, :all, "Show all machines in this group, regardless of state."
|
44
|
+
#argv :awsid
|
45
|
+
#command :status => Rudy::CLI::Machines
|
46
|
+
#
|
47
|
+
#usage "rudy [global options] connect [-g group-name] [-i instance-ID] [cmd]"
|
48
|
+
#desc "Open an SSH connection"
|
49
|
+
#option :print, "Only print the SSH command, don't connect"
|
50
|
+
#option :g, :group, String, "A security group name"
|
51
|
+
#option :i, :awsid, String, "An instance ID"
|
52
|
+
#argv :cmd
|
53
|
+
#command :connect => Rudy::CLI::Machines
|
54
|
+
#command_alias :connect, :ssh
|
55
|
+
#
|
56
|
+
#usage "rudy [global options] copy [-p] [-r] source target"
|
57
|
+
#desc "Copy files to or from machines. NOTE: You must use quotes when using a tilda for your remote dir ('~/')."
|
58
|
+
#option :r, :recursive, "Recursively copy entire directories"
|
59
|
+
#option :p, :preserve, "Preserve atimes and ctimes."
|
60
|
+
#option :d, :download, "Download FROM the remote machine to the local machine"
|
61
|
+
#option :print, "Only print the SSH command, don't connect"
|
62
|
+
#option :g, :group, String, "A security group name"
|
63
|
+
#option :i, :awsid, String, "An instance ID"
|
64
|
+
#command :copy => Rudy::CLI::Machines
|
65
|
+
#command_alias :copy, :scp
|
66
|
+
#command_alias :copy, :upload
|
67
|
+
#command_alias :copy, :download
|
85
68
|
|
86
|
-
usage "rudy [global options] addresses [-A address instance ID]"
|
87
|
-
desc "Manage Amazon Elastic IP addresses"
|
88
|
-
argv :ipaddress, :instid
|
89
|
-
action :A, :associate, "Associate an IP address to a running instance"
|
90
|
-
action :C, :create, "Create an IP address"
|
91
|
-
action :D, :destroy, "Destroy an IP address"
|
92
|
-
command :addresses => Rudy::CLI::Addresses
|
93
|
-
command_alias :addresses, :address
|
94
|
-
|
95
|
-
usage "rudy [global options] groups [-C -R -A] [-a IP addresses] [-p ports] [group name]"
|
96
|
-
usage "rudy groups -C (create a group)"
|
97
|
-
usage "rudy -e prod groups (list groups in the prod environment)"
|
98
|
-
usage "rudy groups -A -p 81,82,83 (open ports to a group from this machine)"
|
99
|
-
desc "Manage EC2 Security Groups"
|
100
|
-
option :all, "Display all security groups"
|
101
|
-
option :r, :protocols, Array, "Comma-separated list of protocols. One of: tcp (default), udp, icmp"
|
102
|
-
option :p, :ports, Array, "List of comma-separated port ranges in the form FROM:TO (default: 22,80,443)"
|
103
|
-
option :a, :addresses, Array, "List of comma-separated IP addresses (default: your current external IP)"
|
104
|
-
option :g, :group, String, "A group name to authorize or revoke network rule. Must also supply -o!"
|
105
|
-
option :o, :owner, String, "A group owner ID (account number). Must also supply -g!"
|
106
|
-
action :C, :create, "Create a security group"
|
107
|
-
action :D, :destroy, "Destroy a security group"
|
108
|
-
action :A, :authorize, "Authorize a rule for a security group"
|
109
|
-
action :R, :revoke, "Revoke a rule for a security group"
|
110
|
-
argv :name
|
111
|
-
command :group => Rudy::CLI::Groups
|
112
|
-
command_alias :group, :groups
|
113
|
-
|
114
|
-
desc "Manage EC2 Volumes"
|
115
|
-
usage "rudy volumes"
|
116
|
-
usage "rudy volume -C -s size [-d device-path]"
|
117
|
-
usage "rudy volume -A volume-id instance-id"
|
118
|
-
usage "rudy volume -N volume-id"
|
119
|
-
usage "rudy volume -D volume-id"
|
120
|
-
option :s, :size, String, "Size (in GB)"
|
121
|
-
option :d, :device, String, "Device path (default: /dev/sdh)"
|
122
|
-
action :D, :destroy, "Destroy a volume"
|
123
|
-
action :C, :create, "Create a volume"
|
124
|
-
action :A, :attach, "Attach a volume to a running instance"
|
125
|
-
action :N, :detach, "Detach a volume from an instance"
|
126
|
-
argv :volid, :insid
|
127
|
-
command :volume => Rudy::CLI::Volumes
|
128
|
-
command_alias :volume, :volumes
|
129
|
-
|
130
|
-
desc "Manage KeyPairs"
|
131
|
-
usage "rudy keypairs [-C] [-D] [name]"
|
132
|
-
action :D, :destroy, "Destroy KeyPair"
|
133
|
-
action :C, :create, "Create KeyPair"
|
134
|
-
argv :kpname
|
135
|
-
command :keypair => Rudy::CLI::KeyPairs
|
136
|
-
command_alias :keypair, :keypairs
|
137
|
-
|
138
|
-
usage "rudy console [-g group] [instance ID]"
|
139
|
-
desc "Displays system console output for given instance(s)"
|
140
|
-
option :g, :group, String, "A group name to authorize or revoke network rule. Must also supply -o!"
|
141
|
-
argv :awsid
|
142
|
-
command :console => Rudy::CLI::Instances
|
143
69
|
|
144
|
-
desc "Manage Machines"
|
145
|
-
usage "rudy [global options] machines [-g group-name] [-s state] [instance-ID]"
|
146
|
-
option :g, :group, String, "The security group name"
|
147
|
-
option :i, :ami, String, "The machine image ID (ami-)"
|
148
|
-
option :t, :itype, String, "The instance type (default: m1.small)"
|
149
|
-
option :k, :keypair, String, "The SSH keypair to use for launch"
|
150
|
-
option :a, :address, String, "The IP address to associate"
|
151
|
-
action :C, :create, "Create a machine instance"
|
152
|
-
action :D, :destroy, "Destroy a machine instance"
|
153
|
-
argv :awsid
|
154
|
-
command :instance => Rudy::CLI::Instances
|
155
|
-
command_alias :instance, :instances
|
156
|
-
|
157
|
-
#usage "rudy images [-C -i name [-b bucket -a account]] [-D AMI-ID]"
|
158
|
-
#desc "Manage EC2 Machine Images (AMIs)"
|
159
|
-
#option :a, :account, String, "Your Amazon Account Number"
|
160
|
-
#option :i, :image_name, String, "The name of the image" # TODO: change to --ami
|
161
|
-
#option :p, :print, "Print-only (don't execute commands)"
|
162
|
-
#option :b, :bucket_name, String, "The name of the bucket that will store the image"
|
163
|
-
#action :C, :create, "Create an image"
|
164
|
-
##action :P, :prepare, "Prepare a running instance to be used as an image"
|
165
|
-
#action :D, :destroy, "Deregister an image (currently _does not_ remove images files from S3)"
|
166
|
-
#argv :ami
|
167
|
-
#command :images => Rudy::CLI::Images
|
168
|
-
#command_alias :images, :image
|
169
70
|
|
170
71
|
|
171
72
|
# -------------------------------- MISCELLANEOUS COMMANDS --------
|
172
73
|
# ------------------------------------------------------------------
|
173
|
-
|
74
|
+
|
75
|
+
desc "Display time (in UTC)"
|
76
|
+
option :l, :local, "Display local time"
|
77
|
+
command :time do |obj|
|
78
|
+
t = obj.option.local ? Time.now : Time.now.utc
|
79
|
+
puts '%s' % t.strftime("%Y-%m-%d %T %Z (%z)")
|
80
|
+
end
|
81
|
+
|
174
82
|
usage "rudy [-f config-file] config [param-name]"
|
175
83
|
desc "Check Rudy configuration."
|
176
84
|
option :l, :all, "Display configs for all machines"
|
85
|
+
option :s, :script, "Output configuration identical to what is provided to scripts called in routines"
|
86
|
+
option :r, :rudy, "Output a skeleton Rudyfile"
|
177
87
|
option :d, :defaults, "Display the default value for the supplied parameter"
|
178
88
|
option :g, :group, String, "Display configuration for a specific group"
|
179
89
|
argv :name
|
@@ -193,6 +103,7 @@ module RudyCLI
|
|
193
103
|
puts "%10s: %s" % ['Internal', ia] unless obj.option.external && !obj.option.internal
|
194
104
|
puts "%10s: %s" % ['External', ea] unless obj.option.internal && !obj.option.external
|
195
105
|
end
|
106
|
+
obj.global.quiet = true # don't print elapsed time
|
196
107
|
end
|
197
108
|
|
198
109
|
usage "rudy [global options] annoy [-h -m -l] [-e]"
|
@@ -210,20 +121,22 @@ module RudyCLI
|
|
210
121
|
factor = [:insane, :high, :medium, :low].detect { |v| obj.option.send(v) } || :medium
|
211
122
|
success = Annoy.challenge?("Is this annoying?", factor, flavor)
|
212
123
|
puts (success ? "Correct!" : "WRONG!").bright
|
124
|
+
obj.global.quiet = true # don't print elapsed time
|
213
125
|
end
|
214
126
|
|
215
127
|
desc "Display the current Rudy slogan"
|
216
|
-
command :slogan do
|
128
|
+
command :slogan do |obj|
|
217
129
|
puts "Rudy: Not your grandparent's deployment tool!"
|
130
|
+
obj.global.quiet = true # don't print elapsed time
|
218
131
|
end
|
219
132
|
|
220
|
-
desc "Generates a configuration template to #{Rudy::
|
133
|
+
desc "Generates a configuration template to #{Rudy::CONFIG_FILE}"
|
221
134
|
command :generate_config do |obj|
|
222
|
-
unless File.exists?(Rudy::
|
135
|
+
unless File.exists?(Rudy::CONFIG_FILE)
|
223
136
|
Rudy::Config.init_config_dir
|
224
|
-
puts "Add your AWS credentials to #{Rudy::
|
137
|
+
puts "Add your AWS credentials to #{Rudy::CONFIG_FILE}"
|
225
138
|
else
|
226
|
-
puts "#{Rudy::
|
139
|
+
puts "#{Rudy::CONFIG_FILE} already exists"
|
227
140
|
end
|
228
141
|
end
|
229
142
|
|
@@ -231,71 +144,35 @@ module RudyCLI
|
|
231
144
|
desc "Initialize Rudy configuration"
|
232
145
|
command :init do |obj|
|
233
146
|
|
234
|
-
unless File.exists?(Rudy::
|
147
|
+
unless File.exists?(Rudy::CONFIG_FILE)
|
235
148
|
Rudy::Config.init_config_dir
|
236
149
|
end
|
237
150
|
|
238
151
|
begin
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
rdom.create
|
152
|
+
|
153
|
+
unless Rudy::Huxtable.domain_exists?
|
154
|
+
puts "Creating SimpleDB domain #{Rudy::Huxtable.domain}"
|
155
|
+
Rudy::Huxtable.create_domain
|
244
156
|
puts "Initialized"
|
245
157
|
else
|
246
158
|
puts "Already Initialized"
|
247
159
|
end
|
248
160
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
rescue Rudy::NoConfig => ex
|
161
|
+
rescue Rudy::AWS::SDB::NoSecretKey,
|
162
|
+
Rudy::AWS::SDB::NoAccessKey,
|
163
|
+
Rudy::NoConfig => ex
|
253
164
|
puts "AWS credentials must be configured to continue."
|
254
|
-
puts "You can modify these in #{Rudy::
|
165
|
+
puts "You can modify these in #{Rudy::CONFIG_FILE}"
|
255
166
|
exit 1
|
256
167
|
end
|
257
168
|
|
258
|
-
|
259
|
-
|
169
|
+
obj.global.quiet = true # don't print elapsed time
|
260
170
|
end
|
261
171
|
|
262
|
-
desc "Displays the SimpleDB domains associated to your account"
|
263
|
-
command :domains => Rudy::CLI::Domains
|
264
|
-
|
265
172
|
|
266
173
|
# --------------------------------- RUDY MANAGER COMMANDS --------
|
267
174
|
# ------------------------------------------------------------------
|
268
175
|
|
269
|
-
#usage "rudy init"
|
270
|
-
#desc "Run this the first time you use Rudy (it's immutable so running it again does no harm)."
|
271
|
-
#command :create_domain => Rudy::CLI::Manager
|
272
|
-
#
|
273
|
-
#usage "rudy info"
|
274
|
-
#desc "Displays info about the current Rudy configuration"
|
275
|
-
#command :info => Rudy::CLI::Manager
|
276
|
-
|
277
|
-
#desc "Update a Machine Group with the current version of Rudy"
|
278
|
-
#option :g, :group, String, "A security group name"
|
279
|
-
#command :update => Rudy::CLI::Manager
|
280
|
-
|
281
|
-
|
282
|
-
#usage "#{$/} [global options] disks [-C -p path -d device -s size] [-A] [-D] [path]"
|
283
|
-
#desc "Manage Disks"
|
284
|
-
#option :l, :all, "Display all disk definitions"
|
285
|
-
#option :i, :awsid, String, "EC2 Instance ID"
|
286
|
-
#option :g, :group, String, "Machine group name"
|
287
|
-
#option :p, :path, String, "The filesystem path to use as the mount point"
|
288
|
-
#option :d, :device, String, "The device id (default: /dev/sdh)"
|
289
|
-
#option :s, :size, Integer, "The size of disk (in GB)"
|
290
|
-
#action :C, :create, "Create a disk definition"
|
291
|
-
#action :D, :destroy, "Destroy a disk definition"
|
292
|
-
#action :A, :attach, "Attach a disk"
|
293
|
-
#action :N, :unattach, "Unattach a disk"
|
294
|
-
#argv :diskname
|
295
|
-
#command :disk => Rudy::CLI::Disks
|
296
|
-
#command_alias :disk, :disks
|
297
|
-
|
298
|
-
|
299
176
|
#usage "rudy [global options] backups [-C] [disk name]"
|
300
177
|
#desc "Manage Backups"
|
301
178
|
#option :s, :snapshot, String, "Create a backup entry from an existing snapshot"
|
@@ -306,13 +183,34 @@ module RudyCLI
|
|
306
183
|
#argv :disk
|
307
184
|
#command :'backup' => Rudy::CLI::Backups
|
308
185
|
#command_alias :backup, :bu
|
186
|
+
|
187
|
+
desc "Startup a machine group"
|
188
|
+
usage "rudy startup"
|
189
|
+
command :startup => Rudy::CLI::Routines
|
190
|
+
command_alias :startup, :s
|
191
|
+
|
192
|
+
desc "Shutdown a machine group"
|
193
|
+
usage "rudy shutdown"
|
194
|
+
command :shutdown => Rudy::CLI::Routines
|
195
|
+
|
196
|
+
desc "Create a release"
|
197
|
+
usage "rudy release"
|
198
|
+
command :release => Rudy::CLI::Routines
|
199
|
+
command_alias :release, :r
|
309
200
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
201
|
+
desc "Manage Machines"
|
202
|
+
action :W, :wash, "Wash machine metadata."
|
203
|
+
command :machines => Rudy::CLI::Machines
|
204
|
+
command_alias :machines, :m
|
205
|
+
|
206
|
+
desc "Log in to a machine"
|
207
|
+
command :ssh => Rudy::CLI::Machines
|
208
|
+
|
209
|
+
desc "Manage Disks"
|
210
|
+
action :W, :wash, "Wash disk metadata."
|
211
|
+
command :disks => Rudy::CLI::Disks
|
212
|
+
command_alias :disks, :d
|
213
|
+
|
316
214
|
# -------------------------- RUDY RELEASE/DEPLOY COMMANDS --------
|
317
215
|
# ------------------------------------------------------------------
|
318
216
|
|
@@ -350,20 +248,30 @@ module RudyCLI
|
|
350
248
|
#command :restart => Rudy::CLI::Routines
|
351
249
|
#
|
352
250
|
|
353
|
-
|
354
|
-
|
251
|
+
|
355
252
|
# ------------------------------------------- UGLY STUFFS --------
|
356
253
|
# ------------------------------------------------------------------
|
357
254
|
debug :off
|
358
|
-
default :
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
255
|
+
default :machines
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
# We call Drydock specifically otherwise it will run at_exit. Rye also
|
262
|
+
# uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
|
263
|
+
# blocks in reverse order so if Drydock is required first, it's block
|
264
|
+
# will run after Rye shuts down the ssh-agent.
|
265
|
+
begin
|
266
|
+
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
267
|
+
rescue Drydock::ArgError, Drydock::OptError=> ex
|
268
|
+
STDERR.puts ex.message
|
269
|
+
STDERR.puts ex.usage
|
270
|
+
rescue Rudy::Error => ex
|
271
|
+
STDERR.puts ex.message
|
272
|
+
rescue => ex
|
273
|
+
STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
|
274
|
+
STDERR.puts ex.backtrace if Drydock.debug?
|
275
|
+
rescue SystemExit
|
276
|
+
# Don't balk
|
369
277
|
end
|
data/bin/rudy-ec2
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# = Rudy EC2
|
4
|
+
#
|
5
|
+
# === A Rudy interface to Amazon EC2
|
6
|
+
#
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# See rudy-ec2 -h for usage
|
10
|
+
#
|
11
|
+
|
12
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib') # Put our local lib in first place
|
13
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'highline-1.5.1', 'lib')
|
14
|
+
#%w{net-scp amazon-ec2 caesars rye}.each { |dir| $:.unshift File.join(File.dirname(__FILE__), '..', '..', dir, 'lib') }
|
15
|
+
#require 'rubygems'
|
16
|
+
|
17
|
+
require 'rudy'
|
18
|
+
require 'rudy/cli'
|
19
|
+
|
20
|
+
require 'drydock'
|
21
|
+
|
22
|
+
# Command-line interface for bin/rudy-ec2
|
23
|
+
module RudyCLI_EC2
|
24
|
+
extend Drydock
|
25
|
+
|
26
|
+
|
27
|
+
# ----------------------------------- AMAZON EC2 COMMANDS --------
|
28
|
+
# ------------------------------------------------------------------
|
29
|
+
|
30
|
+
desc "Amazon EC2 Elastic IP addresses"
|
31
|
+
usage "rudy-ec2 addresses"
|
32
|
+
usage "rudy-ec2 addresses -A -i instance-id address"
|
33
|
+
usage "rudy-ec2 addresses -A -i instance-id -n"
|
34
|
+
usage "rudy-ec2 addresses -N address"
|
35
|
+
usage "rudy-ec2 addresses -D address"
|
36
|
+
usage "rudy-ec2 addresses -C"
|
37
|
+
option :i, :instance, String, "Instance ID"
|
38
|
+
option :n, :newaddress, "Create and assign a new elastic IP"
|
39
|
+
action :A, :associate, "Associate an IP address to a running instance"
|
40
|
+
action :N, :disassociate, "Disassociate an IP address from an instance"
|
41
|
+
action :C, :create, "Request an IP address from Amazon"
|
42
|
+
action :D, :destroy, "Return an IP address to Amazon (this is permanent!)"
|
43
|
+
argv :ipaddress
|
44
|
+
command :addresses => Rudy::CLI::AWS::EC2::Addresses
|
45
|
+
command_alias :addresses, :address
|
46
|
+
command_alias :addresses, :a
|
47
|
+
|
48
|
+
desc "Amazon EC2 instance console output"
|
49
|
+
usage "rudy-ec2 console [-g group] [instance ID]"
|
50
|
+
option :g, :group, String, "A security group name"
|
51
|
+
argv :awsid
|
52
|
+
command :consoles => Rudy::CLI::AWS::EC2::Instances
|
53
|
+
command_alias :consoles, :console
|
54
|
+
command_alias :consoles, :c
|
55
|
+
|
56
|
+
desc "Copy files to or from machines."
|
57
|
+
usage "rudy-ec2 copy [-p] [-r] [-u user] [-k path/2/privatekey] source target"
|
58
|
+
usage "rudy-ec2 upload -k path/2/privatekey -u username local-source target"
|
59
|
+
usage "rudy-ec2 download remote-source target"
|
60
|
+
usage "NOTE: Use quotes when using a tilda or asterisk in remote paths ('~/')."
|
61
|
+
usage "rudy-ec2 download '~/*' /tmp/"
|
62
|
+
option :r, :recursive, "Recursively copy entire directories"
|
63
|
+
option :p, :preserve, "Preserve atimes and ctimes."
|
64
|
+
option :d, :download, "Download FROM the remote machine to the local machine"
|
65
|
+
option :print, "Only print the SSH command, don't connect"
|
66
|
+
option :g, :group, String, "A security group name"
|
67
|
+
option :i, :awsid, String, "An instance ID"
|
68
|
+
option :u, :user, String, "Username"
|
69
|
+
command :copy => Rudy::CLI::AWS::EC2::Candy
|
70
|
+
command_alias :copy, :ul
|
71
|
+
command_alias :copy, :dl
|
72
|
+
command_alias :copy, :scp
|
73
|
+
command_alias :copy, :upload
|
74
|
+
command_alias :copy, :download
|
75
|
+
|
76
|
+
desc "Amazon EC2 EC2 Security Groups"
|
77
|
+
usage "rudy-ec2 groups"
|
78
|
+
usage "rudy-ec2 groups -C [-p ports] [-a addresses] [-r protocols] name"
|
79
|
+
usage "rudy-ec2 groups -A [-p ports] [-a addresses] [-r protocols] name"
|
80
|
+
usage "rudy-ec2 groups -A -p 81,8000-9000 -a 127.0.0.1,127.0.0.2 name"
|
81
|
+
usage "rudy-ec2 groups -A -g default -o 123456789012 name"
|
82
|
+
usage "rudy-ec2 groups -R -g default name"
|
83
|
+
usage "rudy-ec2 groups -D name"
|
84
|
+
option :all, "Display all security groups"
|
85
|
+
option :r, :protocols, Array, "List of protocols. One of: tcp (default), udp, icmp"
|
86
|
+
option :p, :ports, Array, "List of port ranges (default: 22,80,443)"
|
87
|
+
option :a, :addresses, Array, "List of IP addresses (default: your current external IP)"
|
88
|
+
option :g, :group, String, "Other group to authorize or revoke. Use with -o!"
|
89
|
+
option :o, :owner, String, "Other group owner ID (account number). Use with -g!"
|
90
|
+
option :d, :description, String, "A group description"
|
91
|
+
action :C, :create, "Create a security group"
|
92
|
+
action :D, :destroy, "Destroy a security group"
|
93
|
+
action :A, :authorize, "Authorize a rule for a security group"
|
94
|
+
action :R, :revoke, "Revoke a rule for a security group"
|
95
|
+
argv :name
|
96
|
+
command :groups => Rudy::CLI::AWS::EC2::Groups
|
97
|
+
command_alias :groups, :group
|
98
|
+
command_alias :groups, :g
|
99
|
+
|
100
|
+
desc "Amazon EC2 Machine Images (AMIs)"
|
101
|
+
usage "rudy-ec2 im"
|
102
|
+
usage "rudy-ec2 image"
|
103
|
+
usage "rudy-ec2 images image-id"
|
104
|
+
usage "rudy-ec2 images -o 123456789012"
|
105
|
+
usage "rudy-ec2 images -o amazon"
|
106
|
+
usage "rudy-ec2 images -o self"
|
107
|
+
option :o, :owner, String, "Amazon Account Number or one of: amazon, self"
|
108
|
+
option :l, :all, "Display all registered machine images (warning: slow)"
|
109
|
+
#option :p, :private, "Private images only"
|
110
|
+
option :b, :bucket, String, "The name of the bucket that will store the image"
|
111
|
+
option :n, :name, String, "The name of the image file (to create)"
|
112
|
+
option :u, :user, String, "Username to connect as (used for creating an image)"
|
113
|
+
action :C, :create, "Create an image"
|
114
|
+
action :P, :prepare, "Prepare a running instance to be used as an image"
|
115
|
+
#action :D, :destroy, "Deregister an image (does not remove image files from S3)"
|
116
|
+
argv :ami
|
117
|
+
command :images => Rudy::CLI::AWS::EC2::Images
|
118
|
+
command_alias :images, :image
|
119
|
+
command_alias :images, :im
|
120
|
+
|
121
|
+
desc "Amazon EC2 Instances"
|
122
|
+
usage "rudy-ec2 i"
|
123
|
+
usage "rudy-ec2 instance"
|
124
|
+
usage "rudy-ec2 instances"
|
125
|
+
usage "rudy-ec2 instances [-g group-name] [instance-ID]"
|
126
|
+
usage "rudy-ec2 instances -C -g group-name -s m1.small -k keypair-name"
|
127
|
+
usage "rudy-ec2 instances -C -a 255.255.255.255 -k keypair-name"
|
128
|
+
usage "rudy-ec2 instances -R instance-ID"
|
129
|
+
usage "rudy-ec2 instances -D instance-ID"
|
130
|
+
usage "rudy-ec2 instances -R -g group-name"
|
131
|
+
usage "rudy-ec2 instances -D -g group-name"
|
132
|
+
option :g, :group, String, "The security group name"
|
133
|
+
option :m, :ami, String, "The machine image ID (ami)"
|
134
|
+
option :s, :size, String, "The instance size (default: m1.small)"
|
135
|
+
option :k, :keypair, String, "The SSH keypair to use for launch"
|
136
|
+
option :a, :address, String, "The IP address to associate to the new instance"
|
137
|
+
option :n, :newaddress, "Create and assign a new elastic IP"
|
138
|
+
option :p, :private, "Do not give the instance a public IP address"
|
139
|
+
action :C, :create, "Create a machine instance"
|
140
|
+
action :R, :restart, "Restart a machine instance"
|
141
|
+
action :D, :destroy, "Destroy a machine instance"
|
142
|
+
argv :instid
|
143
|
+
command :instances => Rudy::CLI::AWS::EC2::Instances
|
144
|
+
command_alias :instances, :instance
|
145
|
+
command_alias :instances, :in
|
146
|
+
command_alias :instances, :i
|
147
|
+
|
148
|
+
desc "Amazon EC2 KeyPairs"
|
149
|
+
usage "rudy-ec2 keypairs"
|
150
|
+
usage "rudy-ec2 keypairs -C name"
|
151
|
+
usage "rudy-ec2 keypairs -D name"
|
152
|
+
action :D, :destroy, "Unregister keypair from EC2 (this is permanent!)"
|
153
|
+
action :C, :create, "Create and register a keypair with EC2"
|
154
|
+
argv :name
|
155
|
+
command :keypairs => Rudy::CLI::AWS::EC2::KeyPairs
|
156
|
+
command_alias :keypairs, :keypair
|
157
|
+
command_alias :keypairs, :k
|
158
|
+
|
159
|
+
desc "Amazon EC2 Snapshots"
|
160
|
+
usage "rudy-ec2 snapshots"
|
161
|
+
usage "rudy-ec2 snapshots -C -v volume-id"
|
162
|
+
usage "rudy-ec2 snapshots -D snapshot-id"
|
163
|
+
option :v, :volume, String, "Volume ID"
|
164
|
+
action :D, :destroy, "Destroy a snapshot (this is permanent!)"
|
165
|
+
action :C, :create, "Create a snapshot"
|
166
|
+
argv :snapid
|
167
|
+
command :snapshots => Rudy::CLI::AWS::EC2::Snapshots
|
168
|
+
command_alias :snapshots, :snapshot
|
169
|
+
command_alias :snapshots, :t
|
170
|
+
|
171
|
+
desc "Open an SSH connection"
|
172
|
+
usage "rudy-ec2 ssh"
|
173
|
+
usage "rudy-ec2 -u root -k path/2/key ssh"
|
174
|
+
usage "rudy-ec2 -u root -k path/2/key ssh uname -a"
|
175
|
+
usage "rudy-ec2 ssh -g group-name"
|
176
|
+
usage "rudy-ec2 ssh -i instance-id"
|
177
|
+
option :print, "Only print the SSH command, don't connect"
|
178
|
+
option :g, :group, String, "A security group name"
|
179
|
+
option :i, :instid, String, "An instance ID"
|
180
|
+
argv :cmd
|
181
|
+
command :ssh => Rudy::CLI::AWS::EC2::Candy
|
182
|
+
command_alias :ssh, :connect
|
183
|
+
|
184
|
+
desc "Amazon EC2 status"
|
185
|
+
command :status => Rudy::CLI::AWS::EC2::Candy
|
186
|
+
|
187
|
+
desc "Amazon EC2 Volumes"
|
188
|
+
usage "rudy-ec2 volumes"
|
189
|
+
usage "rudy-ec2 volumes -C -s size [-d device-path]"
|
190
|
+
usage "rudy-ec2 volumes -A volume-id instance-id"
|
191
|
+
usage "rudy-ec2 volumes -N volume-id"
|
192
|
+
usage "rudy-ec2 volumes -D volume-id"
|
193
|
+
option :i, :instance, String, "Instance ID"
|
194
|
+
option :s, :size, String, "Size (in GB)"
|
195
|
+
option :t, :snapshot, String, "Snapshot ID (snap)"
|
196
|
+
option :d, :device, String, "Device path (default: /dev/sdh)"
|
197
|
+
action :D, :destroy, "Destroy a volume (this is permanent!)"
|
198
|
+
action :C, :create, "Create a volume"
|
199
|
+
action :A, :attach, "Attach a volume to a running instance"
|
200
|
+
action :N, :detach, "Detach a volume from an instance"
|
201
|
+
argv :volid
|
202
|
+
command :volumes => Rudy::CLI::AWS::EC2::Volumes
|
203
|
+
command_alias :volumes, :volume
|
204
|
+
command_alias :volumes, :v
|
205
|
+
|
206
|
+
desc "Availability Zones"
|
207
|
+
argv :name
|
208
|
+
command :zones => Rudy::CLI::AWS::EC2::Zones
|
209
|
+
command_alias :zones, :zone
|
210
|
+
command_alias :zones, :z
|
211
|
+
|
212
|
+
|
213
|
+
# -------------------------------- RUDY-EC2 MISCELLANEOUS --------
|
214
|
+
# ------------------------------------------------------------------
|
215
|
+
|
216
|
+
default :instances
|
217
|
+
debug :off
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
#puts Rudy::Utils.banner("THIS IS RUBY #{RUBY_VERSION}") if Drydock.debug?
|
222
|
+
|
223
|
+
# We call Drydock specifically otherwise it will run at_exit. Rye also
|
224
|
+
# uses at_exit for shutting down the ssh-agent. Ruby executes at_exit
|
225
|
+
# blocks in reverse order so if Drydock is required first, it's block
|
226
|
+
# will run after Rye shuts down the ssh-agent.
|
227
|
+
begin
|
228
|
+
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
229
|
+
rescue Drydock::ArgError, Drydock::OptError=> ex
|
230
|
+
STDERR.puts ex.message
|
231
|
+
STDERR.puts ex.usage
|
232
|
+
rescue Rudy::Error => ex
|
233
|
+
STDERR.puts ex.message
|
234
|
+
rescue => ex
|
235
|
+
STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
|
236
|
+
STDERR.puts ex.backtrace if Drydock.debug?
|
237
|
+
rescue SystemExit
|
238
|
+
# Don't balk
|
239
|
+
end
|
240
|
+
|