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
data/lib/rudy/disks.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Rudy
|
4
|
+
|
5
|
+
module Disks
|
6
|
+
RTYPE = 'disk'.freeze
|
7
|
+
|
8
|
+
extend self
|
9
|
+
extend Rudy::Metadata::ClassMethods
|
10
|
+
include Rudy::Huxtable
|
11
|
+
extend Rudy::Huxtable
|
12
|
+
|
13
|
+
def get(path)
|
14
|
+
tmp = Rudy::Disk.new path
|
15
|
+
record = Rudy::Metadata.get tmp.name
|
16
|
+
return nil unless record.is_a?(Hash)
|
17
|
+
tmp.from_hash record
|
18
|
+
end
|
19
|
+
|
20
|
+
def from_hash(h)
|
21
|
+
Rudy::Disk.from_hash h
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Rudy
|
2
|
+
|
3
|
+
class Error < RuntimeError
|
4
|
+
def initialize(obj=nil); @obj = obj; end
|
5
|
+
def message; "#{self.class}: #{@obj}"; end
|
6
|
+
end
|
7
|
+
class InsecureKeyPermissions < Rudy::Error
|
8
|
+
def message
|
9
|
+
lines = ["Insecure file permissions for #{@obj}"]
|
10
|
+
lines << "Try: chmod 600 #{@obj}"
|
11
|
+
lines.join($/)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
#--
|
16
|
+
# TODO: Update exception Syntax based on:
|
17
|
+
# http://blog.rubybestpractices.com/posts/gregory/anonymous_class_hacks.html
|
18
|
+
#++
|
19
|
+
|
20
|
+
class NoConfig < Rudy::Error
|
21
|
+
def message; "No configuration found!"; end
|
22
|
+
end
|
23
|
+
class NoGlobal < Rudy::Error
|
24
|
+
def message; "No globals defined!"; end
|
25
|
+
end
|
26
|
+
class NoMachinesConfig < Rudy::Error
|
27
|
+
def message; "No machines configuration. Check your configs!"; end
|
28
|
+
end
|
29
|
+
class NoRoutinesConfig < Rudy::Error
|
30
|
+
def message; "No routines configuration. Check your configs!"; end
|
31
|
+
end
|
32
|
+
class ServiceUnavailable < Rudy::Error
|
33
|
+
def message; "#{@obj} is not available. Check your internets!"; end
|
34
|
+
end
|
35
|
+
class MachineGroupAlreadyRunning < Rudy::Error
|
36
|
+
def message; "Machine group #{@obj} is already running."; end
|
37
|
+
end
|
38
|
+
class MachineGroupNotRunning < Rudy::Error
|
39
|
+
def message; "Machine group #{@obj} is not running."; end
|
40
|
+
end
|
41
|
+
class MachineGroupMetadataExists < Rudy::Error
|
42
|
+
def message; "Machine group #{@obj} has existing metadata."; end
|
43
|
+
end
|
44
|
+
class MachineAlreadyRunning < Rudy::Error
|
45
|
+
def message; "Machine #{@obj} is already running."; end
|
46
|
+
end
|
47
|
+
class MachineNotRunning < Rudy::Error
|
48
|
+
def message; "Machine #{@obj} is not running."; end
|
49
|
+
end
|
50
|
+
class NoMachines < Rudy::Error;
|
51
|
+
def message
|
52
|
+
msg = "No machines running "
|
53
|
+
msg << "in #{@obj}" if @obj
|
54
|
+
msg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
class MachineGroupNotDefined < Rudy::Error
|
58
|
+
def message; "#{@obj} is not defined in machines config."; end
|
59
|
+
end
|
60
|
+
class PrivateKeyFileExists < Rudy::Error
|
61
|
+
def message; "Private key #{@obj} already exists."; end
|
62
|
+
end
|
63
|
+
class PrivateKeyNotFound < Rudy::Error
|
64
|
+
def message; "Private key file #{@obj} not found."; end
|
65
|
+
end
|
66
|
+
class UnsupportedOS < Rudy::Error; end
|
67
|
+
|
68
|
+
|
69
|
+
class NotImplemented < Rudy::Error; end
|
70
|
+
|
71
|
+
|
72
|
+
module Metadata
|
73
|
+
class UnknownRecordType < Rudy::Error
|
74
|
+
def message; "Unknown record type: #{@obj}"; end
|
75
|
+
end
|
76
|
+
class UnknownObject < Rudy::Error
|
77
|
+
def message; "Unknown object: #{@obj}"; end
|
78
|
+
end
|
79
|
+
# Raised when trying to save a record with a key that already exists
|
80
|
+
class DuplicateRecord < Rudy::Error; end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
module Disks
|
85
|
+
class NotAttached < Rudy::Error; end
|
86
|
+
class NotFormatted < Rudy::Error; end
|
87
|
+
class AlreadyFormatted < Rudy::Error; end
|
88
|
+
class AlreadyMounted < Rudy::Error; end
|
89
|
+
class AlreadyAttached < Rudy::Error; end
|
90
|
+
class NotMounted < Rudy::Error; end
|
91
|
+
class InUse < Rudy::Error; end
|
92
|
+
end
|
93
|
+
|
94
|
+
module Backups
|
95
|
+
class NoDisk < Rudy::Error; end
|
96
|
+
class NoBackup < Rudy::Error; end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/lib/rudy/global.rb
CHANGED
@@ -22,19 +22,23 @@ module Rudy
|
|
22
22
|
field :verbose
|
23
23
|
field :format
|
24
24
|
field :print_header
|
25
|
-
field :
|
25
|
+
field :auto
|
26
|
+
field :force
|
26
27
|
|
27
28
|
field :accesskey
|
28
29
|
field :secretkey
|
29
30
|
field :accountnum
|
30
31
|
field :accountname # TODO: use this. And accounttype (aws)
|
31
32
|
field :cert
|
32
|
-
field :
|
33
|
+
field :pkey
|
33
34
|
|
34
|
-
field :
|
35
|
-
field :
|
35
|
+
field :localhost
|
36
|
+
field :parallel
|
37
|
+
field :identity
|
36
38
|
|
39
|
+
field :testrun
|
37
40
|
field :offline
|
41
|
+
field :bucket
|
38
42
|
|
39
43
|
field :config => String
|
40
44
|
|
@@ -46,45 +50,61 @@ module Rudy
|
|
46
50
|
@verbose ||= 0
|
47
51
|
@nocolor = true unless @nocolor == "false" || @nocolor == false
|
48
52
|
@quiet ||= false
|
53
|
+
@parallel ||= false
|
54
|
+
@force ||= false
|
49
55
|
@format ||= :string # as in, to_s
|
50
56
|
@print_header = true if @print_header == nil
|
51
|
-
@yes = false if @yes.nil?
|
52
57
|
end
|
53
58
|
|
54
59
|
def apply_config(config)
|
60
|
+
|
55
61
|
return unless config.is_a?(Rudy::Config)
|
62
|
+
clear_system_defaults # temporarily unapply default values
|
63
|
+
|
56
64
|
if config.defaults?
|
57
65
|
# Apply the "color" default before "nocolor" so nocolor has presedence
|
58
66
|
@nocolor = !config.defaults.color unless config.defaults.color.nil?
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
# WARNING: Don't add user to this list. The global value should return
|
68
|
+
# the value specified on the command line or nil. If it is nil, we can
|
69
|
+
# check the value from the machines config. If that is nil, we use the
|
70
|
+
# value from the defaults config.
|
71
|
+
# WARNING: Don't add bucket either or any machines configuration param
|
72
|
+
# TODO: investigate removing this apply_config method
|
73
|
+
%w[region zone environment role position
|
74
|
+
localhost nocolor quiet auto force parallel].each do |name|
|
75
|
+
curval, defval = self.send(name), config.defaults.send(name)
|
76
|
+
if curval.nil? && !defval.nil?
|
77
|
+
# Don't use the accessors. These are defaults so no Region magic.
|
78
|
+
self.instance_variable_set("@#{name}", defval)
|
79
|
+
end
|
62
80
|
end
|
63
81
|
end
|
64
82
|
|
65
83
|
if config.accounts? && config.accounts.aws
|
66
|
-
%w[accesskey secretkey accountnum cert
|
84
|
+
%w[accesskey secretkey accountnum cert pkey].each do |name|
|
67
85
|
val = config.accounts.aws.send(name)
|
68
86
|
self.send("#{name}=", val) unless val.nil?
|
69
87
|
end
|
70
88
|
end
|
71
|
-
|
72
89
|
postprocess
|
73
90
|
end
|
74
91
|
|
75
|
-
|
76
92
|
def update(ghash={})
|
77
|
-
ghash = ghash.marshal_dump if ghash.is_a?(OpenStruct)
|
78
|
-
|
79
|
-
if ghash.is_a?(Hash)
|
80
|
-
ghash.each_pair { |n,v| self.send("#{n}=", v) }
|
81
|
-
else
|
82
|
-
raise "Unexpected #{ghash.class.to_s}"
|
83
|
-
end
|
84
|
-
|
93
|
+
ghash = ghash.marshal_dump if ghash.is_a?(OpenStruct)
|
94
|
+
ghash.each_pair { |n,v| self.send("#{n}=", v) }
|
85
95
|
postprocess
|
86
96
|
end
|
87
97
|
|
98
|
+
def zone=(z)
|
99
|
+
@zone = z
|
100
|
+
@region = @zone.to_s.gsub(/[a-z]$/, '').to_sym
|
101
|
+
end
|
102
|
+
|
103
|
+
def region=(r)
|
104
|
+
@region = r
|
105
|
+
@zone = "#{@region}b".to_sym
|
106
|
+
end
|
107
|
+
|
88
108
|
def to_s(*args)
|
89
109
|
super()
|
90
110
|
end
|
@@ -97,11 +117,12 @@ module Rudy
|
|
97
117
|
apply_system_defaults
|
98
118
|
@nocolor = !@color unless @color.nil?
|
99
119
|
@cert &&= File.expand_path(@cert)
|
100
|
-
@
|
120
|
+
@pkey &&= File.expand_path(@pkey)
|
101
121
|
@position &&= @position.to_s.rjust(2, '0')
|
102
122
|
@format &&= @format.to_sym rescue nil
|
103
123
|
@quiet ? Rudy.enable_quiet : Rudy.disable_quiet
|
104
|
-
@
|
124
|
+
@auto ? Rudy.enable_auto : Rudy.disable_auto
|
125
|
+
|
105
126
|
end
|
106
127
|
|
107
128
|
def apply_environment_variables
|
@@ -109,18 +130,36 @@ module Rudy
|
|
109
130
|
@secretkey ||= ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY']
|
110
131
|
@accountnum ||= ENV['AWS_ACCOUNT_NUMBER']
|
111
132
|
@cert ||= ENV['EC2_CERT']
|
112
|
-
@
|
113
|
-
@local_user = ENV['USER'] || :rudy
|
114
|
-
@local_hostname = Socket.gethostname || :localhost
|
133
|
+
@pkey ||= ENV['EC2_PRIVATE_KEY']
|
115
134
|
end
|
116
135
|
|
136
|
+
# Apply defaults for parameters that must have values
|
117
137
|
def apply_system_defaults
|
118
|
-
@region
|
119
|
-
|
138
|
+
if @region.nil? && @zone.nil?
|
139
|
+
@region, @zone = Rudy::DEFAULT_REGION, Rudy::DEFAULT_ZONE
|
140
|
+
elsif @region.nil?
|
141
|
+
@region = @zone.to_s.gsub(/[a-z]$/, '').to_sym
|
142
|
+
elsif @zone.nil?
|
143
|
+
@zone = "#{@region}b".to_sym
|
144
|
+
end
|
145
|
+
|
120
146
|
@environment ||= Rudy::DEFAULT_ENVIRONMENT
|
121
147
|
@role ||= Rudy::DEFAULT_ROLE
|
122
|
-
@
|
123
|
-
@
|
148
|
+
@localhost ||= Rudy.sysinfo.hostname || 'localhost'
|
149
|
+
@auto = false if @auto.nil?
|
150
|
+
end
|
151
|
+
|
152
|
+
# Unapply defaults for parameters that must have values.
|
153
|
+
# This is important when reloading configuration since
|
154
|
+
# we don't overwrite existing values. If the default
|
155
|
+
# ones remained the configuration would not be applied.
|
156
|
+
def clear_system_defaults
|
157
|
+
@region = nil if @region == Rudy::DEFAULT_REGION
|
158
|
+
@zone = nil if @zone == Rudy::DEFAULT_ZONE
|
159
|
+
@environment = nil if @environment == Rudy::DEFAULT_ENVIRONMENT
|
160
|
+
@role = nil if @role == Rudy::DEFAULT_ROLE
|
161
|
+
@localhost = nil if @localhost == (Rudy.sysinfo.hostname || 'localhost')
|
162
|
+
@auto = nil if @auto == false
|
124
163
|
end
|
125
164
|
|
126
165
|
end
|
data/lib/rudy/guidelines.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
module Rudy
|
4
|
-
module Guidelines
|
4
|
+
module Guidelines
|
5
5
|
extend self
|
6
|
-
AFE = "Always fail early"
|
6
|
+
AFE = "Always fail early"
|
7
7
|
ABA = "Always be accurate"
|
8
8
|
CBC = "Consistency before cuteness"
|
9
9
|
UNO = "Ugly's not okay"
|
10
|
+
WOC = "Write offensive code"
|
10
11
|
def inspect
|
11
12
|
all = Guidelines.constants
|
12
13
|
g = all.collect { |c| '%s="%s"' % [c, const_get(c)] }
|
data/lib/rudy/huxtable.rb
CHANGED
@@ -20,6 +20,7 @@ module Rudy
|
|
20
20
|
# end
|
21
21
|
#
|
22
22
|
module Huxtable
|
23
|
+
extend self
|
23
24
|
|
24
25
|
@@config = Rudy::Config.new
|
25
26
|
@@global = Rudy::Global.new
|
@@ -30,15 +31,13 @@ module Rudy
|
|
30
31
|
def self.logger; @@logger; end
|
31
32
|
|
32
33
|
def self.update_config(path=nil)
|
33
|
-
@@config.verbose = (@@global.verbose
|
34
|
+
@@config.verbose = (@@global.verbose >= 3) # -vvv
|
34
35
|
# nil and bad paths sent to look_and_load are ignored
|
35
36
|
@@config.look_and_load(path || @@global.config)
|
36
37
|
@@global.apply_config(@@config)
|
37
|
-
# And then update global again b/c some values come from @@config
|
38
|
-
update_global ## TODO: Check if this can be removed
|
39
38
|
end
|
40
39
|
|
41
|
-
def self.update_global(ghash
|
40
|
+
def self.update_global(ghash); @@global.update(ghash); end
|
42
41
|
def self.update_logger(logger); @@logger = logger; end
|
43
42
|
|
44
43
|
def self.reset_config; @@config = Rudy::Config.new; end
|
@@ -58,6 +57,17 @@ module Rudy
|
|
58
57
|
Rudy::DOMAIN
|
59
58
|
end
|
60
59
|
|
60
|
+
# Puts +msg+ to +@@logger+
|
61
|
+
def self.li(*msg); msg.each { |m| @@logger.puts m } if !@@global.quiet; end
|
62
|
+
# Puts +msg+ to +@@logger+ if +Rudy.debug?+ returns true
|
63
|
+
def self.ld(*msg); msg.each { |m| @@logger.puts "D: #{m}" } if Rudy.debug?; end
|
64
|
+
# Puts +msg+ to +@@logger+ with "ERROR: " prepended
|
65
|
+
def self.le(*msg); msg.each { |m| @@logger.puts " #{m}" }; end
|
66
|
+
|
67
|
+
def li(*msg); Rudy::Huxtable.li *msg; end
|
68
|
+
def ld(*msg); Rudy::Huxtable.ld *msg; end
|
69
|
+
def le(*msg); Rudy::Huxtable.le *msg; end
|
70
|
+
|
61
71
|
def config_dirname
|
62
72
|
raise "No config paths defined" unless @@config.is_a?(Rudy::Config) && @@config.paths.is_a?(Array)
|
63
73
|
base_dir = File.dirname @@config.paths.first
|
@@ -65,21 +75,18 @@ module Rudy
|
|
65
75
|
base_dir
|
66
76
|
end
|
67
77
|
|
68
|
-
def has_keypair?(name=nil)
|
69
|
-
kp = user_keypairpath(name)
|
70
|
-
(!kp.nil? && File.exists?(kp))
|
71
|
-
end
|
72
78
|
|
73
79
|
# Returns the name of the current keypair for the given user.
|
74
80
|
# If there's a private key path in the config this will return
|
75
|
-
# the basename (it's assumed the Amazon
|
81
|
+
# the basename (it's assumed the Amazon Keypair has the same
|
76
82
|
# name as the file). Otherwise this returns the Rudy style
|
77
83
|
# name: <tt>key-ZONE-ENV-ROLE-USER</tt>. Or if this the user is
|
78
84
|
# root: <tt>key-ZONE-ENV-ROLE</tt>
|
79
|
-
def user_keypairname(user)
|
80
|
-
|
81
|
-
|
82
|
-
|
85
|
+
def user_keypairname(user=nil)
|
86
|
+
user ||= current_machine_user
|
87
|
+
path = defined_keypairpath user
|
88
|
+
if path
|
89
|
+
Huxtable.keypair_path_to_name(path)
|
83
90
|
else
|
84
91
|
n = (user.to_s == 'root') ? '' : "-#{user}"
|
85
92
|
"key-%s-%s%s" % [@@global.zone, current_machine_group, n]
|
@@ -88,50 +95,56 @@ module Rudy
|
|
88
95
|
def root_keypairname
|
89
96
|
user_keypairname :root
|
90
97
|
end
|
98
|
+
def current_user_keypairname
|
99
|
+
user_keypairname current_machine_user
|
100
|
+
end
|
91
101
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
# EC2 Keypairs that were created are intended for starting the machine instances.
|
105
|
-
# These are used as the root SSH keys. If we can find a user defined key, we'll
|
106
|
-
# check the config path for a generated one.
|
107
|
-
if !path && name.to_s == 'root'
|
108
|
-
path = File.join(self.config_dirname, "key-#{@@global.zone}-#{current_machine_group}")
|
102
|
+
def user_keypairpath(name=nil)
|
103
|
+
name ||= current_machine_user
|
104
|
+
path = defined_keypairpath name
|
105
|
+
# If we can't find a user defined key, we'll
|
106
|
+
# check the config path for a generated one.
|
107
|
+
if path
|
108
|
+
raise "Private key file not found (#{path})" unless File.exists?(path)
|
109
|
+
path = File.expand_path(path)
|
110
|
+
else
|
111
|
+
ssh_key_dir = @@config.defaults.keydir || Rudy::SSH_KEY_DIR
|
112
|
+
path = File.join(ssh_key_dir, user_keypairname(name))
|
109
113
|
end
|
110
|
-
path = File.expand_path(path) if path && File.exists?(path)
|
111
114
|
path
|
112
115
|
end
|
113
116
|
def root_keypairpath
|
114
117
|
user_keypairpath :root
|
115
118
|
end
|
116
|
-
|
117
|
-
|
118
|
-
path = user_keypairpath(:root)
|
119
|
-
(!path.nil? && !path.empty?)
|
119
|
+
def current_user_keypairpath
|
120
|
+
user_keypairpath current_machine_user
|
120
121
|
end
|
121
122
|
|
122
|
-
def
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
def defined_keypairpath(name=nil)
|
124
|
+
name ||= current_machine_user
|
125
|
+
raise Rudy::Error, "No user provided" unless name
|
126
|
+
## NOTE: I think it is more appropriate to return nil here
|
127
|
+
## than raise errors. This stuff should be checked already
|
128
|
+
##raise NoConfig unless @@config
|
129
|
+
##raise NoMachinesConfig unless @@config.machines
|
130
|
+
##raise NoGlobal unless @@global
|
131
|
+
return unless @@global && @@config && @@config.machines
|
132
|
+
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
133
|
+
path = @@global.identity
|
134
|
+
path ||= @@config.machines.find_deferred(zon, env, rol, [:users, name, :keypair])
|
135
|
+
path ||= @@config.machines.find_deferred(env, rol, [:users, name, :keypair])
|
136
|
+
path ||= @@config.machines.find_deferred(rol, [:users, name, :keypair])
|
137
|
+
path ||= @@config.machines.find_deferred(@@global.region, [:users, name, :keypair])
|
138
|
+
path
|
127
139
|
end
|
128
140
|
|
141
|
+
|
129
142
|
def current_machine_group
|
130
143
|
[@@global.environment, @@global.role].join(Rudy::DELIM)
|
131
144
|
end
|
132
145
|
|
133
146
|
def current_group_name
|
134
|
-
"
|
147
|
+
"grp-#{@@global.zone}-#{current_machine_group}"
|
135
148
|
end
|
136
149
|
|
137
150
|
def current_machine_count
|
@@ -175,20 +188,13 @@ module Rudy
|
|
175
188
|
def current_machine_name
|
176
189
|
[@@global.zone, current_machine_group, @@global.position].join(Rudy::DELIM)
|
177
190
|
end
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
def
|
184
|
-
|
185
|
-
@@global.user = @switch_user_previous
|
186
|
-
elsif @@global.user != name
|
187
|
-
raise "No root keypair defined for #{name}!" unless has_keypair?(name)
|
188
|
-
@@logger.puts "Remote commands will be run as #{name} user"
|
189
|
-
@switch_user_previous = @@global.user
|
190
|
-
@@global.user = name
|
191
|
-
end
|
191
|
+
|
192
|
+
def current_machine_user
|
193
|
+
@@global.user || fetch_machine_param(:user) || @@config.defaults.user || Rudy.sysinfo.user
|
194
|
+
end
|
195
|
+
|
196
|
+
def current_machine_bucket
|
197
|
+
@@global.bucket || fetch_machine_param(:bucket) || nil
|
192
198
|
end
|
193
199
|
|
194
200
|
def self.keypair_path_to_name(kp)
|
@@ -247,7 +253,7 @@ module Rudy
|
|
247
253
|
raise NoRoutinesConfig unless @@config.routines
|
248
254
|
raise NoGlobal unless @@global
|
249
255
|
|
250
|
-
action = action.to_s.tr('
|
256
|
+
action = action.to_s.tr('-:', '_')
|
251
257
|
|
252
258
|
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
253
259
|
|
@@ -264,12 +270,12 @@ module Rudy
|
|
264
270
|
|
265
271
|
routine.disks.each_pair do |raction,disks|
|
266
272
|
unless disks.kind_of?(Hash)
|
267
|
-
|
273
|
+
li "#{raction} is not defined. Check your #{action} routines config.".color(:red)
|
268
274
|
next
|
269
275
|
end
|
270
276
|
disks.each_pair do |path, props|
|
271
277
|
unless disk_defs.has_key?(path)
|
272
|
-
|
278
|
+
li "#{path} is not defined. Check your #{action} machines config.".color(:red)
|
273
279
|
routine.disks[raction].delete(path)
|
274
280
|
next
|
275
281
|
end
|
@@ -311,12 +317,15 @@ module Rudy
|
|
311
317
|
raise NoGlobal unless @@global
|
312
318
|
zon, env, rol = @@global.zone, @@global.environment, @@global.role
|
313
319
|
hashes = []
|
320
|
+
# This is fucked!
|
314
321
|
hashes << @@config.machines.find(env, rol)
|
315
322
|
hashes << @@config.machines.find(zon, env, rol)
|
316
323
|
hashes << @@config.machines.find(zon, [env, rol])
|
317
324
|
hashes << @@config.machines.find(zon, env)
|
318
325
|
hashes << @@config.machines.find(env)
|
319
326
|
hashes << @@config.machines.find(zon)
|
327
|
+
hashes << @@config.machines.find(rol)
|
328
|
+
hashes << @@config.machines.find(@@global.region)
|
320
329
|
compilation = {}
|
321
330
|
hashes.reverse.each do |conf|
|
322
331
|
compilation.merge! conf if conf
|