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.
Files changed (132) hide show
  1. data/CHANGES.txt +110 -18
  2. data/README.rdoc +40 -44
  3. data/Rudyfile +35 -50
  4. data/bin/rudy +88 -57
  5. data/bin/rudy-ec2 +2 -16
  6. data/bin/rudy-s3 +0 -10
  7. data/bin/rudy-sdb +11 -12
  8. data/lib/rudy.rb +59 -91
  9. data/lib/rudy/aws.rb +4 -45
  10. data/lib/rudy/aws/ec2.rb +57 -20
  11. data/lib/rudy/aws/ec2/address.rb +10 -11
  12. data/lib/rudy/aws/ec2/group.rb +10 -9
  13. data/lib/rudy/aws/ec2/image.rb +8 -8
  14. data/lib/rudy/aws/ec2/instance.rb +18 -19
  15. data/lib/rudy/aws/ec2/keypair.rb +14 -19
  16. data/lib/rudy/aws/ec2/snapshot.rb +16 -9
  17. data/lib/rudy/aws/ec2/volume.rb +39 -26
  18. data/lib/rudy/aws/ec2/zone.rb +5 -4
  19. data/lib/rudy/aws/s3.rb +2 -1
  20. data/lib/rudy/aws/sdb.rb +35 -86
  21. data/lib/rudy/backups.rb +24 -0
  22. data/lib/rudy/cli.rb +5 -131
  23. data/lib/rudy/cli/aws/ec2/addresses.rb +19 -27
  24. data/lib/rudy/cli/aws/ec2/candy.rb +45 -20
  25. data/lib/rudy/cli/aws/ec2/groups.rb +9 -13
  26. data/lib/rudy/cli/aws/ec2/images.rb +5 -133
  27. data/lib/rudy/cli/aws/ec2/instances.rb +25 -25
  28. data/lib/rudy/cli/aws/ec2/keypairs.rb +7 -11
  29. data/lib/rudy/cli/aws/ec2/snapshots.rb +5 -9
  30. data/lib/rudy/cli/aws/ec2/volumes.rb +22 -23
  31. data/lib/rudy/cli/aws/ec2/zones.rb +2 -3
  32. data/lib/rudy/cli/aws/sdb/domains.rb +5 -6
  33. data/lib/rudy/cli/aws/sdb/objects.rb +33 -0
  34. data/lib/rudy/cli/aws/sdb/select.rb +23 -0
  35. data/lib/rudy/cli/backups.rb +38 -0
  36. data/lib/rudy/cli/base.rb +104 -0
  37. data/lib/rudy/cli/candy.rb +1 -2
  38. data/lib/rudy/cli/config.rb +20 -7
  39. data/lib/rudy/cli/disks.rb +7 -9
  40. data/lib/rudy/cli/execbase.rb +56 -0
  41. data/lib/rudy/cli/machines.rb +242 -45
  42. data/lib/rudy/cli/metadata.rb +24 -10
  43. data/lib/rudy/cli/networks.rb +34 -0
  44. data/lib/rudy/cli/routines.rb +32 -6
  45. data/lib/rudy/cli/status.rb +60 -0
  46. data/lib/rudy/config.rb +55 -32
  47. data/lib/rudy/config/objects.rb +44 -30
  48. data/lib/rudy/disks.rb +25 -0
  49. data/lib/rudy/exceptions.rb +99 -0
  50. data/lib/rudy/global.rb +67 -28
  51. data/lib/rudy/guidelines.rb +3 -2
  52. data/lib/rudy/huxtable.rb +67 -58
  53. data/lib/rudy/machines.rb +41 -263
  54. data/lib/rudy/metadata.rb +212 -38
  55. data/lib/rudy/metadata/backup.rb +123 -78
  56. data/lib/rudy/metadata/disk.rb +153 -170
  57. data/lib/rudy/metadata/machine.rb +179 -0
  58. data/lib/rudy/mixins.rb +2 -1
  59. data/lib/rudy/mixins/hash.rb +3 -1
  60. data/lib/rudy/mixins/symbol.rb +8 -0
  61. data/lib/rudy/routines.rb +127 -344
  62. data/lib/rudy/routines/base.rb +229 -0
  63. data/lib/rudy/routines/handlers/base.rb +48 -0
  64. data/lib/rudy/routines/handlers/depends.rb +49 -0
  65. data/lib/rudy/routines/handlers/disks.rb +249 -0
  66. data/lib/rudy/routines/handlers/group.rb +44 -0
  67. data/lib/rudy/routines/handlers/host.rb +70 -0
  68. data/lib/rudy/routines/handlers/keypair.rb +70 -0
  69. data/lib/rudy/routines/handlers/machines.rb +15 -0
  70. data/lib/rudy/routines/handlers/script.rb +85 -0
  71. data/lib/rudy/routines/handlers/user.rb +45 -0
  72. data/lib/rudy/routines/passthrough.rb +19 -23
  73. data/lib/rudy/routines/reboot.rb +98 -50
  74. data/lib/rudy/routines/shutdown.rb +65 -14
  75. data/lib/rudy/routines/startup.rb +112 -17
  76. data/lib/rudy/utils.rb +35 -68
  77. data/rudy.gemspec +82 -25
  78. data/tryouts/01_mixins/01_hash_tryouts.rb +20 -0
  79. data/tryouts/10_require_time/10_rudy_tryouts.rb +33 -0
  80. data/tryouts/10_require_time/15_global_tryouts.rb +58 -0
  81. data/tryouts/12_config/10_load_config_tryouts.rb +43 -0
  82. data/tryouts/12_config/20_defaults_tryouts.rb +16 -0
  83. data/tryouts/12_config/30_accounts_tryouts.rb +17 -0
  84. data/tryouts/12_config/40_machines_tryouts.rb +53 -0
  85. data/tryouts/12_config/50_commands_tryouts.rb +17 -0
  86. data/tryouts/12_config/60_routines_tryouts.rb +16 -0
  87. data/tryouts/15_huxtable/10_huxtable_tryouts.rb +47 -0
  88. data/tryouts/15_huxtable/20_user_tryouts.rb +47 -0
  89. data/tryouts/20_simpledb/10_domains_tryouts.rb +36 -0
  90. data/tryouts/20_simpledb/20_objects_tryouts.rb +56 -0
  91. data/tryouts/25_ec2/10_keypairs_tryouts.rb +54 -0
  92. data/tryouts/25_ec2/20_groups_tryouts.rb +56 -0
  93. data/tryouts/25_ec2/21_groups_authorize_address_tryouts.rb +53 -0
  94. data/tryouts/25_ec2/22_groups_authorize_account_tryouts.rb +54 -0
  95. data/tryouts/25_ec2/30_addresses_tryouts.rb +42 -0
  96. data/tryouts/25_ec2/40_volumes_tryouts.rb +53 -0
  97. data/tryouts/25_ec2/50_snapshots_tryouts.rb +75 -0
  98. data/tryouts/26_ec2_instances/10_instance_tryouts.rb +107 -0
  99. data/tryouts/26_ec2_instances/50_images_tryouts.rb +7 -0
  100. data/tryouts/30_metadata/10_include_tryouts.rb +45 -0
  101. data/tryouts/30_metadata/13_object_tryouts.rb +19 -0
  102. data/tryouts/30_metadata/50_disk_tryouts.rb +115 -0
  103. data/tryouts/30_metadata/51_disk_digest_tryouts.rb +24 -0
  104. data/tryouts/30_metadata/53_disk_list_tryouts.rb +35 -0
  105. data/tryouts/30_metadata/56_disk_volume_tryouts.rb +68 -0
  106. data/tryouts/30_metadata/60_backup_tryouts.rb +101 -0
  107. data/tryouts/30_metadata/63_backup_list_tryouts.rb +38 -0
  108. data/tryouts/30_metadata/64_backup_disk_tryouts.rb +65 -0
  109. data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +76 -0
  110. data/tryouts/30_metadata/70_machine_tryouts.rb +85 -0
  111. data/tryouts/30_metadata/73_machine_list_tryouts.rb +58 -0
  112. data/tryouts/30_metadata/76_machine_instance_tryouts.rb +64 -0
  113. data/tryouts/30_metadata/77_machines_tryouts.rb +45 -0
  114. data/tryouts/40_routines/10_keypair_handler_tryouts.rb +52 -0
  115. data/tryouts/40_routines/11_group_handler_tryouts.rb +36 -0
  116. data/tryouts/80_cli/10_rudyec2_tryouts.rb +8 -0
  117. data/tryouts/80_cli/60_rudy_tryouts.rb +41 -0
  118. data/tryouts/exploration/console.rb +91 -0
  119. data/tryouts/exploration/machine.rb +23 -0
  120. data/tryouts/failer +6 -0
  121. metadata +116 -32
  122. data/bin/ird +0 -153
  123. data/lib/rudy/metadata/backups.rb +0 -67
  124. data/lib/rudy/metadata/debug.rb +0 -38
  125. data/lib/rudy/metadata/disks.rb +0 -67
  126. data/lib/rudy/metadata/objectbase.rb +0 -108
  127. data/lib/rudy/routines/helper.rb +0 -76
  128. data/lib/rudy/routines/helpers/dependshelper.rb +0 -34
  129. data/lib/rudy/routines/helpers/diskhelper.rb +0 -403
  130. data/lib/rudy/routines/helpers/scripthelper.rb +0 -197
  131. data/lib/rudy/routines/helpers/userhelper.rb +0 -37
  132. data/support/rudy-ec2-startup +0 -200
