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.
Files changed (146) hide show
  1. data/CHANGES.txt +19 -1
  2. data/README.rdoc +66 -35
  3. data/Rakefile +1 -0
  4. data/Rudyfile +97 -6
  5. data/bin/ird +7 -4
  6. data/bin/rudy +120 -212
  7. data/bin/rudy-ec2 +240 -0
  8. data/bin/rudy-s3 +76 -0
  9. data/bin/rudy-sdb +67 -0
  10. data/lib/annoy.rb +61 -18
  11. data/lib/console.rb +10 -5
  12. data/lib/rudy/aws/ec2/address.rb +76 -40
  13. data/lib/rudy/aws/ec2/group.rb +138 -78
  14. data/lib/rudy/aws/ec2/image.rb +134 -12
  15. data/lib/rudy/aws/ec2/instance.rb +116 -89
  16. data/lib/rudy/aws/ec2/keypair.rb +26 -14
  17. data/lib/rudy/aws/ec2/snapshot.rb +23 -12
  18. data/lib/rudy/aws/ec2/volume.rb +198 -202
  19. data/lib/rudy/aws/ec2/zone.rb +77 -0
  20. data/lib/rudy/aws/ec2.rb +56 -25
  21. data/lib/rudy/aws/s3.rb +54 -0
  22. data/lib/rudy/aws/sdb/error.rb +46 -0
  23. data/lib/rudy/aws/sdb.rb +298 -0
  24. data/lib/rudy/aws.rb +29 -57
  25. data/lib/rudy/{metadata/backup.rb → backup.rb} +8 -8
  26. data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
  27. data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
  28. data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
  29. data/lib/rudy/cli/aws/ec2/images.rb +196 -0
  30. data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
  31. data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
  32. data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
  33. data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
  34. data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
  35. data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
  36. data/lib/rudy/cli/aws/s3/store.rb +22 -0
  37. data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
  38. data/lib/rudy/cli/{deploy.rb → candy.rb} +2 -6
  39. data/lib/rudy/cli/config.rb +25 -20
  40. data/lib/rudy/cli/disks.rb +18 -108
  41. data/lib/rudy/cli/machines.rb +94 -0
  42. data/lib/rudy/cli/routines.rb +47 -70
  43. data/lib/rudy/cli.rb +104 -89
  44. data/lib/rudy/config/objects.rb +5 -43
  45. data/lib/rudy/config.rb +8 -24
  46. data/lib/rudy/disks.rb +248 -0
  47. data/lib/rudy/global.rb +121 -0
  48. data/lib/rudy/huxtable.rb +232 -147
  49. data/lib/rudy/machines.rb +245 -0
  50. data/lib/rudy/metadata.rb +136 -0
  51. data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
  52. data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
  53. data/lib/rudy/routines/release.rb +27 -8
  54. data/lib/rudy/routines/shutdown.rb +47 -32
  55. data/lib/rudy/routines/startup.rb +47 -37
  56. data/lib/rudy/routines.rb +30 -37
  57. data/lib/rudy/scm/svn.rb +1 -1
  58. data/lib/rudy/utils.rb +262 -4
  59. data/lib/rudy.rb +76 -248
  60. data/lib/storable.rb +19 -16
  61. data/lib/sysinfo.rb +1 -1
  62. data/rudy.gemspec +88 -68
  63. data/support/rudy-ec2-startup +5 -5
  64. data/test/05_config/00_setup_test.rb +3 -7
  65. data/test/20_sdb/00_setup_test.rb +2 -17
  66. data/test/20_sdb/10_domains_test.rb +18 -16
  67. data/test/25_ec2/00_setup_test.rb +5 -10
  68. data/test/25_ec2/10_keypairs_test.rb +13 -5
  69. data/test/25_ec2/20_groups_test.rb +48 -56
  70. data/test/25_ec2/30_addresses_test.rb +13 -10
  71. data/test/25_ec2/40_volumes_test.rb +11 -8
  72. data/test/25_ec2/50_snapshots_test.rb +17 -12
  73. data/test/26_ec2_instances/00_setup_test.rb +3 -8
  74. data/test/26_ec2_instances/10_instances_test.rb +21 -19
  75. data/test/30_sdb_metadata/00_setup_test.rb +2 -9
  76. data/test/30_sdb_metadata/10_disks_test.rb +47 -37
  77. data/test/30_sdb_metadata/20_backups_test.rb +9 -9
  78. data/test/helper.rb +5 -3
  79. data/vendor/highline-1.5.1/CHANGELOG +222 -0
  80. data/vendor/highline-1.5.1/INSTALL +35 -0
  81. data/vendor/highline-1.5.1/LICENSE +7 -0
  82. data/vendor/highline-1.5.1/README +63 -0
  83. data/vendor/highline-1.5.1/Rakefile +82 -0
  84. data/vendor/highline-1.5.1/TODO +6 -0
  85. data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
  86. data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
  87. data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
  88. data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
  89. data/vendor/highline-1.5.1/examples/limit.rb +12 -0
  90. data/vendor/highline-1.5.1/examples/menus.rb +65 -0
  91. data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
  92. data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
  93. data/vendor/highline-1.5.1/examples/password.rb +7 -0
  94. data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
  95. data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
  96. data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
  97. data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
  98. data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
  99. data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
  100. data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
  101. data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
  102. data/vendor/highline-1.5.1/lib/highline.rb +758 -0
  103. data/vendor/highline-1.5.1/setup.rb +1360 -0
  104. data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
  105. data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
  106. data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
  107. data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
  108. data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
  109. metadata +81 -69
  110. data/lib/aws_sdb/error.rb +0 -42
  111. data/lib/aws_sdb/service.rb +0 -215
  112. data/lib/aws_sdb.rb +0 -3
  113. data/lib/rudy/aws/simpledb.rb +0 -71
  114. data/lib/rudy/cli/addresses.rb +0 -85
  115. data/lib/rudy/cli/backups.rb +0 -175
  116. data/lib/rudy/cli/domains.rb +0 -17
  117. data/lib/rudy/cli/groups.rb +0 -77
  118. data/lib/rudy/cli/images.rb +0 -111
  119. data/lib/rudy/cli/instances.rb +0 -142
  120. data/lib/rudy/cli/keypairs.rb +0 -47
  121. data/lib/rudy/cli/manager.rb +0 -51
  122. data/lib/rudy/cli/release.rb +0 -174
  123. data/lib/rudy/cli/volumes.rb +0 -121
  124. data/lib/rudy/command/addresses.rb +0 -69
  125. data/lib/rudy/command/backups.rb +0 -65
  126. data/lib/rudy/command/disks-old.rb +0 -322
  127. data/lib/rudy/command/disks.rb +0 -9
  128. data/lib/rudy/command/domains.rb +0 -34
  129. data/lib/rudy/command/groups.rb +0 -118
  130. data/lib/rudy/command/instances.rb +0 -278
  131. data/lib/rudy/command/keypairs.rb +0 -149
  132. data/lib/rudy/command/manager.rb +0 -65
  133. data/lib/rudy/command/volumes.rb +0 -127
  134. data/lib/rudy/metadata/disk.rb +0 -149
  135. data/lib/rudy/metadata/machine.rb +0 -34
  136. data/lib/rudy/routines/disk_handler.rb +0 -190
  137. data/lib/rudy/routines/script_runner.rb +0 -65
  138. data/test/50_commands/00_setup_test.rb +0 -11
  139. data/test/50_commands/10_keypairs_test.rb +0 -79
  140. data/test/50_commands/20_groups_test.rb +0 -77
  141. data/test/50_commands/40_volumes_test.rb +0 -55
  142. data/test/50_commands/50_instances_test.rb +0 -110
  143. data/tryouts/console_tryout.rb +0 -91
  144. data/tryouts/disks.rb +0 -55
  145. data/tryouts/nested_methods.rb +0 -36
  146. data/tryouts/session_tryout.rb +0 -46
