rudy 0.4.0 → 0.6.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 +54 -30
  2. data/README.rdoc +100 -12
  3. data/Rakefile +103 -8
  4. data/Rudyfile +119 -0
  5. data/bin/ird +175 -0
  6. data/bin/rudy +259 -156
  7. data/bin/rudy-ec2 +228 -95
  8. data/bin/rudy-s3 +76 -0
  9. data/bin/rudy-sdb +67 -0
  10. data/lib/annoy.rb +270 -0
  11. data/lib/console.rb +30 -9
  12. data/lib/escape.rb +305 -0
  13. data/lib/rudy.rb +151 -182
  14. data/lib/rudy/aws.rb +56 -49
  15. data/lib/rudy/aws/ec2.rb +47 -292
  16. data/lib/rudy/aws/ec2/address.rb +157 -0
  17. data/lib/rudy/aws/ec2/group.rb +301 -0
  18. data/lib/rudy/aws/ec2/image.rb +168 -0
  19. data/lib/rudy/aws/ec2/instance.rb +434 -0
  20. data/lib/rudy/aws/ec2/keypair.rb +104 -0
  21. data/lib/rudy/aws/ec2/snapshot.rb +98 -0
  22. data/lib/rudy/aws/ec2/volume.rb +230 -0
  23. data/lib/rudy/aws/ec2/zone.rb +77 -0
  24. data/lib/rudy/aws/s3.rb +54 -0
  25. data/lib/rudy/aws/sdb.rb +298 -0
  26. data/lib/rudy/aws/sdb/error.rb +46 -0
  27. data/lib/rudy/{metadata/backup.rb → backup.rb} +26 -51
  28. data/lib/rudy/cli.rb +157 -0
  29. data/lib/rudy/cli/aws/ec2/addresses.rb +105 -0
  30. data/lib/rudy/cli/aws/ec2/candy.rb +208 -0
  31. data/lib/rudy/cli/aws/ec2/groups.rb +121 -0
  32. data/lib/rudy/cli/aws/ec2/images.rb +196 -0
  33. data/lib/rudy/cli/aws/ec2/instances.rb +194 -0
  34. data/lib/rudy/cli/aws/ec2/keypairs.rb +53 -0
  35. data/lib/rudy/cli/aws/ec2/snapshots.rb +49 -0
  36. data/lib/rudy/cli/aws/ec2/volumes.rb +104 -0
  37. data/lib/rudy/cli/aws/ec2/zones.rb +22 -0
  38. data/lib/rudy/cli/aws/s3/buckets.rb +50 -0
  39. data/lib/rudy/cli/aws/s3/store.rb +22 -0
  40. data/lib/rudy/cli/aws/sdb/domains.rb +41 -0
  41. data/lib/rudy/cli/candy.rb +8 -0
  42. data/lib/rudy/{command → cli}/config.rb +34 -24
  43. data/lib/rudy/cli/disks.rb +35 -0
  44. data/lib/rudy/cli/machines.rb +94 -0
  45. data/lib/rudy/cli/routines.rb +57 -0
  46. data/lib/rudy/config.rb +77 -72
  47. data/lib/rudy/config/objects.rb +29 -0
  48. data/lib/rudy/disks.rb +248 -0
  49. data/lib/rudy/global.rb +121 -0
  50. data/lib/rudy/huxtable.rb +340 -0
  51. data/lib/rudy/machines.rb +245 -0
  52. data/lib/rudy/metadata.rb +123 -13
  53. data/lib/rudy/routines.rb +47 -0
  54. data/lib/rudy/routines/helpers/diskhelper.rb +101 -0
  55. data/lib/rudy/routines/helpers/scripthelper.rb +91 -0
  56. data/lib/rudy/routines/release.rb +34 -0
  57. data/lib/rudy/routines/shutdown.rb +57 -0
  58. data/lib/rudy/routines/startup.rb +58 -0
  59. data/lib/rudy/scm/svn.rb +1 -1
  60. data/lib/rudy/utils.rb +322 -4
  61. data/lib/storable.rb +26 -17
  62. data/lib/sysinfo.rb +274 -0
  63. data/lib/tryouts.rb +6 -13
  64. data/rudy.gemspec +128 -42
  65. data/support/randomize-root-password +45 -0
  66. data/support/rudy-ec2-startup +9 -9
  67. data/support/update-ec2-ami-tools +20 -0
  68. data/test/05_config/00_setup_test.rb +20 -0
  69. data/test/05_config/30_machines_test.rb +69 -0
  70. data/test/20_sdb/00_setup_test.rb +16 -0
  71. data/test/20_sdb/10_domains_test.rb +115 -0
  72. data/test/25_ec2/00_setup_test.rb +29 -0
  73. data/test/25_ec2/10_keypairs_test.rb +41 -0
  74. data/test/25_ec2/20_groups_test.rb +131 -0
  75. data/test/25_ec2/30_addresses_test.rb +38 -0
  76. data/test/25_ec2/40_volumes_test.rb +49 -0
  77. data/test/25_ec2/50_snapshots_test.rb +74 -0
  78. data/test/26_ec2_instances/00_setup_test.rb +28 -0
  79. data/test/26_ec2_instances/10_instances_test.rb +83 -0
  80. data/test/26_ec2_instances/50_images_test.rb +13 -0
  81. data/test/30_sdb_metadata/00_setup_test.rb +21 -0
  82. data/test/30_sdb_metadata/10_disks_test.rb +109 -0
  83. data/test/30_sdb_metadata/20_backups_test.rb +102 -0
  84. data/test/coverage.txt +51 -0
  85. data/test/helper.rb +36 -0
  86. data/vendor/highline-1.5.1/CHANGELOG +222 -0
  87. data/vendor/highline-1.5.1/INSTALL +35 -0
  88. data/vendor/highline-1.5.1/LICENSE +7 -0
  89. data/vendor/highline-1.5.1/README +63 -0
  90. data/vendor/highline-1.5.1/Rakefile +82 -0
  91. data/vendor/highline-1.5.1/TODO +6 -0
  92. data/vendor/highline-1.5.1/examples/ansi_colors.rb +38 -0
  93. data/vendor/highline-1.5.1/examples/asking_for_arrays.rb +18 -0
  94. data/vendor/highline-1.5.1/examples/basic_usage.rb +75 -0
  95. data/vendor/highline-1.5.1/examples/color_scheme.rb +32 -0
  96. data/vendor/highline-1.5.1/examples/limit.rb +12 -0
  97. data/vendor/highline-1.5.1/examples/menus.rb +65 -0
  98. data/vendor/highline-1.5.1/examples/overwrite.rb +19 -0
  99. data/vendor/highline-1.5.1/examples/page_and_wrap.rb +322 -0
  100. data/vendor/highline-1.5.1/examples/password.rb +7 -0
  101. data/vendor/highline-1.5.1/examples/trapping_eof.rb +22 -0
  102. data/vendor/highline-1.5.1/examples/using_readline.rb +17 -0
  103. data/vendor/highline-1.5.1/lib/highline.rb +758 -0
  104. data/vendor/highline-1.5.1/lib/highline/color_scheme.rb +120 -0
  105. data/vendor/highline-1.5.1/lib/highline/compatibility.rb +17 -0
  106. data/vendor/highline-1.5.1/lib/highline/import.rb +43 -0
  107. data/vendor/highline-1.5.1/lib/highline/menu.rb +395 -0
  108. data/vendor/highline-1.5.1/lib/highline/question.rb +463 -0
  109. data/vendor/highline-1.5.1/lib/highline/system_extensions.rb +193 -0
  110. data/vendor/highline-1.5.1/setup.rb +1360 -0
  111. data/vendor/highline-1.5.1/test/tc_color_scheme.rb +56 -0
  112. data/vendor/highline-1.5.1/test/tc_highline.rb +823 -0
  113. data/vendor/highline-1.5.1/test/tc_import.rb +54 -0
  114. data/vendor/highline-1.5.1/test/tc_menu.rb +429 -0
  115. data/vendor/highline-1.5.1/test/ts_all.rb +15 -0
  116. metadata +141 -38
  117. data/lib/aws_sdb.rb +0 -3
  118. data/lib/aws_sdb/error.rb +0 -42
  119. data/lib/aws_sdb/service.rb +0 -215
  120. data/lib/rudy/aws/simpledb.rb +0 -53
  121. data/lib/rudy/command/addresses.rb +0 -46
  122. data/lib/rudy/command/backups.rb +0 -175
  123. data/lib/rudy/command/base.rb +0 -841
  124. data/lib/rudy/command/deploy.rb +0 -12
  125. data/lib/rudy/command/disks.rb +0 -213
  126. data/lib/rudy/command/environment.rb +0 -73
  127. data/lib/rudy/command/groups.rb +0 -61
  128. data/lib/rudy/command/images.rb +0 -91
  129. data/lib/rudy/command/instances.rb +0 -85
  130. data/lib/rudy/command/machines.rb +0 -161
  131. data/lib/rudy/command/metadata.rb +0 -41
  132. data/lib/rudy/command/release.rb +0 -174
  133. data/lib/rudy/command/volumes.rb +0 -66
  134. data/lib/rudy/metadata/disk.rb +0 -138
  135. data/tryouts/console_tryout.rb +0 -91