@@ -5,11 +5,6 @@ module AWS; module EC2;
5
5
 
6
6
  class Images < Rudy::CLI::CommandBase
7
7
 
8
- #def print_header
9
- # puts @global.print_header, @@global.print_header
10
- #end
11
-
12
-
13
8
  def images_valid?
14
9
  if @option.owner == 'self'
15
10
  raise "AWS_ACCOUNT_NUMBER not set" unless @@global.accountnum
@@ -20,159 +15,36 @@ module AWS; module EC2;
20
15
  end
21
16
  def images
22
17
 
23
- rimages = Rudy::AWS::EC2::Images.new(@@global.accesskey, @@global.secretkey, @@global.region)
24
18
  unless @option.all
25
19
  @option.owner ||= 'amazon'
26
20
  puts "Images owned by #{@option.owner.bright}" unless @argv.awsid
27
21
  end
28
22
 
29
- images = rimages.list(@option.owner, @argv) || []
23
+ images = Rudy::AWS::EC2::Images.list(@option.owner, @argv) || []
30
24
  images.each do |img|
31
25
  puts @@global.verbose > 0 ? img.inspect : img.dump(@@global.format)
32
26
  end
33
27
  puts "No images" if images.empty?
34
28
  end
35
-
36
- ##def prepare_images_valid?
37
- ## true
38
- ##end
39
- ##def prepare_images
40
- ## opts = {}
41
- ## opts[:id] = @option.instid if @option.instid
42
- ##
43
- ## puts "This will do the following:"
44
- ## puts "- Clear bash history"
45
- ## # NOTE: We can't delete the host keys here. Otherwise we can't create the image.
46
- ## #puts "- Delete host SSH keys (this is permanent!)"
47
- ## puts ""
48
- ##
49
- ## ## TODO:
50
- ## ## ~/.rudy, /etc/motd, history -c, /etc/hosts, /var/log/rudy*
51
- ##
52
- ## execute_check(:medium)
53
- ##
54
- ##
55
- ## # Options to be sent to Net::SSH
56
- ## ssh_opts = { :user => @global.user || Rudy.sysinfo.user, :debug => STDERR }
57
- ## if @@global.pkey
58
- ## raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
59
- ## raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
60
- ## ssh_opts[:keys] = @@global.pkey
61
- ## end
62
- ##
63
- ##
64
- ## rudy = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
65
- ## lt = rudy.list_group(nil, :running, opts[:id]) do |inst|
66
- ##
67
- ## puts "Preparing #{inst.dns_public}..."
68
- ##
69
- ## # Open the connection and run the command
70
- ## rbox = Rye::Box.new(inst.dns_public, ssh_opts)
71
- ##
72
- ## # We need to explicitly add the rm command for rbox so we
73
- ## # can delete the SSH host keys. This is will force the instance
74
- ## # to re-create it's SSH keys on first boot.
75
- ## def rbox.rm(*args); cmd('rm', args); end
76
- ## p ret = rbox.history(:c)
77
- ## p ret.exit_code
78
- ## p ret.stderr
79
- ## p ret.stdout
80
- ##
81
- ## end
82
- ##
83
- ## puts "done"
84
- ##end
85
-
86
- def create_images_valid?
87
- raise "No account number" unless @@global.accountnum
88
- raise "No Amazon cert-***.pem" unless @@global.cert
89
- raise "No Amazon pk-***.pem" unless @@global.privatekey
90
- raise "You must supply a root keypair path" unless @@global.pkey
91
-
92
- @rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
93
- @rimages = Rudy::AWS::EC2::Images.new(@@global.accesskey, @@global.secretkey, @@global.region)
94
- @s3 = Rudy::AWS::S3.new(@@global.accesskey, @@global.secretkey, @@global.region)
95
- raise "No instances" unless @rinst.any?
96
- raise "You must supply an S3 bucket name. See: 'rudy-s3 buckets'" unless @option.bucket
97
- raise "You must supply an image name" unless @option.name
98
- raise "The bucket '#{@option.bucket}' does not exist" unless @s3.bucket_exists?(@option.bucket)
99
- true
100
- end
101
-
102
- def create_images
103
- opts = {}
104
- opts[:id] = @option.instid if @option.instid
105
-
106
- @@global.user = 'root'
107
-
108
- puts "You may want to run rudy-ec2 #{@alias} --prepare first".bright
109
- puts "NOTE 1: This process is currently Linux-only"
110
- puts "NOTE 2: If you plan to create a public machine image, there are "
111
- puts "additional steps to take to remove any sensitive information"
112
- puts "before creating the image. See:"
113
- puts "http://docs.amazonwebservices.com/AWSEC2/latest/DeveloperGuide/AESDG-chapter-sharingamis.html"
114
- exit unless Annoy.pose_question(" Continue?\a ", /yes|y|ya|sure|you bet!/i, STDERR)
115
-
116
- # Options to be sent to Net::SSH
117
- ssh_opts = { :user => @@global.user || Rudy.sysinfo.user, :debug => nil }
118
- if @@global.pkey
119
- raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
120
- raise InsecureKeyPermissions, @@global.pkey unless File.stat(@@global.pkey).mode == 33152
121
- ssh_opts[:keys] = @@global.pkey
122
- end
123
-
124
- lt = @rinst.list_group(nil, :running, opts[:id]) do |inst|
125
-
126
- puts inst.to_s
127
-
128
- # Open the connection and run the command
129
- rbox = Rye::Box.new(inst.dns_public, ssh_opts)
130
- def rbox.bundle_vol(*args); cmd('ec2-bundle-vol', args); end
131
- def rbox.upload_vol(*args); cmd('ec2-upload-bundle', args); end
132
-
133
- rbox.upload(@@global.cert, @@global.privatekey, "/mnt")
134
- rbox.touch("/root/firstrun")
135
-
136
- ## TODO:
137
- ## We have to delete the host keys just before we run the bundle command.
138
- ## The problem is that if we lose the connection we won't be able to connect
139
- ## to the instance again. A better solution is to add the keys to the ignore
140
- ## list for the bundle command.
141
- ##ret = rbox.rm('/etc/ssh/ssh_host_*_key*')
142
-
143
- puts "Starting bundling process..."
144
-
145
- pkeyfile = File.basename(@@global.privatekey)
146
- certfile = File.basename(@@global.cert)
147
-
148
- rbox.bundle_vol(:r, "i386", :p, @option.name, :k, "/mnt/#{pkeyfile}", :c, "/mnt/#{certfile}", :u, @@global.accountnum)
149
- rbox.upload_vol(:b, @option.bucket, :m, "/tmp/#{@option.name}.manifest.xml", :a, @@global.accesskey, :s, @@global.secretkey)
150
-
151
- @rimages.register("#{@option.bucket}/#{@option.name}.manifest.xml")
152
-
153
- break
154
- end
155
-
156
- end
157
29
 
