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.
- data/CHANGES.txt +110 -18
- data/README.rdoc +40 -44
- data/Rudyfile +35 -50
- data/bin/rudy +88 -57
- data/bin/rudy-ec2 +2 -16
- data/bin/rudy-s3 +0 -10
- data/bin/rudy-sdb +11 -12
- data/lib/rudy.rb +59 -91
- data/lib/rudy/aws.rb +4 -45
- data/lib/rudy/aws/ec2.rb +57 -20
- data/lib/rudy/aws/ec2/address.rb +10 -11
- data/lib/rudy/aws/ec2/group.rb +10 -9
- data/lib/rudy/aws/ec2/image.rb +8 -8
- data/lib/rudy/aws/ec2/instance.rb +18 -19
- data/lib/rudy/aws/ec2/keypair.rb +14 -19
- data/lib/rudy/aws/ec2/snapshot.rb +16 -9
- data/lib/rudy/aws/ec2/volume.rb +39 -26
- data/lib/rudy/aws/ec2/zone.rb +5 -4
- data/lib/rudy/aws/s3.rb +2 -1
- data/lib/rudy/aws/sdb.rb +35 -86
- data/lib/rudy/backups.rb +24 -0
- data/lib/rudy/cli.rb +5 -131
- data/lib/rudy/cli/aws/ec2/addresses.rb +19 -27
- data/lib/rudy/cli/aws/ec2/candy.rb +45 -20
- data/lib/rudy/cli/aws/ec2/groups.rb +9 -13
- data/lib/rudy/cli/aws/ec2/images.rb +5 -133
- data/lib/rudy/cli/aws/ec2/instances.rb +25 -25
- data/lib/rudy/cli/aws/ec2/keypairs.rb +7 -11
- data/lib/rudy/cli/aws/ec2/snapshots.rb +5 -9
- data/lib/rudy/cli/aws/ec2/volumes.rb +22 -23
- data/lib/rudy/cli/aws/ec2/zones.rb +2 -3
- data/lib/rudy/cli/aws/sdb/domains.rb +5 -6
- data/lib/rudy/cli/aws/sdb/objects.rb +33 -0
- data/lib/rudy/cli/aws/sdb/select.rb +23 -0
- data/lib/rudy/cli/backups.rb +38 -0
- data/lib/rudy/cli/base.rb +104 -0
- data/lib/rudy/cli/candy.rb +1 -2
- data/lib/rudy/cli/config.rb +20 -7
- data/lib/rudy/cli/disks.rb +7 -9
- data/lib/rudy/cli/execbase.rb +56 -0
- data/lib/rudy/cli/machines.rb +242 -45
- data/lib/rudy/cli/metadata.rb +24 -10
- data/lib/rudy/cli/networks.rb +34 -0
- data/lib/rudy/cli/routines.rb +32 -6
- data/lib/rudy/cli/status.rb +60 -0
- data/lib/rudy/config.rb +55 -32
- data/lib/rudy/config/objects.rb +44 -30
- data/lib/rudy/disks.rb +25 -0
- data/lib/rudy/exceptions.rb +99 -0
- data/lib/rudy/global.rb +67 -28
- data/lib/rudy/guidelines.rb +3 -2
- data/lib/rudy/huxtable.rb +67 -58
- data/lib/rudy/machines.rb +41 -263
- data/lib/rudy/metadata.rb +212 -38
- data/lib/rudy/metadata/backup.rb +123 -78
- data/lib/rudy/metadata/disk.rb +153 -170
- data/lib/rudy/metadata/machine.rb +179 -0
- data/lib/rudy/mixins.rb +2 -1
- data/lib/rudy/mixins/hash.rb +3 -1
- data/lib/rudy/mixins/symbol.rb +8 -0
- data/lib/rudy/routines.rb +127 -344
- data/lib/rudy/routines/base.rb +229 -0
- data/lib/rudy/routines/handlers/base.rb +48 -0
- data/lib/rudy/routines/handlers/depends.rb +49 -0
- data/lib/rudy/routines/handlers/disks.rb +249 -0
- data/lib/rudy/routines/handlers/group.rb +44 -0
- data/lib/rudy/routines/handlers/host.rb +70 -0
- data/lib/rudy/routines/handlers/keypair.rb +70 -0
- data/lib/rudy/routines/handlers/machines.rb +15 -0
- data/lib/rudy/routines/handlers/script.rb +85 -0
- data/lib/rudy/routines/handlers/user.rb +45 -0
- data/lib/rudy/routines/passthrough.rb +19 -23
- data/lib/rudy/routines/reboot.rb +98 -50
- data/lib/rudy/routines/shutdown.rb +65 -14
- data/lib/rudy/routines/startup.rb +112 -17
- data/lib/rudy/utils.rb +35 -68
- data/rudy.gemspec +82 -25
- data/tryouts/01_mixins/01_hash_tryouts.rb +20 -0
- data/tryouts/10_require_time/10_rudy_tryouts.rb +33 -0
- data/tryouts/10_require_time/15_global_tryouts.rb +58 -0
- data/tryouts/12_config/10_load_config_tryouts.rb +43 -0
- data/tryouts/12_config/20_defaults_tryouts.rb +16 -0
- data/tryouts/12_config/30_accounts_tryouts.rb +17 -0
- data/tryouts/12_config/40_machines_tryouts.rb +53 -0
- data/tryouts/12_config/50_commands_tryouts.rb +17 -0
- data/tryouts/12_config/60_routines_tryouts.rb +16 -0
- data/tryouts/15_huxtable/10_huxtable_tryouts.rb +47 -0
- data/tryouts/15_huxtable/20_user_tryouts.rb +47 -0
- data/tryouts/20_simpledb/10_domains_tryouts.rb +36 -0
- data/tryouts/20_simpledb/20_objects_tryouts.rb +56 -0
- data/tryouts/25_ec2/10_keypairs_tryouts.rb +54 -0
- data/tryouts/25_ec2/20_groups_tryouts.rb +56 -0
- data/tryouts/25_ec2/21_groups_authorize_address_tryouts.rb +53 -0
- data/tryouts/25_ec2/22_groups_authorize_account_tryouts.rb +54 -0
- data/tryouts/25_ec2/30_addresses_tryouts.rb +42 -0
- data/tryouts/25_ec2/40_volumes_tryouts.rb +53 -0
- data/tryouts/25_ec2/50_snapshots_tryouts.rb +75 -0
- data/tryouts/26_ec2_instances/10_instance_tryouts.rb +107 -0
- data/tryouts/26_ec2_instances/50_images_tryouts.rb +7 -0
- data/tryouts/30_metadata/10_include_tryouts.rb +45 -0
- data/tryouts/30_metadata/13_object_tryouts.rb +19 -0
- data/tryouts/30_metadata/50_disk_tryouts.rb +115 -0
- data/tryouts/30_metadata/51_disk_digest_tryouts.rb +24 -0
- data/tryouts/30_metadata/53_disk_list_tryouts.rb +35 -0
- data/tryouts/30_metadata/56_disk_volume_tryouts.rb +68 -0
- data/tryouts/30_metadata/60_backup_tryouts.rb +101 -0
- data/tryouts/30_metadata/63_backup_list_tryouts.rb +38 -0
- data/tryouts/30_metadata/64_backup_disk_tryouts.rb +65 -0
- data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +76 -0
- data/tryouts/30_metadata/70_machine_tryouts.rb +85 -0
- data/tryouts/30_metadata/73_machine_list_tryouts.rb +58 -0
- data/tryouts/30_metadata/76_machine_instance_tryouts.rb +64 -0
- data/tryouts/30_metadata/77_machines_tryouts.rb +45 -0
- data/tryouts/40_routines/10_keypair_handler_tryouts.rb +52 -0
- data/tryouts/40_routines/11_group_handler_tryouts.rb +36 -0
- data/tryouts/80_cli/10_rudyec2_tryouts.rb +8 -0
- data/tryouts/80_cli/60_rudy_tryouts.rb +41 -0
- data/tryouts/exploration/console.rb +91 -0
- data/tryouts/exploration/machine.rb +23 -0
- data/tryouts/failer +6 -0
- metadata +116 -32
- data/bin/ird +0 -153
- data/lib/rudy/metadata/backups.rb +0 -67
- data/lib/rudy/metadata/debug.rb +0 -38
- data/lib/rudy/metadata/disks.rb +0 -67
- data/lib/rudy/metadata/objectbase.rb +0 -108
- data/lib/rudy/routines/helper.rb +0 -76
- data/lib/rudy/routines/helpers/dependshelper.rb +0 -34
- data/lib/rudy/routines/helpers/diskhelper.rb +0 -403
- data/lib/rudy/routines/helpers/scripthelper.rb +0 -197
- data/lib/rudy/routines/helpers/userhelper.rb +0 -37
- data/support/rudy-ec2-startup +0 -200
@@ -1,37 +0,0 @@
|
|
1
|
-
|
2
|
-
module Rudy; module Routines;
|
3
|
-
module UserHelper
|
4
|
-
include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
|
5
|
-
extend self
|
6
|
-
|
7
|
-
def adduser?(routine)
|
8
|
-
(!routine.adduser.nil? && !routine.adduser.to_s.empty?)
|
9
|
-
end
|
10
|
-
def adduser(routine, machine, rbox)
|
11
|
-
|
12
|
-
# On Solaris, the user's home directory needs to be specified
|
13
|
-
# explicitly so we do it for linux too for fun.
|
14
|
-
homedir = rbox.guess_user_home(routine.adduser.to_s)
|
15
|
-
args = [:m, :d, homedir, :s, '/bin/bash', routine.adduser.to_s]
|
16
|
-
puts command_separator(rbox.preview_command(:useradd, args), rbox.user, rbox.host)
|
17
|
-
|
18
|
-
# NOTE: We'll may to use platform specific code here.
|
19
|
-
# Linux has adduser and useradd commands:
|
20
|
-
# adduser can prompt for info which we don't want.
|
21
|
-
# useradd does not prompt (on Debian/Ubuntu at least).
|
22
|
-
# We need to specify bash b/c the default is /bin/sh
|
23
|
-
trap_rbox_errors { rbox.useradd(args) }
|
24
|
-
end
|
25
|
-
|
26
|
-
def authorize?(routine)
|
27
|
-
(!routine.authorize.nil? && !routine.authorize.to_s.empty?)
|
28
|
-
end
|
29
|
-
def authorize(routine, machine, rbox)
|
30
|
-
puts command_separator(:authorize_keys_remote, rbox.user, rbox.host)
|
31
|
-
trap_rbox_errors { rbox.authorize_keys_remote(routine.authorize) }
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end; end
|
data/support/rudy-ec2-startup
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
# what: Rudy EC2 startup script
|
4
|
-
# who: delano@solutious.com
|
5
|
-
# when: 2009-02-25 (rev: 4)
|
6
|
-
|
7
|
-
# NOTE: This is a prototype version of this script. A cleaner version
|
8
|
-
# with better documentation is forthcoming.
|
9
|
-
|
10
|
-
# Runs when an ec2 instance startups up.
|
11
|
-
# Grabs configuration from the run time user data and stores it locally.
|
12
|
-
# See Rudy::CLI::Machines#start_instance for the expected yaml format.
|
13
|
-
|
14
|
-
# Put this in /etc/init.d. Then:
|
15
|
-
# * chmod 755 rudy-ec2-startup
|
16
|
-
# * cd /etc/rc3.d
|
17
|
-
# * ln -s ../init.d/rudy-ec2-startup S17rudy
|
18
|
-
# * cd /etc/rc4.d
|
19
|
-
# * ln -s ../init.d/rudy-ec2-startup S17rudy
|
20
|
-
# * cd /etc/rc5.d
|
21
|
-
# * ln -s ../init.d/rudy-ec2-startup S17rudy
|
22
|
-
|
23
|
-
require 'yaml'
|
24
|
-
require 'resolv'
|
25
|
-
|
26
|
-
LOGFILE = '/var/log/rudy-ec2-startup'
|
27
|
-
USERDATA = 'http://169.254.169.254/2008-02-01/user-data'
|
28
|
-
METADATA = 'http://169.254.169.254/2008-02-01/meta-data'
|
29
|
-
|
30
|
-
#LOGFILE = '/tmp/rudy-ec2-startup'
|
31
|
-
#USERDATA = 'http://127.0.0.1/2008-02-01/user-data'
|
32
|
-
#METADATA = 'http://127.0.0.1/2008-02-01/meta-data'
|
33
|
-
|
34
|
-
METADATAPARAMS = ['instance-id', 'instance-type']
|
35
|
-
|
36
|
-
Rudy::CONFIG_DIR=File.join('.rudy')
|
37
|
-
Rudy::CONFIG_FILE=File.join('config')
|
38
|
-
|
39
|
-
module Rudy
|
40
|
-
module EC2Startup
|
41
|
-
extend self
|
42
|
-
|
43
|
-
VERSION = 4.freeze
|
44
|
-
|
45
|
-
def process_config
|
46
|
-
begin
|
47
|
-
File.unlink(LOGFILE) if File.exists?(LOGFILE)
|
48
|
-
log "RUDY (rev#{VERSION}) is in the house"
|
49
|
-
|
50
|
-
log "Grabing configuration..."
|
51
|
-
config_yaml = run("curl -s #{USERDATA}")
|
52
|
-
|
53
|
-
log "Grabing meta-data..."
|
54
|
-
metadata = get_metadata
|
55
|
-
|
56
|
-
log "Processing metadata..."
|
57
|
-
METADATAPARAMS.each do |name|
|
58
|
-
default = name.gsub('instance-', '')
|
59
|
-
value = (metadata[name] && !metadata[name].empty?) ? metadata[name] : default
|
60
|
-
log " ---> #{name}: #{value}"
|
61
|
-
write_to_file("/etc/ec2/#{name}", value, "w")
|
62
|
-
end
|
63
|
-
|
64
|
-
log "Processing userdata..."
|
65
|
-
|
66
|
-
if !config_yaml || config_yaml.empty?
|
67
|
-
raise "Nothing to process (did you supply user-data when you created the instance)"
|
68
|
-
end
|
69
|
-
|
70
|
-
config = YAML::load(config_yaml)
|
71
|
-
config ||= {}
|
72
|
-
|
73
|
-
# Print to STDOUT and NOT to the log.
|
74
|
-
# We don't want sensitive config values available in the log
|
75
|
-
puts "CONFIG: " << config_yaml
|
76
|
-
|
77
|
-
zone = config[:zone] ? config[:zone].to_s.downcase : "zone"
|
78
|
-
environment = config[:environment] ? config[:environment].to_s.downcase : "env"
|
79
|
-
role = config[:role] ? config[:role].to_s.downcase : "role"
|
80
|
-
position = config[:position] ? config[:position].to_s.downcase : "00"
|
81
|
-
|
82
|
-
hostname = [zone, environment, role, position].join('-')
|
83
|
-
log "Setting hostname: #{hostname}"
|
84
|
-
`hostname #{hostname}`
|
85
|
-
|
86
|
-
config[:hosts] ||= {}
|
87
|
-
config[:hosts][hostname] = '127.0.0.1'
|
88
|
-
|
89
|
-
if config[:userdata] && config[:userdata].is_a?(Hash)
|
90
|
-
# TODO: How to we get the path to any user's home directory?
|
91
|
-
# (when we're not running as that user.)
|
92
|
-
config[:userdata].each_pair do |n,hash|
|
93
|
-
fileparts = (n == :root) ? ['/root'] : [user_home_dir(n)]
|
94
|
-
fileparts << Rudy::CONFIG_DIR
|
95
|
-
dirpath = File.join(fileparts)
|
96
|
-
filepath = File.join(dirpath, Rudy::CONFIG_FILE)
|
97
|
-
|
98
|
-
# Backwards compatability
|
99
|
-
if !File.directory?(dirpath)
|
100
|
-
log "Deleting the deprecated #{dirpath} config"
|
101
|
-
File.unlink(dirpath)
|
102
|
-
end
|
103
|
-
|
104
|
-
unless File.exists?(dirpath)
|
105
|
-
log "Creating #{dirpath}"
|
106
|
-
Dir.mkdir(dirpath, 0700)
|
107
|
-
end
|
108
|
-
|
109
|
-
log "Writing to #{filepath}"
|
110
|
-
user_data = {
|
111
|
-
:userdata => hash
|
112
|
-
}
|
113
|
-
write_to_file(filepath, user_data.to_yaml, "w")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
if config[:hosts] && config[:hosts].is_a?(Hash)
|
118
|
-
unless read_file('/etc/hosts') =~ /----- RUDY SAYS -----/
|
119
|
-
log "Updating /etc/hosts..."
|
120
|
-
write_to_file("/etc/hosts", "\n# ----- RUDY SAYS -----\n", :append)
|
121
|
-
config[:hosts].each_pair do |name, address|
|
122
|
-
# Respect existing entries
|
123
|
-
next if read_file('/etc/hosts') =~ /#{name}/
|
124
|
-
|
125
|
-
ip_address = (address !~ /^\d.+/) ? Resolv.getaddress(address) : address
|
126
|
-
|
127
|
-
log " ---> #{name}: #{ip_address}"
|
128
|
-
write_to_file("/etc/hosts", "\n#{ip_address}\t#{name}\n", :append)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
log "Done!"
|
134
|
-
|
135
|
-
rescue => ex
|
136
|
-
log "ERROR: #{ex.message}"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
def get_metadata
|
142
|
-
metadata = {}
|
143
|
-
|
144
|
-
begin
|
145
|
-
METADATAPARAMS.each do |param|
|
146
|
-
log " ---> #{param}"
|
147
|
-
metadata[param.to_s] = run("curl -s #{METADATA}/#{param}")
|
148
|
-
metadata[param.to_s] = nil if metadata[param.to_s].empty?
|
149
|
-
end
|
150
|
-
rescue => ex
|
151
|
-
log("Problem getting metadata: #{ex.message}")
|
152
|
-
end
|
153
|
-
metadata
|
154
|
-
end
|
155
|
-
|
156
|
-
def run(command, input='')
|
157
|
-
IO.popen(command, 'r+') do |io|
|
158
|
-
io.read
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def get_formatted_time
|
163
|
-
t = Time.now
|
164
|
-
t_out = t.strftime("%H:%M:%S%p (%m/%d/%Y)")
|
165
|
-
end
|
166
|
-
|
167
|
-
def write_to_file(filename, s, type)
|
168
|
-
type = (type == :append) ? 'a' : 'w'
|
169
|
-
f = File.open(filename,type)
|
170
|
-
f.puts s
|
171
|
-
f.close
|
172
|
-
end
|
173
|
-
|
174
|
-
def read_file(path)
|
175
|
-
read_file_to_array(path).join('')
|
176
|
-
end
|
177
|
-
|
178
|
-
def read_file_to_array(path)
|
179
|
-
contents = []
|
180
|
-
return contents unless File.exists?(path)
|
181
|
-
open(path, 'r') do |l|
|
182
|
-
contents = l.readlines
|
183
|
-
end
|
184
|
-
contents
|
185
|
-
end
|
186
|
-
|
187
|
-
def user_home_dir(user)
|
188
|
-
(`su #{user} -c "echo \\$HOME"` || '').chomp
|
189
|
-
end
|
190
|
-
|
191
|
-
def log(s)
|
192
|
-
msg = "#{get_formatted_time}: #{s}"
|
193
|
-
write_to_file(LOGFILE, msg, :append)
|
194
|
-
puts msg
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
Rudy::EC2Startup.process_config
|