@@ -1,66 +0,0 @@
1
-
2
-
3
- module Rudy
4
- module Command
5
- class Volumes < Rudy::Command::Base
6
-
7
- def destroy_volumes_valid?
8
- id = @argv.first
9
- raise "No volume ID provided" unless id
10
- raise "I will not help you destroy production!" if @global.environment == "prod"
11
- raise "The volume #{id} doesn't exist!" unless @ec2.volumes.exists?(id)
12
- exit unless are_you_sure? 4
13
- true
14
- end
15
-
16
- def destroy_volumes
17
- id = @argv.first
18
- disk = Rudy::MetaData::Disk.find_from_volume(@sdb, id)
19
-
20
- begin
21
- puts "Detaching #{id}"
22
- @ec2.volumes.detach(id)
23
- sleep 3
24
-
25
- puts "Destroying #{id}"
26
- @ec2.volumes.destroy(id)
27
-
28
- if disk
29
- puts "Deleteing metadata for #{disk.name}"
30
- Rudy::MetaData::Disk.destroy(@sdb, disk)
31
- end
32
-
33
- rescue => ex
34
- puts "Error while detaching volume #{id}: #{ex.message}"
35
- end
36
-
37
-
38
- end
39
-
40
- def volumes
41
- machines = {}
42
- volumes = @ec2.volumes.list
43
- @ec2.volumes.list.each do |volume|
44
- machine = @ec2.instances.get(volume[:aws_instance_id])
45
- machines[ volume[:aws_instance_id] ] ||= {
46
- :machine => machine,
47
- :volumes => []
48
- }
49
- machines[ volume[:aws_instance_id] ][:volumes] << volume
50
- end
51
-
52
- machines.each_pair do |instance_id, hash|
53
- machine = hash[:machine]
54
- env = (machine[:aws_groups]) ? machine[:aws_groups] : "Not-attached"
55
- puts "Environment: #{env}"
56
- hash[:volumes].each do |vol|
57
- disk = Rudy::MetaData::Disk.find_from_volume(@sdb, vol[:aws_id])
58
- print_volume(vol, disk)
59
- end
60
- end
61
- end
62
-
63
- end
64
- end
65
- end
66
-
@@ -1,138 +0,0 @@
1
-
2
-
3
- module Rudy
4
-
5
- module MetaData
6
- class Disk < Storable
7
-
8
- @@rtype = 'disk'
9
-
10
- # This is a flag used internally to specify that a volume has been
11
- # created for this disk, but not formated.
12
- attr_accessor :raw_volume
13
-
14
- field :rtype
15
- field :awsid
16
-
17
- field :environment
18
- field :role
19
- field :path
20
- field :position
21
-
22
- field :zone
23
- field :region
24
- field :device
25
- #field :backups => Array
26
- field :size
27
-
28
- def initialize
29
- @backups = []
30
- @rtype = @@rtype.to_s
31
- @raw_volume = false
32
- end
33
-
34
- def rtype
35
- @@rtype.to_s
36
- end
37
-
38
- def rtype=(val)
39
- end
40
-
41
- def name
42
- Disk.generate_name(@zone, @environment, @role, @position, @path)
43
- end
44
-
45
- def valid?
46
- @zone && @environment && @role && @position && @path && @size && @device
47
- end
48
-
49
- def to_query(more=[], remove=[])
50
- criteria = [:rtype, :zone, :environment, :role, :position, :path, *more]
51
- criteria -= [*remove].flatten
52
- query = []
53
- criteria.each do |n|
54
- query << "['#{n}' = '#{self.send(n.to_sym)}'] "
55
- end
56
- query.join(" intersection ")
57
- end
58
-
59
- def to_s
60
- str = ""
61
- field_names.each do |key|
62
- str << sprintf(" %22s: %s#{$/}", key, self.send(key.to_sym))
63
- end
64
- str
65
- end
66
-
67
- def Disk.generate_name(zon, env, rol, pos, pat, sep=File::SEPARATOR)
68
- pos = pos.to_s.rjust 2, '0'
69
- dirs = pat.split sep if pat
70
- dirs.shift while dirs && (dirs[0].nil? || dirs[0].empty?)
71
- ["disk", zon, env, rol, pos, *dirs].join(RUDY_DELIM)
72
- end
73
-
74
- def Disk.get(sdb, name)
75
- disk = sdb.get_attributes(RUDY_DOMAIN, name)
76
- return nil unless disk && disk.has_key?(:attributes) && !disk[:attributes].empty?
77
- # raise "Disk #{name} does not exist!" unless
78
- Rudy::MetaData::Disk.from_hash(disk[:attributes])
79
- end
80
-
81
- def Disk.destroy(sdb, disk)
82
- disk = Disk.get(sdb, disk) if disk.is_a?(String) # get raises an exception if the disk doesn't exist
83
- sdb.destroy(RUDY_DOMAIN, disk.name)
84
- true # wtf: RightAws::SimpleDB doesn't tell us whether it succeeds. We'll assume!
85
- end
86
-
87
- def Disk.save(sdb, disk)
88
- sdb.store(RUDY_DOMAIN, disk.name, disk.to_hash, :replace)
89
- end
90
-
91
- def Disk.is_defined?(sdb, disk)
92
- # We don't care about the path, but we do care about the device
93
- # which is not part of the disk's name.
94
- query = disk.to_query(:device, :path)
95
- !sdb.query_with_attributes(RUDY_DOMAIN, query).empty?
96
- end
97
-
98
- def Disk.find_from_volume(sdb, vol_id)
99
- query = "['awsid' = '#{vol_id}']"
100
- res = sdb.query_with_attributes(RUDY_DOMAIN, query)
101
- if res.empty?
102
- nil
103
- else
104
- disk = Rudy::MetaData::Disk.from_hash(res.values.first)
105
- end
106
- end
107
-
108
-
109
- def Disk.find_from_path(sdb, path)
110
- query = "['path' = '#{path}']"
111
- res = sdb.query_with_attributes(RUDY_DOMAIN, query)
112
- if res.empty?
113
- nil
114
- else
115
- disk = Rudy::MetaData::Disk.from_hash(res.values.first)
116
- end
117
- end
118
-
119
- def Disk.list(sdb, zon, env=nil, rol=nil, pos=nil)
120
- query = ''
121
- query << "['rtype' = '#{@@rtype}']" if zon
122
- query << " intersection ['zone' = '#{zon}']" if zon
123
- query << " intersection ['environment' = '#{env}']" if env
124
- query << " intersection ['role' = '#{rol}']" if rol
125
- query << " intersection ['position' = '#{pos}']" if pos
126
-
127
- list = []
128
- sdb.query_with_attributes(RUDY_DOMAIN, query).each_pair do |name, hash|
129
- #puts "DISK: #{hash.to_yaml}"
130
- list << Rudy::MetaData::Disk.from_hash(hash)
131
- end
132
- list
133
- end
134
- end
135
-
136
- end
137
-
138
- end
@@ -1,91 +0,0 @@
1
- RUDY_HOME = File.join(File.dirname(__FILE__), '..')
2
- RUDY_LIB = File.join(RUDY_HOME, 'lib')
3
- $:.unshift RUDY_LIB # Put our local lib in first place
4
-
5
- require 'yaml'
6
- require 'date'
7
-
8
- require 'tryouts'
9
- require 'console'
10
-
11
- raise "Sorry Ruby 1.9 only!" unless RUBY_VERSION =~ /1.9/
12
-
13
- before do
14
- @title = "RUDY v0.3"
15
- @now_utc = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")
16
- @props = {
17
- :zone => "us-east-1b",
18
- :environment => "stage",
19
- :role =>"app",
20
- :position => "01"
21
- }
22
- # PROMPT_COMMAND
23
- end
24
-
25
- after do
26
- #Console.clear
27
- end
28
-
29
-
30
- tryout :positioned do
31
- Console.print_at(@title, {:y => Cursor.y, :x => Cursor.x })
32
- sleep 1
33
- Console.print_at(@now_utc, {:y => Cursor.y, :x => Console.width, :minus => true})
34
- puts
35
- sleep 1
36
- Console.print_left(@title)
37
- sleep 1
38
- Console.print_right(@now_utc)
39
- puts
40
- sleep 1
41
- Console.print_spaced('1'*25, 2, 3, '4'*30, 5, 6)
42
- puts
43
- sleep 1
44
- Console.print_center(Window.bar(50))
45
-
46
- end
47
-
48
- tryout :u_r_d_l do
49
- puts
50
- Cursor.up && print('.')
51
- sleep 1
52
- Cursor.right && print('.')
53
- sleep 1
54
- Cursor.left && Cursor.down && print('.')
55
- sleep 1
56
- Cursor.left(3) && print('.')
57
- end
58
-
59
- tryout :update_inplace do
60
- [(0..11).to_a, (90..110).to_a].flatten.each do |i|
61
- Console.print_at(i, {:y => Cursor.y, :x => 4 })
62
- sleep 0.05
63
- end
64
-
65
- end
66
-
67
-
68
- tryout :danger! do
69
- win = Window.new(:width => 100, :height => 100)
70
-
71
- # DEBUGGING: There is a threading bug where the values of props and the
72
- # string to print are being shared. Make Console and class and give an instance
73
- # to each thread. However, that could fuck up shit like Cursor.position.
74
-
75
-
76
- win.static(:right, 0.2, {:y => 0}) do
77
- Time.now.utc.strftime("%Y-%m-%d %H:%M:%S").colour(:blue, :white, :underline)
78
- end
79
- win.static(:left, 0.2) do
80
- rand
81
- end
82
-
83
- win.join_threads
84
-
85
- puts $/, "Done!"
86
-
87
- end
88
-
89
-
90
-
91
-