158
30
  def destroy_images_valid?
159
31
  unless @argv.ami && Rudy::Utils.is_id?(:image, @argv.ami)
160
32
  raise "Must supply an AMI ID (ami-XXXXXXX)"
161
33
  end
162
- @rimages = Rudy::AWS::EC2::Images.new(@@global.accesskey, @@global.secretkey, @@global.region)
34
+ true
163
35
  end
164
36
  def destroy_images
165
- puts @rimages.deregister(@argv.ami) ? "Done" : "Unknown error"
37
+ puts Rudy::AWS::EC2::Images.deregister(@argv.ami) ? "Done" : "Unknown error"
166
38
  end
167
39
 
168
40
  def register_images_valid?
169
41
  unless @argv.first
170
42
  raise "Must supply a valid manifest path (bucket/ami-name.manifest.xml)"
171
43
  end
172
- @rimages = Rudy::AWS::EC2::Images.new(@@global.accesskey, @@global.secretkey, @@global.region)
44
+ true
173
45
  end
174
46
  def register_images
175
- puts @rimages.register(@argv.first)
47
+ puts Rudy::AWS::EC2::Images.register(@argv.first)
176
48
  end
177
49
 
178
50
 
@@ -16,8 +16,9 @@ module AWS; module EC2;
16
16
  raise "Cannot supply an instance ID" if @option.instid
