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
@@ -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,95 @@
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; "Specified remote machine(s) not running"; end
52
+ end
53
+ class MachineGroupNotDefined < Rudy::Error
54
+ def message; "#{@obj} is not defined in machines config."; end
55
+ end
56
+ class PrivateKeyFileExists < Rudy::Error
57
+ def message; "Private key #{@obj} already exists."; end
58
+ end
59
+ class PrivateKeyNotFound < Rudy::Error
60
+ def message; "Private key file #{@obj} not found."; end
61
+ end
62
+ class UnsupportedOS < Rudy::Error; end
63
+
64
+
65
+ class NotImplemented < Rudy::Error; end
66
+
67
+
68
+ module Metadata
69
+ class UnknownRecordType < Rudy::Error
70
+ def message; "Unknown record type: #{@obj}"; end
71
+ end
72
+ class UnknownObject < Rudy::Error
73
+ def message; "Unknown object: #{@obj}"; end
74
+ end
75
+ # Raised when trying to save a record with a key that already exists
76
+ class DuplicateRecord < Rudy::Error; end
77
+
78
+ end
79
+
80
+ module Disks
81
+ class NotAttached < Rudy::Error; end
82
+ class NotFormatted < Rudy::Error; end
83
+ class AlreadyFormatted < Rudy::Error; end
84
+ class AlreadyMounted < Rudy::Error; end
85
+ class AlreadyAttached < Rudy::Error; end
86
+ class NotMounted < Rudy::Error; end
87
+ class InUse < Rudy::Error; end
88
+ end
89
+
90
+ module Backups
91
+ class NoDisk < Rudy::Error; end
92
+ class NoBackup < Rudy::Error; end
93
+ end
94
+
95
+ end
@@ -23,18 +23,22 @@ module Rudy
23
23
  field :format
24
24
  field :print_header
25
25
  field :yes
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 :privatekey
33
+ field :pkey
33
34
 
34
- field :local_user
35
- field :local_hostname
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,42 +50,49 @@ 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)
55
60
  return unless config.is_a?(Rudy::Config)
61
+ clear_system_defaults # temporarily unapply default values
62
+
56
63
  if config.defaults?
57
64
  # Apply the "color" default before "nocolor" so nocolor has presedence
58
65
  @nocolor = !config.defaults.color unless config.defaults.color.nil?
59
- %w[region zone environment role position user nocolor quiet yes].each do |name|
60
- val = config.defaults.send(name)
61
- self.send("#{name}=", val) unless val.nil?
66
+ # WARNING: Don't add user to this list. The global value should return
67
+ # the value specified on the command line or nil. If it is nil, we can
68
+ # check the value from the machines config. If that is nil, we use the
69
+ # value from the defaults config.
70
+ # WARNING: Don't add bucket either or any machines configuration param
71
+ # TODO: investigate removing this apply_config method
72
+ %w[region zone environment role position
73
+ localhost nocolor quiet yes force parallel].each do |name|
74
+ curval, defval = self.send(name), config.defaults.send(name)
75
+ self.send("#{name}=", defval) if curval.nil? && !defval.nil?
62
76
  end
63
77
  end
64
78
 
65
79
  if config.accounts? && config.accounts.aws
66
- %w[accesskey secretkey accountnum cert privatekey].each do |name|
80
+ %w[accesskey secretkey accountnum cert pkey].each do |name|
67
81
  val = config.accounts.aws.send(name)
68
82
  self.send("#{name}=", val) unless val.nil?
69
83
  end
70
84
  end
71
-
72
85
  postprocess
73
86
  end
74
87
 
88
+ def zone=(z)
89
+ @zone = z.to_sym
90
+ @region = @zone.to_s.gsub(/[a-z]$/, '').to_sym
91
+ end
75
92
 
76
93
  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
-
94
+ ghash = ghash.marshal_dump if ghash.is_a?(OpenStruct)
95
+ ghash.each_pair { |n,v| self.send("#{n}=", v) }
85
96
  postprocess
86
97
  end
87
98
 
@@ -97,7 +108,7 @@ module Rudy
97
108
  apply_system_defaults
98
109
  @nocolor = !@color unless @color.nil?
