solutious-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 (135) hide show
  1. data/CHANGES.txt +55 -14
  2. data/README.rdoc +26 -34
  3. data/Rudyfile +27 -32
  4. data/bin/rudy +47 -27
  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 +49 -89
  9. data/lib/rudy/aws.rb +2 -43
  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 +15 -16
  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 +37 -24
  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 +32 -7
  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 +98 -0
  37. data/lib/rudy/cli/candy.rb +1 -2
  38. data/lib/rudy/cli/config.rb +7 -4
  39. data/lib/rudy/cli/disks.rb +6 -8
  40. data/lib/rudy/cli/execbase.rb +53 -0
  41. data/lib/rudy/cli/machines.rb +14 -18
  42. data/lib/rudy/cli/metadata.rb +24 -10
  43. data/lib/rudy/cli/routines.rb +31 -5
  44. data/lib/rudy/config.rb +17 -22
  45. data/lib/rudy/config/objects.rb +44 -30
  46. data/lib/rudy/disks.rb +25 -0
  47. data/lib/rudy/exceptions.rb +95 -0
  48. data/lib/rudy/global.rb +46 -23
  49. data/lib/rudy/guidelines.rb +3 -2
  50. data/lib/rudy/huxtable.rb +66 -57
  51. data/lib/rudy/machines.rb +41 -263
  52. data/lib/rudy/metadata.rb +212 -38
  53. data/lib/rudy/metadata/backup.rb +123 -78
  54. data/lib/rudy/metadata/disk.rb +152 -170
  55. data/lib/rudy/metadata/machine.rb +179 -0
  56. data/lib/rudy/mixins.rb +2 -1
  57. data/lib/rudy/mixins/hash.rb +3 -1
  58. data/lib/rudy/mixins/symbol.rb +8 -0
  59. data/lib/rudy/routines.rb +127 -344
  60. data/lib/rudy/routines/base.rb +226 -0
  61. data/lib/rudy/routines/handlers/base.rb +48 -0
  62. data/lib/rudy/routines/handlers/depends.rb +49 -0
  63. data/lib/rudy/routines/handlers/disks.rb +239 -0
  64. data/lib/rudy/routines/handlers/group.rb +42 -0
  65. data/lib/rudy/routines/handlers/host.rb +72 -0
  66. data/lib/rudy/routines/handlers/keypair.rb +70 -0
  67. data/lib/rudy/routines/handlers/machines.rb +15 -0
  68. data/lib/rudy/routines/handlers/script.rb +85 -0
  69. data/lib/rudy/routines/handlers/user.rb +41 -0
  70. data/lib/rudy/routines/passthrough.rb +19 -23
  71. data/lib/rudy/routines/reboot.rb +82 -51
  72. data/lib/rudy/routines/shutdown.rb +61 -14
  73. data/lib/rudy/routines/startup.rb +111 -17
  74. data/lib/rudy/utils.rb +12 -59
  75. data/rudy.gemspec +85 -25
  76. data/tryouts/01_mixins/01_hash_tryouts.rb +20 -0
  77. data/tryouts/10_require_time/10_rudy_tryouts.rb +33 -0
  78. data/tryouts/10_require_time/15_global_tryouts.rb +58 -0
  79. data/tryouts/12_config/10_load_config_tryouts.rb +43 -0
  80. data/tryouts/12_config/20_defaults_tryouts.rb +16 -0
  81. data/tryouts/12_config/30_accounts_tryouts.rb +17 -0
  82. data/tryouts/12_config/40_machines_tryouts.rb +53 -0
  83. data/tryouts/12_config/50_commands_tryouts.rb +17 -0
  84. data/tryouts/12_config/60_routines_tryouts.rb +16 -0
  85. data/tryouts/15_huxtable/10_huxtable_tryouts.rb +47 -0
  86. data/tryouts/15_huxtable/20_user_tryouts.rb +47 -0
  87. data/tryouts/20_simpledb/10_domains_tryouts.rb +36 -0
  88. data/tryouts/20_simpledb/20_objects_tryouts.rb +56 -0
  89. data/tryouts/25_ec2/10_keypairs_tryouts.rb +54 -0
  90. data/tryouts/25_ec2/20_groups_tryouts.rb +56 -0
  91. data/tryouts/25_ec2/21_groups_authorize_address_tryouts.rb +53 -0
  92. data/tryouts/25_ec2/22_groups_authorize_account_tryouts.rb +54 -0
  93. data/tryouts/25_ec2/30_addresses_tryouts.rb +42 -0
  94. data/tryouts/25_ec2/40_volumes_tryouts.rb +53 -0
  95. data/tryouts/25_ec2/50_snapshots_tryouts.rb +75 -0
  96. data/tryouts/26_ec2_instances/10_instance_tryouts.rb +107 -0
  97. data/tryouts/26_ec2_instances/50_images_tryouts.rb +7 -0
  98. data/tryouts/30_metadata/10_include_tryouts.rb +45 -0
  99. data/tryouts/30_metadata/13_object_tryouts.rb +19 -0
  100. data/tryouts/30_metadata/50_disk_tryouts.rb +115 -0
  101. data/tryouts/30_metadata/51_disk_digest_tryouts.rb +24 -0
  102. data/tryouts/30_metadata/53_disk_list_tryouts.rb +35 -0
  103. data/tryouts/30_metadata/56_disk_volume_tryouts.rb +68 -0
  104. data/tryouts/30_metadata/60_backup_tryouts.rb +101 -0
  105. data/tryouts/30_metadata/63_backup_list_tryouts.rb +38 -0
  106. data/tryouts/30_metadata/64_backup_disk_tryouts.rb +65 -0
  107. data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +76 -0
  108. data/tryouts/30_metadata/70_machine_tryouts.rb +85 -0
  109. data/tryouts/30_metadata/73_machine_list_tryouts.rb +58 -0
  110. data/tryouts/30_metadata/76_machine_instance_tryouts.rb +64 -0
  111. data/tryouts/30_metadata/77_machines_tryouts.rb +45 -0
  112. data/tryouts/40_routines/10_keypair_handler_tryouts.rb +52 -0
  113. data/tryouts/40_routines/11_group_handler_tryouts.rb +36 -0
  114. data/tryouts/80_cli/10_rudyec2_tryouts.rb +8 -0
  115. data/tryouts/80_cli/60_rudy_tryouts.rb +41 -0
  116. data/tryouts/failer +6 -0
  117. data/tryouts/misc/console_tryout.rb +91 -0
  118. data/tryouts/misc/disks_tryout.rb +48 -0
  119. data/tryouts/misc/drydock_tryout.rb +48 -0
  120. data/tryouts/misc/nested_methods.rb +103 -0
  121. data/tryouts/misc/session_tryout.rb +46 -0
  122. data/tryouts/misc/tryouts.rb +33 -0
  123. data/tryouts/misc/usage_tryout.rb +23 -0
  124. metadata +119 -31
  125. data/bin/ird +0 -153
  126. data/lib/rudy/metadata/backups.rb +0 -67
  127. data/lib/rudy/metadata/debug.rb +0 -38
  128. data/lib/rudy/metadata/disks.rb +0 -67
  129. data/lib/rudy/metadata/objectbase.rb +0 -108
  130. data/lib/rudy/routines/helper.rb +0 -76
  131. data/lib/rudy/routines/helpers/dependshelper.rb +0 -34
  132. data/lib/rudy/routines/helpers/diskhelper.rb +0 -403
  133. data/lib/rudy/routines/helpers/scripthelper.rb +0 -197
  134. data/lib/rudy/routines/helpers/userhelper.rb +0 -37
  135. data/support/rudy-ec2-startup +0 -200