17
17
 
18
18
  if @option.group
19
- rgroup = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
20
- raise "Group #{@option.group} does not exist" unless rgroup.exists?(@option.group)
19
+ unless Rudy::AWS::EC2::Groups.exists?(@option.group)
20
+ raise "Group #{@option.group} does not exist"
21
+ end
21
22
  end
22
23
 
23
24
  true
@@ -30,14 +31,15 @@ module AWS; module EC2;
30
31
  :size => 'm1.small',
31
32
  :zone => @@global.zone
32
33
  }
33
-
34
- radd = Rudy::AWS::EC2::Addresses.new(@@global.accesskey, @@global.secretkey, @@global.region)
35
- rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
36
-
34
+
37
35
  if @option.address
38
36
  raise "Cannot specify both -a and -n" if @option.newaddress
39
- raise "#{@option.address} is not allocated to you" unless radd.exists?(@option.address)
40
- raise "#{@option.address} is already associated!" if radd.associated?(@option.address)
37
+ unless Rudy::AWS::EC2::Addresses.exists?(@option.address)
38
+ raise "#{@option.address} is not allocated to you"
39
+ end
40
+ if Rudy::AWS::EC2::Addresses.associated?(@option.address)
41
+ raise "#{@option.address} is already associated!"
42
+ end
41
43
  end