@@ -1,175 +0,0 @@
1
-
2
-
3
-
4
-
5
- module Rudy
6
- module CLI
7
- class Backups < Rudy::CLI::Base
8
-
9
-
10
- def backup
11
- criteria = [@global.zone]
12
- criteria += [@global.environment, @global.role] unless @option.all
13
-
14
- Rudy::MetaData::Backup.list(@sdb, *criteria).each do |backup|
15
- puts "%s (%s)" % [backup.name, backup.awsid]
16
- end
17
- end
18
-
19
- # Check for backups pointing to snapshots that don't exist.
20
- def sync_backup
21
- unless argv.empty?
22
- puts "The disk you specified will be ignored."
23
- argv.clear
24
- end
25
-
26
- criteria = [@global.zone]
27
- criteria += [@global.environment, @global.role] unless @option.all
28
-
29
- puts "Looking for backup metadata with delinquent snapshots..."
30
- to_be_deleted = {} # snap-id => backup
31
- Rudy::MetaData::Backup.list(@sdb, *criteria).each do |backup|
32
- to_be_deleted[backup.awsid] = backup unless @ec2.snapshots.exists?(backup.awsid)
33
- end
34
-
35
- if to_be_deleted.empty?
36
- puts "All backups are in-sync with snapshots. Nothing to do."
37
- return
38
- end
39
-
40
- puts
41
- puts "These backup metadata will be deleted:"
42
- to_be_deleted.each do |snap_id, backup|
43
- puts "%s: %s" % [snap_id, backup.name]
44
- end
45
-
46
- puts
47
- exit unless Annoy.are_you_sure?
48
-
49
- puts
50
- puts "Deleting..."
51
- to_be_deleted.each do |snap_id, backup|
52
- print " -> #{backup.name}... "
53
- @sdb.destroy(RUDY_DOMAIN, backup.name)
54
- puts "done"
55
- end
56
-
57
- puts "Done!"
58
- end
59
-
60
- def destroy_backup_valid?
61
- raise "No backup specified" if argv.empty?
62
- exit unless Annoy.are_you_sure?(:high)
63
- true
64
- end
65
-
66
- def destroy_backup
67
- name = @argv.first
68
- puts "Destroying #{name}"
69
- begin
70
- backup = Rudy::MetaData::Backup.get(@sdb, name)
71
- rescue => ex
72
- puts "Error deleteing backup: #{ex.message}"
73
- end
74
-
75
- return unless backup
76
-
77
- begin
78
- puts " -> deleting snapshot..."
79
- @ec2.snapshots.destroy(backup.awsid)
80
- rescue => ex
81
- puts "Error deleting snapshot: #{ex.message}."
82
- puts "Continuing..."
83
- ensure
84
- puts " -> deleting metadata..."
85
- @sdb.destroy(RUDY_DOMAIN, name)
86
- end
87
- puts "Done."
88
- end
89
-
90
- def create_backup
91
- diskname = @argv.first
92
-
93
- machine = find_current_machine
94
-
95
- disks = Rudy::MetaData::Disk.list(@sdb, machine[:aws_availability_zone], @global.environment, @global.role, @global.position)
96
- raise "The machine #{machine_name} does not have any disk metadata" if disks.empty?
97
-
98
- puts "Machine: #{machine_name}"
99
-
100
- if @option.snapshot
101
- raise "You must supply a diskname when using an existing snapshot" unless diskname
102
- raise "The snapshot #{@option.snapshot} does not exist" unless @ec2.snapshots.exists?(@option.snapshot)
103
- disk = Rudy::MetaData::Disk.get(@sdb, diskname)
104
-
105
- raise "The disk #{diskname} does not exist" unless disk
106
- backup = Rudy::MetaData::Backup.new
107
- backup.awsid = @option.snapshot
108
- backup.time_stamp
109
-
110
- # Populate machine infos
111
- [:zone, :environment, :role, :position].each do |n|
112
- backup.send("#{n}=", @global.send(n)) if @global.send(n)
113
- end
114
-
115
- # Populate disk infos
116
- [:path, :size].each do |n|
117
- backup.send("#{n}=", disk.send(n)) if disk.send(n)
118
- end
119
-
120
-
121
- Rudy::MetaData::Backup.save(@sdb, backup)
122
-
123
- puts backup.name
124
-
125
- else
126
- volumes = @ec2.instances.volumes(machine[:aws_instance_id])
127
- raise "The machine #{machine_name} does not have any volumes attached." if volumes.empty?
128
-
129
- puts "#{disks.size} Disk(s) defined with #{volumes.size} Volume(s) running"
130
-
131
- volumes.each do |volume|
132
- print "Volume #{volume[:aws_id]}... "
133
- disk = Rudy::MetaData::Disk.find_from_volume(@sdb, volume[:aws_id])
134
- backup = Rudy::MetaData::Backup.new
135
-
136
- # TODO: Look for the disk based on the machine
137
- raise "No disk associated to volume #{volume[:aws_id]}" unless disk
138
-
139
- backup.volume = volume[:aws_id]
140
-
141
- # Populate machine infos
142
- [:zone, :environment, :role, :position].each do |n|
143
- backup.send("#{n}=", @global.send(n)) if @global.send(n)
144
- end
145
-
146
- # Populate disk infos
147
- [:path, :size].each do |n|
148
- backup.send("#{n}=", disk.send(n)) if disk.send(n)
149
- end
150
-
151
- backup.time_stamp
152
-
153
- raise "There was a problem creating the backup metadata" unless backup.valid?
154
-
155
- snap = @ec2.snapshots.create(volume[:aws_id])
156
-
157
- if !snap || !snap.is_a?(Hash)
158
- puts "There was an unknown problem creating #{backup.name}. Continuing with the next volume..."
159
- next
160
- end
161
-
162
- backup.awsid = snap[:aws_id]
163
-
164
- Rudy::MetaData::Backup.save(@sdb, backup)
165
-
166
- puts backup.name
167
-
168
- end
169
- end
170
- end
171
-
172
-
173
- end
174
- end
175
- end
@@ -1,17 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module CLI
5
- class Domains < Rudy::CLI::Base
6
-
7
-
8
- def domains
9
- puts "Domains".bright, $/
10
-
11
- rdom = Rudy::Domains.new(:config => @config, :global => @global)
12
- puts rdom.list
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,77 +0,0 @@
1
-
2
- #
3
- #
4
- module Rudy
5
- module CLI
6
- class Groups < Rudy::CLI::Base
7
-
8
- def group
9
- puts "Machine Groups".bright
10
- opts = {}
11
- name = @option.all ? nil : @argv.name
12
- rudy = Rudy::Groups.new(:config => @config, :global => @global)
13
- rudy.list(name).each do |grp|
14
- puts '-'*60
15
- puts grp.to_s
16
- end
17
- end
18
-
19
- def destroy_group_valid?
20
- @rgroup = Rudy::Groups.new(:config => @config, :global => @global)
21
- raise "Group #{@rgroup.name(@argv.name)} does not exist" unless @rgroup.exists?(@argv.name)
22
- true
23
- end
24
-
25
- def destroy_group
26
- puts "Destroying Machine Group".bright
27
- opts = {}
28
- puts "Destroying group: #{@rgroup.name(@argv.name)}"
29
- exit unless Annoy.are_you_sure?(:medium)
30
-
31
- @rgroup.destroy(@argv.name)
32
- puts "Done!"
33
- end
34
-
35
- def create_group
36
- puts "Creating Machine Group".bright
37
- opts = check_options
38
- exit unless Annoy.are_you_sure?(:medium)
39
- rudy = Rudy::Groups.new(:config => @config, :global => @global)
40
- rudy.create(@argv.name, nil, opts)
41
- rudy.list(@argv.name)
42
- end
43
-
44
- def revoke_group
45
- puts "Revoke Machine Group Rule".bright
46
- opts = check_options
47
- exit unless Annoy.are_you_sure?(:medium)
48
- rudy = Rudy::Groups.new(:config => @config, :global => @global)
49
- rudy.revoke(@argv.name, opts)
50
- rudy.list(@argv.name)
51
- end
52
-
53
- def authorize_group
54
- puts "Authorize Machine Group Rule".bright
55
- opts = check_options
56
- exit unless Annoy.are_you_sure?(:medium)
57
- rudy = Rudy::Groups.new(:config => @config, :global => @global)
58
- rudy.authorize(opts)
59
- rudy.list(opts)
60
- end
61
-
62
-
63
- private
64
-
65
- def check_options
66
- opts = {}
67
- [:addresses, :protocols, :owner, :group, :ports].each do |opt|
68
- opts[opt] = @option.send(opt) if @option.respond_to?(opt)
69
- end
70
- opts[:ports].collect! { |port| port.split(/:/) } if opts[:ports]
71
- opts
72
- end
73
-
74
- end
75
- end
76
- end
77
-
@@ -1,111 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module CLI
5
- class Images < Rudy::CLI::Base
6
-
7
-
8
- def images
9
- @ec2.images.list.each do |img|
10
- print_image img
11
- end
12
- end
13
-
14
- def create_images_valid?
15
- puts "Make sure the machine is clean. I don't want archive no crud!"
16
- switch_user("root")
17
-
18
- raise "No EC2 .pem keys provided" unless has_pem_keys?
19
- raise "No SSH key provided for #{@global.user}!" unless has_keypair?
20
- raise "No SSH key provided for root!" unless has_keypair?(:root)
21
- true
22
- end
23
-
24
-
25
- def prepare_images
26
- # TODO: Avail hooks for clean an instance
27
- # Clean off Rudy specific crap.
28
- end
29
-
30
-
31
- def create_images
32
- puts "Creating image from #{machine_group}"
33
-
34
- # ~/.rudy, /etc/motd, history -c, /etc/hosts, /var/log/rudy*
35
-
36
- exit unless Annoy.are_you_sure?(:medium)
37
-
38
-
39
- machine_list = @ec2.instances.list(machine_group)
40
- machine = machine_list.values.first # NOTE: Only one machine per group, for now...
41
-
42
- raise "There's no machine running in #{machine_group}" unless machine
43
- raise "The primary machine in #{machine_group} is not in a running state" unless machine[:aws_state] == 'running'
44
-
45
- puts "The new image will be based on #{machine_group}_01"
46
-
47
- @option.account ||= @config.accounts.aws.accountnum
48
-
49
- unless @option.account
50
- puts "Enter your 12 digit Amazon account number:"
51
- @global.account = gets.chomp
52
- end
53
-
54
- unless @option.image_name
55
- puts "Enter the image name:"
56
- @option.image_name = gets.chomp
57
- end
58
-
59
- unless @option.bucket_name
60
- puts "Enter the S3 bucket that will store the image:"
61
- @option.bucket_name = gets.chomp
62
- end
63
-
64
- unless @option.print
65
- puts "Copying .pem keys to /mnt (they will not be included in the AMI)"
66
- scp_command machine[:dns_name], keypairpath, @global.user, @global.cert, "/mnt/"
67
- scp_command machine[:dns_name], keypairpath, @global.user, @global.privatekey, "/mnt/"
68
- end
69
-
70
- ssh do |session|
71
- session.exec!("touch /root/firstrun")
72
- end
73
-
74
- puts "Starting bundling process...".bright
75
- puts ssh_command(machine[:dns_name], keypairpath, @global.user, "ec2-bundle-vol -r i386 -p #{@option.image_name} -k /mnt/pk-*pem -c /mnt/cert*pem -u #{@option.account}", @option.print)
76
- puts ssh_command(machine[:dns_name], keypairpath, @global.user, "ec2-upload-bundle -b #{@option.bucket_name} -m /tmp/#{@option.image_name}.manifest.xml -a #{@global.accesskey} -s #{@global.secretkey}", @option.print)
77
-
78
- @ec2.images.register("#{@option.bucket_name}/#{@option.image_name}.manifest.xml") unless @option.print
79
- end
80
-
81
- def deregister
82
- ami = @argv.first
83
- raise "You must supply an AMI ID (ami-XXXXXXX)" unless ami
84
- puts "Deregistering AMI: #{ami}"
85
-
86
- exit unless Annoy.are_you_sure?
87
-
88
- if @ec2.images.deregister(ami)
89
- puts "Done!"
90
- else
91
- puts "There was an unknown problem!"
92
- end
93
-
94
- end
95
-
96
-
97
- def print_image(img)
98
- puts '-'*60
99
- puts "Image: #{img[:aws_id].bright}"
100
- img.each_pair do |key, value|
101
- printf(" %22s: %s#{$/}", key, value) if value
102
- end
103
- puts
104
- end
105
-
106
-
107
-
108
- end
109
- end
110
- end
111
-
@@ -1,142 +0,0 @@
1
-
2
-
3
- module Rudy::CLI
4
- class Instances < Rudy::CLI::Base
5
-
6
- def connect
7
- puts "Rudy Connect".bright
8
-
9
- if @argv.cmd
10
- @argv.cmd = [@argv.cmd].flatten.join(' ')
11
- if @global.user.to_s == "root"
12
- exit unless Annoy.are_you_sure?(:medium)
13
- end
14
- end
15
-
16
- rudy = Rudy::Instances.new(:config => @config, :global => @global)
17
- rudy.connect(@option.group, @argv.cmd, @option.awsid, @option.print)
18
- end
19
-
20
- def copy_valid?
21
- raise "You must supply a source and a target. See rudy #{@alias} -h" unless @argv.size >= 2
22
- raise "You cannot download and upload at the same time" if @option.download && @alias == 'upload'
23
- true
24
- end
25
- def copy
26
- puts "Rudy Copy".bright
27
- opts = {}
28
- opts[:group] = @option.group if @option.group
29
- opts[:id] = @option.awsid if @option.awsid
30
- opts[:id] &&= [opts[:id]].flatten
31
-
32
- # Is this more clear?
33
- @option.recursive && opts[:recursive] = true
34
- @option.preserve && opts[:preserve] = true
35
- @option.print && opts[:print] = true
36
-
37
-
38
- opts[:paths] = @argv
39
- opts[:dest] = opts[:paths].pop
40
-
41
- opts[:task] = :download if @alias == 'download' || @option.download
42
- opts[:task] = :upload if @alias == 'upload'
43
- opts[:task] ||= :upload
44
-
45
- #exit unless @option.print || Annoy.are_you_sure?(:low)
46
-
47
- rudy = Rudy::Instances.new(:config => @config, :global => @global)
48
- rudy.copy(opts[:group], opts[:id], opts)
49
- end
50
-
51
-
52
- def status
53
- puts "Instance Status".bright
54
- opts = {}
55
- opts[:group] = @option.group if @option.group
56
- opts[:state] = @option.state if @option.state
57
-
58
- # A nil value forces the @ec2.instances.list to return all instances
59
- if @option.all
60
- opts[:state] = :any
61
- opts[:group] = :any
62
- end
63
-
64
- opts[:id] = @argv.awsid if @argv.awsid
65
- opts[:id] &&= [opts[:id]].flatten
66
- rudy = Rudy::Instances.new(:config => @config, :global => @global)
67
-
68
- lt = rudy.list(opts[:state], opts[:group], opts[:id]) do |inst|
69
- puts '-'*60
70
- puts "Instance: #{inst.awsid.bright} (AMI: #{inst.ami})"
71
- puts inst.to_s
72
- end
73
- puts "No instances running" if !lt || lt.empty?
74
- end
75
- alias :instance :status
76
-
77
- def console_valid?
78
-
79
- @rmach = Rudy::Instances.new(:config => @config, :global => @global)
80
- end
81
-
82
- def console
83
- puts "Instance Console".bright
84
- opts = {}
85
- opts[:group] = @option.group if @option.group
86
- opts[:id] = @argv.awsid if @argv.awsid
87
- opts[:id] &&= [opts[:id]].flatten
88
-
89
- unless @rmach.any?
90
- puts "No instances running"
91
- return
92
- end
93
-
94
- console = @rmach.console(opts[:group], opts[:id])
95
-
96
- if console
97
- puts console
98
- else
99
- puts "Console output is not available"
100
- end
101
-
102
- end
103
-
104
-
105
- def instance_create
106
- puts "Create Instance".bright
107
- opts = {}
108
- [:group, :ami, :address, :itype, :keypair].each do |n|
109
- opts[n] = @option.send(n) if @option.send(n)
110
- end
111
-
112
- rmach = Rudy::Instances.new(:config => @config, :global => @global)
113
- # TODO: Print number of instances running. If more than 0, use Annoy.are_you_sure?
114
- rmach.create(opts) do |inst| # Rudy::AWS::EC2::Instance objects
115
- puts '-'*60
116
- puts "Instance: #{inst.awsid.bright} (AMI: #{inst.ami})"
117
- puts inst.to_s
118
- end
119
-
120
- end
121
-
122
-
123
- def instance_destroy
124
- puts "Destroy Instances".bright
125
- opts = {}
126
- opts[:group] = @option.group if @option.group
127
- opts[:id] = @argv.awsid if @argv.awsid
128
- opts[:id] &&= [opts[:id]].flatten
129
-
130
- rmach = Rudy::Instances.new(:config => @config, :global => @global)
131
- instances = rmach.list(:running, opts[:group], opts[:id])
132
- raise "No instances running" if instances.nil? || instances.empty?
133
- puts "Destroying #{instances.size} instances in #{instances.first.groups.first}"
134
- exit unless Annoy.are_you_sure?(:low)
135
- rmach.destroy(opts[:group], opts[:id])
136
- puts "Done!"
137
- end
138
-
139
- end
140
- end
141
-
142
-
@@ -1,47 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module CLI
5
- class KeyPairs < Rudy::CLI::Base
6
-
7
- def create_keypair
8
- puts "Create KeyPairs".bright
9
- rkey = Rudy::KeyPairs.new(:config => @config, :global => @global)
10
- name = @argv.kpname
11
-
12
- rkey.create(@argv.kpname, :force => false)
13
- rkey.list.each do |kp|
14
- puts kp.to_s
15
- end
16
- end
17
-
18
-
19
- def destroy_keypair
20
- puts "Destroy KeyPairs".bright
21
- rkey = Rudy::KeyPairs.new(:config => @config, :global => @global)
22
- raise "KeyPair #{rkey.name(@argv.kpname)} does not exist" unless rkey.exists?(@argv.kpname)
23
- kp = rkey.get(@argv.kpname)
24
- puts "Destroying keypair: #{kp.name}"
25
- puts "NOTE: the private key file will also be deleted and you will not be able to".color(:blue)
26
- puts "connect to instances started with this keypair.".color(:blue)
27
- exit unless Annoy.are_you_sure?(:low)
28
- ret = rkey.destroy(@argv.kpname)
29
- puts ret ? "Success" : "Failed"
30
- end
31
-
32
- def keypair
33
- puts "KeyPairs".bright
34
- rkey = Rudy::KeyPairs.new(:config => @config, :global => @global)
35
-
36
- rkey.list.each do |kp|
37
- puts kp.to_s
38
- end
39
-
40
- puts "No keypairs" unless rkey.any?
41
-
42
- end
43
-
44
-
45
- end
46
- end
47
- end
@@ -1,51 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module CLI
5
- class Manager < Rudy::CLI::Base
6
-
7
-
8
- # Print Rudy's metadata to STDOUT
9
- def metadata
10
- group_metadata.each_pair do |n,h|
11
- puts n.bright
12
- puts h.inspect, ""
13
- end
14
- end
15
-
16
- def destroy_metadata_valid?
17
- false
18
- end
19
-
20
- def destroy_metadata
21
- @sdb.domains.destroy(RUDY_DOMAIN)
22
- end
23
-
24
- # TODO: WHERE TO CREATE DOMAIN???????????????????????????
25
-
26
- def create_domain
27
- puts "Creating SimpleDB Domain called #{RUDY_DOMAIN}".bright
28
- rmanager = Rudy::Manager.new(:config => @config, :global => @global)
29
- rmanager.create_domain(RUDY_DOMAIN)
30
- doms = rmanager.domains || []
31
- puts "Domains: #{doms.join(", ")}"
32
- end
33
-
34
- def info
35
- puts "Rudy Manager".bright
36
- rmanager = Rudy::Manager.new(:config => @config, :global => @global)
37
- doms = rmanager.domains
38
- puts "Domains: #{doms.join(", ")}"
39
- end
40
-
41
- private
42
- def check_environment
43
- raise "No Amazon keys provided!" unless has_keys?
44
- raise "No SSH keypairs provided!" unless has_keypair?
45
- true
46
- end
47
-
48
- end
49
- end
50
- end
51
-