@@ -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 rgroup.exists?(@option.group)
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"
@@ -85,8 +84,7 @@ module AWS; module EC2;
85
84
  end
86
85
 
87
86
  checked = false
88
- rudy = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
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
@@ -152,11 +150,10 @@ module AWS; module EC2;
152
150
 
153
151
 
154
152
  checked = false
155
- rudy = Rudy::AWS::EC2::Instances.new(@@global.accesskey, @@global.secretkey, @@global.region)
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
- Rudy::Utils.scp_command inst.dns_public, @@global.pkey, opts[:user], opts[:paths], opts[:dest], (opts[:task] == :download), false, @option.print
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
 
@@ -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 @rgroups.exists?(@argv.name)
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
- @rgroups.create(@argv.name, @option.description, opts[:addresses], opts[:ports], opts[:protocols])
17
+ Rudy::AWS::EC2::Groups.create(@argv.name, @option.description, opts[:addresses], opts[:ports], opts[:protocols])
19
18
  }
20
- @rgroups.list(@argv.name) do |group|
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 @rgroups.exists?(@argv.name)
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 { @rgroups.destroy(@argv.name) }
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
- rgroups = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
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
- @groups = Rudy::AWS::EC2::Groups.new(@@global.accesskey, @@global.secretkey, @@global.region)
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
- rgroups.send("#{action.to_s}_group", @argv.name, opts[:group], opts[:owner])
86
+ Rudy::AWS::EC2::Groups.send("#{action.to_s}_group", @argv.name, opts[:group], opts[:owner])
91
87
  else
92
- rgroups.send(action, @argv.name, opts[:addresses], opts[:ports], opts[:protocols])
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
@@ -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