42
44
 
43
45
  # These can be sent directly to EC2 class
@@ -53,7 +55,7 @@ module AWS; module EC2;
53
55
  exit unless Annoy.proceed?(:low)
54
56
  end
55
57
 
56
- instances = rinst.list_group(opts[:group], :running)
58
+ instances = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running)
57
59
 
58
60
  if instances && instances.size > 0
59
61
  instance_count = (instances.size == 1) ? 'is 1 instance' : "are #{instances.size} instances"
@@ -63,19 +65,19 @@ module AWS; module EC2;
63
65
 
64
66
  if @option.newaddress
65
67
  print "Creating address... "
66
- address = radd.create
68
+ address = Rudy::AWS::EC2::Addresses.create
67
69
  puts "#{address.ipaddress}"
68
70
  @option.address = address.ipaddress
69
71
  end
70
72
 
71
73
  execute_action do
72
74
  first_instance = true
73
- rinst.create(opts) do |inst| # Rudy::AWS::EC2::Instance objects
75
+ Rudy::AWS::EC2::Instances.create(opts) do |inst| # Rudy::AWS::EC2::Instance objects
74
76
 
75
77
  # Assign IP address to only the first instance
76
78
  if first_instance && @option.address
77
79
  puts "Associating #{@option.address} to #{inst.awsid}"
78
- radd.associate(@option.address, inst.awsid)
80
+ Rudy::AWS::EC2::Addresses.associate(@option.address, inst.awsid)
79
81
  first_instance = false
80
82
  end
81
83
 
@@ -89,16 +91,16 @@ module AWS; module EC2;
89
91
  raise NoInstanceError.new(nil, @alias) if !@option.group && !@argv.instid
90
92
 
91
93
  if @option.group
92
- rgroup = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
93
- raise "Group #{@option.group} does not exist" unless rgroup.exists?(@option.group)
94
+ unless Rudy::AWS::EC2::Groups.exists?(@option.group)
95
+ raise "Group #{@option.group} does not exist"
96
+ end
94
97
  end
95
98
 
96
99
  if @option.private
97
100
  raise Drydock::OptsError.new(nil, @alias, "Cannot allocate public IP for private instance") if @option.address || @option.newadress
98
101
  end
99
102
 
100
- @rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
101
- raise "No instances" unless @rinst.any?
103
+ raise "No instances" unless Rudy::AWS::EC2::Instances.any?
102
104
  true
103
105
  end
104
106
  alias :instances_destroy_valid? :instances_restart_valid?
@@ -112,12 +114,11 @@ module AWS; module EC2;
112
114
  end
113
115
 
114
116
  def consoles_valid?
115
- @rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
116
117
  if @@global.pkey
117
118
  raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
118
119
  raise "Insecure permissions for #{@@global.pkey}" unless (File.stat(@@global.pkey).mode & 600) == 0
119
120
  end