99
110
  @cert &&= File.expand_path(@cert)
100
- @privatekey &&= File.expand_path(@privatekey)
111
+ @pkey &&= File.expand_path(@pkey)
101
112
  @position &&= @position.to_s.rjust(2, '0')
102
113
  @format &&= @format.to_sym rescue nil
103
114
  @quiet ? Rudy.enable_quiet : Rudy.disable_quiet
@@ -109,18 +120,30 @@ module Rudy
109
120
  @secretkey ||= ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY']
110
121
  @accountnum ||= ENV['AWS_ACCOUNT_NUMBER']
111
122
  @cert ||= ENV['EC2_CERT']
112
- @privatekey ||= ENV['EC2_PRIVATE_KEY']
113
- @local_user = ENV['USER'] || :rudy
114
- @local_hostname = Socket.gethostname || :localhost
123
+ @pkey ||= ENV['EC2_PRIVATE_KEY']
115
124
  end
116
125
 
126
+ # Apply defaults for parameters that must have values
117
127
  def apply_system_defaults
118
128
  @region ||= Rudy::DEFAULT_REGION
119
129
  @zone ||= Rudy::DEFAULT_ZONE
120
130
  @environment ||= Rudy::DEFAULT_ENVIRONMENT
121
131
  @role ||= Rudy::DEFAULT_ROLE
122
- @position ||= Rudy::DEFAULT_POSITION
123
- @user ||= Rudy::DEFAULT_USER
132
+ @localhost ||= Rudy.sysinfo.hostname || 'localhost'
133
+ @yes = false if @yes.nil?
134
+ end
135
+
136
+ # Unapply defaults for parameters that must have values.
137
+ # This is important when reloading configuration since
138
+ # we don't overwrite existing values. If the default
139
+ # ones remained the configuration would not be applied.
140
+ def clear_system_defaults
141
+ @region = nil if @region == Rudy::DEFAULT_REGION
142
+ @zone = nil if @zone == Rudy::DEFAULT_ZONE
143
+ @environment = nil if @environment == Rudy::DEFAULT_ENVIRONMENT
144
+ @role = nil if @role == Rudy::DEFAULT_ROLE
145
+ @localhost = nil if @localhost == (Rudy.sysinfo.hostname || 'localhost')
146
+ @yes = nil if @yes == false
124
147
  end
125
148
 
126
149
  end
@@ -1,12 +1,13 @@
1
1
 
2
2
 
3
3
  module Rudy
4
- module Guidelines #:nodoc:all
4
+ module Guidelines
5
5
  extend self
6
- AFE = "Always fail early" # [ed: the A's are a work in progress]
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)] }
@@ -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 > 1)
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={}); @@global.update(ghash); end
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 KeyPair has the same
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
- kp = user_keypairpath(user)
81
- if kp
82
- kp = Huxtable.keypair_path_to_name(kp)
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
- def user_keypairpath(name)
94
- raise Rudy::Error, "No user provided" unless name
95
- raise NoConfig unless @@config
96
- raise NoMachinesConfig unless @@config.machines
97
- raise NoGlobal unless @@global
98
- zon, env, rol = @@global.zone, @@global.environment, @@global.role
99
- #Caesars.enable_debug
100
- path = @@config.machines.find_deferred(zon, env, rol, [:users, name, :keypair])
101
- path ||= @@config.machines.find_deferred(env, rol, [:users, name, :keypair])
102
- path ||= @@config.machines.find_deferred(rol, [:users, name, :keypair])
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
- def has_root_keypair?
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 current_user
123
- @@global.user
124
- end
125
- def current_user_keypairpath
126
- user_keypairpath(current_user)
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
- "g-#{current_machine_group}"
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
- # +name+ the name of the remote user to use for the remainder of the command
180
- # (or until switched again). If no name is provided, the user will be revert
181
- # to whatever it was before the previous switch.
182
- # TODO: deprecate
183
- def switch_user(name=nil)
184
- if name == nil && @switch_user_previous
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) || 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)
@@ -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
- @@logger.puts "#{raction} is not defined. Check your #{action} routines config.".color(:red)
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
- @@logger.puts "#{path} is not defined. Check your #{action} machines config.".color(:red)
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