120
- raise "No instances" unless @rinst.any?
121
+ raise "No instances" unless Rudy::AWS::EC2::Instances.any?
121
122
  true
122
123
  end
123
124
  def consoles
@@ -126,9 +127,9 @@ module AWS; module EC2;
126
127
  opts[:id] = @argv.instid if @argv.instid
127
128
  opts[:id] &&= [opts[:id]].flatten
128
129
 
129
- lt = @rinst.list_group(opts[:group], :any, opts[:id]) do |inst|
130
+ lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :any, opts[:id]) do |inst|
130
131
  puts instance_separator(inst.dns_public || inst.state, inst.awsid)
131
- console = @rinst.console(inst.awsid)
132
+ console = Rudy::AWS::EC2::Instances.console(inst.awsid)
132
133
  output = console ? Base64.decode64(console) : "Unavailable"
133
134
 
134
135
  # The linux console can include ANSI escape codes for color,
@@ -163,7 +164,7 @@ module AWS; module EC2;
163
164
  opts[:group] = @option.group if @option.group
164
165
  opts[:state] = @option.state if @option.state
165
166
 
166
- # A nil value forces the @ec2.instances.list to return all instances
167
+ # A nil value forces the @@ec2.instances.list to return all instances
167
168
  if @option.all
168
169
  opts[:state] = :any
169
170
  opts[:group] = :any
@@ -172,8 +173,7 @@ module AWS; module EC2;
172
173
  opts[:id] = @argv.instid if @argv.instid
173
174
  opts[:id] &&= [opts[:id]].flatten
174
175
 
175
- rudy = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
176
- lt = rudy.list_group(opts[:group], opts[:state], opts[:id]) do |inst|
176
+ lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], opts[:state], opts[:id]) do |inst|
177
177
  puts @@global.verbose > 0 ? inst.inspect : inst.dump(@@global.format)
178
178
  end
179
179
  puts "No instances running" if !lt || lt.empty?
@@ -190,7 +190,7 @@ module AWS; module EC2;
190
190
  opts[:id] = @argv.instid if @argv.instid
191
191
  opts[:id] &&= [opts[:id]].flatten
192
192
 
193
- instances = @rinst.list_group(opts[:group], :running, opts[:id])
193
+ instances = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running, opts[:id])
194
194
  raise "No matching instances running" if instances.nil?
195
195
 
196
196
  inst_names = instances.collect { |inst| inst.dns_public || inst.awsid }
@@ -204,7 +204,7 @@ module AWS; module EC2;
204
204
  execute_check(:medium)
205
205
 
206
206
  execute_action("#{action.to_s.capitalize} Failed") {
207
- @rinst.send(action, inst_ids)
207
+ Rudy::AWS::EC2::Instances.send(action, inst_ids)
208
208
  }
209
209
  status
210
210
  end
@@ -3,15 +3,14 @@
3
3
  module Rudy; module CLI;
4
4
  module AWS; module EC2;
5
5
 
6
- class KeyPairs < Rudy::CLI::CommandBase
6
+ class EC2::Keypairs < Rudy::CLI::CommandBase
7
7
 
8
8
  def create_keypairs_valid?
9
9
  raise Drydock::ArgError.new('name', @alias) unless @argv.name
10
10
  true
11
11
  end
12
12
  def create_keypairs
13
- rkey = Rudy::AWS::EC2::KeyPairs.new(@@global.accesskey, @@global.secretkey, @@global.region)
14
- kp = execute_action { rkey.create(@argv.name) }
13
+ kp = execute_action { Rudy::AWS::EC2::Keypairs.create(@argv.name) }
15
14
  if [:s, :string].member?(@@global.format)
16
15
  puts "Name: #{kp.name}"
17
16
  puts "Fingerprint: #{kp.fingerprint}", $/
@@ -28,21 +27,18 @@ module AWS; module EC2;
28
27
  true
29
28
  end
30
29
  def destroy_keypairs
31
- rkey = Rudy::AWS::EC2::KeyPairs.new(@@global.accesskey, @@global.secretkey, @@global.region)
32
- raise "KeyPair #{@argv.name} does not exist" unless rkey.exists?(@argv.name)
33
- kp = rkey.get(@argv.name)
30
+ raise "Keypair #{@argv.name} does not exist" unless Rudy::AWS::EC2::Keypairs.exists?(@argv.name)
31
+ kp = Rudy::AWS::EC2::Keypairs.get(@argv.name)
34
32
  puts "Destroying: #{kp.name}"
35
33
  execute_check(:medium)
36
- execute_action { rkey.destroy(kp.name) }
37
- keypairs
34
+ execute_action { Rudy::AWS::EC2::Keypairs.destroy(kp.name) }
38
35
  end
39
36
 
40
37
  def keypairs
41
- rkey = Rudy::AWS::EC2::KeyPairs.new(@@global.accesskey, @@global.secretkey, @@global.region)
42
- (rkey.list || []).each do |kp|
38
+ (Rudy::AWS::EC2::Keypairs.list || []).each do |kp|
43
39
  puts @@global.verbose > 0 ? kp.inspect : kp.dump(@@global.format)
44
40
  end
45
- puts "No keypairs" unless rkey.any?
41
+ puts "No keypairs" unless Rudy::AWS::EC2::Keypairs.any?
46
42
  end
47
43
 
48
44
 
@@ -7,34 +7,30 @@ module AWS; module EC2;
7
7
 
8
8
  def create_snapshots_valid?
9
9
  raise Drydock::ArgError.new('volume ID', @alias) unless @option.volume
10
- @rvol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
11
- @volume = @rvol.get(@argv.volid)
10
+ @volume = Rudy::AWS::EC2::Volumes.get(@argv.volid)
12
11
  raise "Volume #{@volume.awsid} does not exist" unless @volume
13
12
  true
14
13
  end
15
14
  def create_snapshots
16
- rsnap = Rudy::AWS::EC2::Snapshots.new(@@global.accesskey, @@global.secretkey, @@global.region)
17
- snap = execute_action { rsnap.create(@volume.awsid) }
15
+ snap = execute_action { Rudy::AWS::EC2::Snapshots.create(@volume.awsid) }
18
16
  puts @@global.verbose > 0 ? snap.inspect : snap.dump(@@global.format)
19
17
  end
20
18
 
21
19
  def destroy_snapshots_valid?
22
20
  raise Drydock::ArgError.new('snapshot ID', @alias) unless @argv.snapid
23
- @rsnap = Rudy::AWS::EC2::Snapshots.new(@@global.accesskey, @@global.secretkey, @@global.region)
24
- @snap = @rsnap.get(@argv.snapid)
21
+ @snap = Rudy::AWS::EC2::Snapshots.get(@argv.snapid)
25
22
  raise "Snapshot #{@snap.awsid} does not exist" unless @snap
26
23
  true
27
24
  end
28
25
  def destroy_snapshots
29
26
  puts "Destroying: #{@snap.awsid}"
30
27
  execute_check(:medium)
31
- execute_action { @rsnap.destroy(@snap.awsid) }
28
+ execute_action { Rudy::AWS::EC2::Snapshots.destroy(@snap.awsid) }
32
29
  snapshots
33
30
  end
34
31
 
35
32
  def snapshots
36
- rsnap = Rudy::AWS::EC2::Snapshots.new(@@global.accesskey, @@global.secretkey, @@global.region)
37
- snaps = rsnap.list || []
33
+ snaps = Rudy::AWS::EC2::Snapshots.list || []
38
34
  snaps.each do |snap|
39
35
  puts @@global.verbose > 0 ? snap.inspect : snap.dump(@@global.format)
40
36
  end
@@ -13,23 +13,27 @@ module AWS; module EC2;
13
13
  end
14
14
  def volumes_create
15
15
  puts "Creating #{@option.size}GB volume in #{@@global.zone}"
16
- rvol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
17
16
  execute_check(:low)
18
17
  vol = execute_action("Create Failed") {
19
- rvol.create(@option.size, @@global.zone, @option.snapshot)
18
+ Rudy::AWS::EC2::Volumes.create(@option.size, @@global.zone, @option.snapshot)
20
19
  }
21
20
  puts @global.verbose > 1 ? vol.inspect : vol.dump(@@global.format)
22
21
  end
23
22
 
24
23
 
25
24
  def destroy_volumes_valid?
26
- raise "You must supply a volume ID. See rudy volume -h" unless @argv.volid
25
+ raise "You must supply a volume ID. See rudy volume -h" unless @argv.volid
26
+
27
+ unless Rudy::AWS::EC2::Volumes.exists? @argv.volid
28
+ raise Rudy::AWS::EC2::UnknownVolume, @argv.volid
29
+ end
27
30
  true
28
31
  end
29
32
 
30
33
  def destroy_volumes
31
- @rvol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
32
- @volume = @rvol.get(@argv.volid)
34
+
35
+ @volume = Rudy::AWS::EC2::Volumes.get(@argv.volid)
36
+
33
37
  raise "Volume #{@volume.awsid} does not exist" unless @volume
34
38
  raise "Volume #{@volume.awsid} is still in-use" if @volume.in_use?
35
39
  raise "Volume #{@volume.awsid} is still attached" if @volume.attached?
@@ -37,9 +41,10 @@ module AWS; module EC2;
37
41
 
38
42
  puts "Destroying #{@volume.awsid}"
39
43
  execute_check(:medium)
40
- execute_action("Destroy Failed") { @rvol.destroy(@volume.awsid) }
44
+ execute_action("Destroy Failed") { Rudy::AWS::EC2::Volumes.destroy(@volume.awsid) }
41
45
 
42
- vol = @rvol.get(@volume.awsid)
46
+ vol = Rudy::AWS::EC2::Volumes.get(@volume.awsid)
47
+
43
48
  puts @global.verbose > 1 ? vol.inspect : vol.dump(@@global.format)
44
49
  end
45
50
 
@@ -51,20 +56,17 @@ module AWS; module EC2;
51
56
  end
52
57
  def volumes_attach
53
58
  @option.device ||= "/dev/sdh"
54
-
55
- rvol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
56
- rinst = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
57
- raise "Volume #{@argv.volid} does not exist" unless rvol.exists?(@argv.volid)
58
- raise "Volume #{@argv.volid} is already attached" if rvol.attached?(@argv.volid)
59
- raise "Instance #{@option.instance} does not exist" unless rinst.exists?(@option.instance)
59
+ raise "Volume #{@argv.volid} does not exist" unless Rudy::AWS::EC2::Volumes.exists?(@argv.volid)
60
+ raise "Volume #{@argv.volid} is already attached" if Rudy::AWS::EC2::Volumes.attached?(@argv.volid)
61
+ raise "Instance #{@option.instance} does not exist" unless Rudy::AWS::EC2::Instances.exists?(@option.instance)
60
62
 
61
63
  puts "Attaching #{@argv.volid} to #{@option.instance} on #{@option.device}"
62
64
  execute_check(:low)
63
65
  execute_action("Attach Failed") {
64
- rvol.attach(@argv.volid, @option.instance, @option.device)
66
+ Rudy::AWS::EC2::Volumes.attach(@argv.volid, @option.instance, @option.device)
65
67
  }
66
68
 
67
- vol = rvol.get(@argv.volid)
69
+ vol = Rudy::AWS::EC2::Volumes.get(@argv.volid)
68
70
  puts @global.verbose > 1 ? vol.inspect : vol.dump(@@global.format)
69
71
  end
70
72
 
@@ -74,24 +76,21 @@ module AWS; module EC2;
74
76
  end
75
77
 
76
78
  def volumes_detach
77
- rvol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
78
- raise "Volume #{@argv.volid} does not exist" unless rvol.exists?(@argv.volid)
79
-
80
- vol = rvol.get(@argv.volid)
79
+ raise "Volume #{@argv.volid} does not exist" unless Rudy::AWS::EC2::Volumes.exists?(@argv.volid)
80
+ vol = Rudy::AWS::EC2::Volumes.get(@argv.volid)
81
81
  raise "Volume #{vol.awsid} is not attached" unless vol.attached?
82
82
 
83
83
  puts "Detaching #{vol.awsid} from #{vol.instid}"
84
84
  execute_check(:medium)
85
- execute_action("Detach Failed") { rvol.detach(vol.awsid) }
85
+ execute_action("Detach Failed") { Rudy::AWS::EC2::Volumes.detach(vol.awsid) }
86
86
 
87
- vol = rvol.get(vol.awsid)
87
+ vol = Rudy::AWS::EC2::Volumes.get(vol.awsid)
88
88
  puts @global.verbose > 1 ? vol.inspect : vol.dump(@@global.format)
89
89
  end
90
90
 
91
91
 
92
92
  def volumes
93
- rvol = Rudy::AWS::EC2::Volumes.new(@@global.accesskey, @@global.secretkey, @@global.region)
94
- volumes = rvol.list || []
93
+ volumes = Rudy::AWS::EC2::Volumes.list || []
95
94
  volumes.each do |vol|
96
95
  puts @global.verbose > 1 ? vol.inspect : vol.dump(@@global.format)
97
96
  end