solutious-rudy 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/CHANGES.txt +8 -9
  2. data/README.rdoc +48 -7
  3. data/Rakefile +102 -7
  4. data/Rudyfile +28 -0
  5. data/bin/ird +162 -0
  6. data/bin/rudy +287 -93
  7. data/lib/annoy.rb +227 -0
  8. data/lib/aws_sdb/service.rb +1 -1
  9. data/lib/console.rb +20 -4
  10. data/lib/escape.rb +305 -0
  11. data/lib/rudy.rb +265 -125
  12. data/lib/rudy/aws.rb +61 -26
  13. data/lib/rudy/aws/ec2.rb +20 -296
  14. data/lib/rudy/aws/ec2/address.rb +121 -0
  15. data/lib/rudy/aws/ec2/group.rb +241 -0
  16. data/lib/rudy/aws/ec2/image.rb +46 -0
  17. data/lib/rudy/aws/ec2/instance.rb +407 -0
  18. data/lib/rudy/aws/ec2/keypair.rb +92 -0
  19. data/lib/rudy/aws/ec2/snapshot.rb +87 -0
  20. data/lib/rudy/aws/ec2/volume.rb +234 -0
  21. data/lib/rudy/aws/simpledb.rb +33 -15
  22. data/lib/rudy/cli.rb +142 -0
  23. data/lib/rudy/cli/addresses.rb +85 -0
  24. data/lib/rudy/cli/backups.rb +175 -0
  25. data/lib/rudy/{command → cli}/config.rb +18 -13
  26. data/lib/rudy/cli/deploy.rb +12 -0
  27. data/lib/rudy/cli/disks.rb +125 -0
  28. data/lib/rudy/cli/domains.rb +17 -0
  29. data/lib/rudy/cli/groups.rb +77 -0
  30. data/lib/rudy/{command → cli}/images.rb +18 -6
  31. data/lib/rudy/cli/instances.rb +142 -0
  32. data/lib/rudy/cli/keypairs.rb +47 -0
  33. data/lib/rudy/cli/manager.rb +51 -0
  34. data/lib/rudy/{command → cli}/release.rb +10 -10
  35. data/lib/rudy/cli/routines.rb +80 -0
  36. data/lib/rudy/cli/volumes.rb +121 -0
  37. data/lib/rudy/command/addresses.rb +62 -39
  38. data/lib/rudy/command/backups.rb +60 -170
  39. data/lib/rudy/command/disks-old.rb +322 -0
  40. data/lib/rudy/command/disks.rb +5 -209
  41. data/lib/rudy/command/domains.rb +34 -0
  42. data/lib/rudy/command/groups.rb +105 -48
  43. data/lib/rudy/command/instances.rb +263 -70
  44. data/lib/rudy/command/keypairs.rb +149 -0
  45. data/lib/rudy/command/manager.rb +65 -0
  46. data/lib/rudy/command/volumes.rb +110 -49
  47. data/lib/rudy/config.rb +90 -70
  48. data/lib/rudy/config/objects.rb +67 -0
  49. data/lib/rudy/huxtable.rb +253 -0
  50. data/lib/rudy/metadata/backup.rb +23 -48
  51. data/lib/rudy/metadata/disk.rb +79 -68
  52. data/lib/rudy/metadata/machine.rb +34 -0
  53. data/lib/rudy/routines.rb +54 -0
  54. data/lib/rudy/routines/disk_handler.rb +190 -0
  55. data/lib/rudy/routines/release.rb +15 -0
  56. data/lib/rudy/routines/script_runner.rb +65 -0
  57. data/lib/rudy/routines/shutdown.rb +42 -0
  58. data/lib/rudy/routines/startup.rb +48 -0
  59. data/lib/rudy/utils.rb +57 -2
  60. data/lib/storable.rb +11 -5
  61. data/lib/sysinfo.rb +274 -0
  62. data/rudy.gemspec +84 -20
  63. data/support/randomize-root-password +45 -0
  64. data/support/rudy-ec2-startup +5 -5
  65. data/support/update-ec2-ami-tools +20 -0
  66. data/test/05_config/00_setup_test.rb +24 -0
  67. data/test/05_config/30_machines_test.rb +69 -0
  68. data/test/20_sdb/00_setup_test.rb +31 -0
  69. data/test/20_sdb/10_domains_test.rb +113 -0
  70. data/test/25_ec2/00_setup_test.rb +34 -0
  71. data/test/25_ec2/10_keypairs_test.rb +33 -0
  72. data/test/25_ec2/20_groups_test.rb +139 -0
  73. data/test/25_ec2/30_addresses_test.rb +35 -0
  74. data/test/25_ec2/40_volumes_test.rb +46 -0
  75. data/test/25_ec2/50_snapshots_test.rb +69 -0
  76. data/test/26_ec2_instances/00_setup_test.rb +33 -0
  77. data/test/26_ec2_instances/10_instances_test.rb +81 -0
  78. data/test/26_ec2_instances/50_images_test.rb +13 -0
  79. data/test/30_sdb_metadata/00_setup_test.rb +28 -0
  80. data/test/30_sdb_metadata/10_disks_test.rb +99 -0
  81. data/test/30_sdb_metadata/20_backups_test.rb +102 -0
  82. data/test/50_commands/00_setup_test.rb +11 -0
  83. data/test/50_commands/10_keypairs_test.rb +79 -0
  84. data/test/50_commands/20_groups_test.rb +77 -0
  85. data/test/50_commands/40_volumes_test.rb +55 -0
  86. data/test/50_commands/50_instances_test.rb +110 -0
  87. data/test/coverage.txt +51 -0
  88. data/test/helper.rb +35 -0
  89. data/tryouts/disks.rb +55 -0
  90. data/tryouts/nested_methods.rb +36 -0
  91. data/tryouts/session_tryout.rb +48 -0
  92. metadata +94 -25
  93. data/bin/rudy-ec2 +0 -108
  94. data/lib/rudy/command/base.rb +0 -839
  95. data/lib/rudy/command/deploy.rb +0 -12
  96. data/lib/rudy/command/environment.rb +0 -74
  97. data/lib/rudy/command/machines.rb +0 -170
  98. data/lib/rudy/command/metadata.rb +0 -41
  99. data/lib/rudy/metadata.rb +0 -26
@@ -0,0 +1,149 @@
1
+
2
+ module Rudy
3
+ class KeyPairs
4
+ include Rudy::Huxtable
5
+
6
+
7
+ def create(n=nil, opts={})
8
+ raise KeyPairAlreadyDefined.new(current_machine_group) if !n && has_root_keypair?
9
+
10
+ n ||= name(n)
11
+
12
+ opts = {
13
+ :force => false
14
+ }.merge(opts)
15
+
16
+ delete_pk(n) if opts[:force] == true && File.exists?(self.path(n))
17
+ raise KeyPairExists, self.path(n) if File.exists?(self.path(n))
18
+
19
+ kp = @@ec2.keypairs.create(n)
20
+ raise ErrorCreatingKeyPair, n unless kp.is_a?(Rudy::AWS::EC2::KeyPair)
21
+
22
+ Rudy.trap_known_errors do
23
+ @logger.puts "Writing #{self.path(n)}"
24
+ Rudy::Utils.write_to_file(self.path(n), kp.private_key, 'w', 0600)
25
+ end
26
+
27
+ Rudy.trap_known_errors do
28
+ @logger.puts "Writing #{self.public_path(n)}"
29
+ Rudy::Utils.write_to_file(self.public_path(n), kp.public_key, 'w', 0600)
30
+ end
31
+
32
+ @logger.puts "NOTE: If you move #{self.path(n)} you need to also update your Rudy machines config.".color(:blue)
33
+
34
+ kp
35
+ end
36
+
37
+ #def check_permissions(n=nil)
38
+ # n ||= name(n)
39
+ # raise NoPrivateKeyFile, self.path(n) unless File.exists?(self.path(n))
40
+ # raise InsecureKeyPairPermissions, self.path(n) unless File::Stat....
41
+ # p n
42
+ #end
43
+
44
+
45
+ def destroy(n=nil)
46
+ n ||= name(n)
47
+ raise "KeyPair #{n} doesn't exist" unless exists?(n)
48
+ @logger.puts "No private key file: #{self.path(n)}. Continuing..." unless File.exists?(self.path(n))
49
+ @logger.puts "Unregistering KeyPair with Amazon"
50
+ ret = @@ec2.keypairs.destroy(n)
51
+ if ret
52
+ ret = delete_files(n) if ret # only delete local file if remote keypair is successfully destroyed
53
+ else
54
+ @logger.puts "Keypair not destroyed successfully."
55
+ end
56
+ ret
57
+ end
58
+
59
+ # Lists the keypairs registered with Amazon
60
+ def list(n=nil, &each_object)
61
+ n &&= [n].flatten.compact
62
+ keypairs = @@ec2.keypairs.list(n)
63
+ keypairs.each { |n,kp| each_object.call(kp) } if each_object
64
+ keypairs || []
65
+ end
66
+
67
+ def get(n=nil)
68
+ n ||= name(n)
69
+ keypairs = @@ec2.keypairs.list(n) || []
70
+ keypairs.first
71
+ end
72
+
73
+ def list_as_hash(n=nil, &each_object)
74
+ n &&= [n].flatten.compact
75
+ keypairs = @@ec2.keypairs.list_as_hash(n)
76
+ keypairs.each_pair { |n,kp| each_object.call(kp) } if each_object
77
+ keypairs || {}
78
+ end
79
+
80
+ def exists?(n=nil)
81
+ n ||= name(n)
82
+ @@ec2.keypairs.exists?(n)
83
+ end
84
+
85
+ def any?(n=nil)
86
+ n ||= name(n)
87
+ @@ec2.keypairs.any?
88
+ end
89
+
90
+ def name(n=nil)
91
+ n ||= "key-#{current_machine_group}"
92
+ n
93
+ end
94
+
95
+ def path(n=nil)
96
+ n ||= name(n)
97
+ File.join(self.config_dirname, "#{n}")
98
+ end
99
+
100
+ def public_path(n=nil)
101
+ n ||= name(n)
102
+ File.join(self.config_dirname, "#{n}.pub")
103
+ end
104
+
105
+
106
+ # We use the base file name to determine the registered keypair name.
107
+ def KeyPairs.path_to_name(path)
108
+ return unless path
109
+ return path unless File.exists?(path)
110
+ File.basename(path)
111
+ end
112
+
113
+ private
114
+ def delete_files(n=nil)
115
+ n ||= name(n)
116
+ @logger.puts "Deleting #{self.path(n)}"
117
+ #return false unless File.exists?(self.path(n))
118
+ ret = (File.unlink(self.path(n)) > 0) # raise exception on error. handle?
119
+
120
+ @logger.puts "Deleting #{self.public_path(n)}"
121
+ #return false unless File.exists?(self.public_path(n))
122
+ ret && (File.unlink(self.public_path(n)) > 0)
123
+ end
124
+
125
+ end
126
+ class Keypairs
127
+ def initialize(*args)
128
+ raise "Oops! The correct class uses a capital 'P': Rudy::KeyPairs"
129
+ end
130
+ end
131
+ end
132
+
133
+ module Rudy
134
+ class KeyPairs
135
+ class InsecureKeyPairPermissions < RuntimeError; end
136
+ class NoPrivateKeyFile < RuntimeError; end
137
+ class ErrorCreatingKeyPair < RuntimeError; end
138
+ class KeyPairExists < RuntimeError; end
139
+ class KeyPairAlreadyDefined < RuntimeError
140
+ attr_reader :group
141
+ def initialize(group)
142
+ @group = group
143
+ end
144
+ def message
145
+ "A keypair is defined for #{group}. Check your Rudy config."
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,65 @@
1
+
2
+
3
+ module Rudy
4
+ class Manager
5
+ include Rudy::Huxtable
6
+
7
+
8
+ end
9
+ end
10
+
11
+
12
+ __END__
13
+
14
+
15
+ def create_domain(name=nil)
16
+ name ||= Rudy::RUDY_DOMAIN
17
+ @@sdb.domains.create(name)
18
+ end
19
+
20
+ def domains
21
+ (@@sdb.domains.list || []).flatten
22
+ end
23
+
24
+
25
+
26
+ def update_valid?
27
+ raise "No EC2 .pem keys provided" unless has_pem_keys?
28
+ raise "No SSH key provided for #{@global.user}!" unless has_keypair?
29
+ raise "No SSH key provided for root!" unless has_keypair?(:root)
30
+
31
+ @option.group ||= machine_group
32
+
33
+ @scripts = %w[rudy-ec2-startup update-ec2-ami-tools randomize-root-password]
34
+ @scripts.collect! {|script| File.join(RUDY_HOME, 'support', script) }
35
+ @scripts.each do |script|
36
+ raise "Cannot find #{script}" unless File.exists?(script)
37
+ end
38
+
39
+ true
40
+ end
41
+
42
+ def update
43
+ puts "Updating Rudy on machines in #{@option.group}"
44
+ switch_user("root")
45
+
46
+ exit unless Annoy.are_you_sure?
47
+ scp do |scp|
48
+ @scripts.each do |script|
49
+ puts "Uploading #{File.basename(script)}"
50
+ scp.upload!(script, "/etc/init.d/")
51
+ end
52
+ end
53
+
54
+ ssh do |session|
55
+ @scripts.each do |script|
56
+ session.exec!("chmod 700 /etc/init.d/#{File.basename(script)}")
57
+ end
58
+
59
+ puts "Installing Rudy (#{Rudy::VERSION})"
60
+ session.exec!("mkdir -p /etc/ec2")
61
+ session.exec!("gem sources -a http://gems.github.com")
62
+ puts session.exec!("gem install --no-ri --no-rdoc rudy -v #{Rudy::VERSION}")
63
+ end
64
+ end
65
+
@@ -1,66 +1,127 @@
1
1
 
2
-
3
2
  module Rudy
4
- module Command
5
- class Volumes < Rudy::Command::Base
3
+ class Volumes
4
+ include Rudy::Huxtable
5
+
6
+
7
+ def create(size, zone=nil, snapshot=nil)
8
+ raise "No size supplied" unless size
9
+ zone ||= @global.zone
6
10
 
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
11
+ @logger.puts "Creating Volume "
12
+ vol = @@ec2.volumes.create(size, zone, snapshot)
13
+ Rudy.waiter(1, 30, @logger) do
14
+ vol = get(vol.awsid) # update the volume until it says it's available
15
+ (vol && vol.status == "available")
14
16
  end
17
+
18
+ vol
19
+ end
15
20
 
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
21
+ def attach(volume, instance, device="/dev/sdh")
22
+ volume = get(volume)
23
+ instance = instance.is_a?(Rudy::AWS::EC2::Instance) ? instance.awsid : instance
24
+ raise "Volume #{volume.awsid} already attached" if volume.attached?
25
+ raise "No instance supplied" unless instance
26
+ raise "No device supplied" unless device
27
+
28
+ ret = false
29
+ begin
30
+ @logger.puts "Attaching Volume... "
31
+ ret = @@ec2.volumes.attach(instance, volume.awsid, device)
32
+ raise "Unknown error" unless ret
24
33
 
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}"
34
+ Rudy.waiter(1, 30, @logger) do
35
+ ret = attached?(volume.awsid)
35
36
  end
36
37
 
38
+ rescue => ex
39
+ @logger.puts ex.backtrace if debug?
40
+ raise "Error attaching #{volume.awsid} to #{instance}: #{ex.message}"
41
+ end
42
+
43
+ ret
44
+ end
45
+
46
+ def destroy(volume)
47
+ volume = get(volume)
48
+
49
+
50
+ ret = false
51
+ begin
52
+
53
+ detach(volume) if volume.attached?
54
+ raise "Volume is still attached. Cannot destroy." unless available?(volume.awsid)
55
+
56
+ ret = @@ec2.volumes.destroy(volume.awsid)
37
57
 
58
+ rescue => ex
59
+ puts ex.backtrace if debug?
60
+ raise "Error destroying volume #{volume.awsid}: #{ex.message}"
38
61
  end
62
+ ret
63
+ end
64
+
65
+ def detach(volume)
66
+ volume = get(volume)
67
+ raise "#{volume.awsid} is not attached" unless attached?(volume.awsid)
39
68
 
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
69
+ ret = false
70
+ begin
71
+ @logger.puts "Dettaching #{volume.awsid} "
72
+ @@ec2.volumes.detach(volume.awsid)
73
+ Rudy.waiter(1, 30) do
74
+ ret = @@ec2.volumes.available?(volume.awsid)
50
75
  end
51
76
 
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
77
+ rescue => ex
78
+ puts ex.backtrace if debug?
79
+ raise "Error detaching volume #{volume.awsid}: #{ex.message}"
61
80
  end
62
81
 
82
+ ret
63
83
  end
64
- end
65
- end
84
+
85
+
86
+ def attached?(volume)
87
+ @@ec2.volumes.attached?(volume)
88
+ end
89
+
90
+ def deleting?(volume)
91
+ @@ec2.volumes.deleting?(volume)
92
+ end
93
+
94
+ def available?(volume)
95
+ @@ec2.volumes.available?(volume)
96
+ end
97
+
98
+ def in_use?(volume)
99
+ @@ec2.volumes.in_use?(volume)
100
+ end
101
+
102
+
103
+ def list(state=nil, vol_id=[])
104
+ @@ec2.volumes.list(state, vol_id)
105
+ end
106
+
107
+ def list_as_hash(state=nil, vol_id=[])
108
+ @@ec2.volumes.list_as_hash(state, vol_id)
109
+ end
110
+
111
+ def any?(state=nil, vol_id=[])
112
+ @@ec2.volumes.any?(state, vol_id)
113
+ end
114
+
115
+ def exists?(vol_id)
116
+ @@ec2.volumes.exists?(vol_id)
117
+ end
118
+
119
+ # * +volopt* is a volume ID or an Rudy::AWS::EC2::Volume object
120
+ def get(volopt)
121
+ return volopt if volopt.is_a?(Rudy::AWS::EC2::Volume)
122
+ @@ec2.volumes.get(volopt)
123
+ end
124
+
66
125
 
126
+ end
127
+ end
data/lib/rudy/config.rb CHANGED
@@ -1,92 +1,112 @@
1
1
 
2
-
3
2
  module Rudy
4
3
  require 'caesars'
5
-
6
- class AWSInfo < Caesars
7
- def valid?
8
- (!account.nil? && !accesskey.nil? && !secretkey.nil?) &&
9
- (!account.empty? && !accesskey.empty? && !secretkey.empty?)
10
- end
11
- end
12
-
13
- class Defaults < Caesars
14
- end
15
-
16
4
 
17
- class Routines < Caesars
5
+ class Config < Caesars::Config
6
+ require 'rudy/config/objects'
18
7
 
19
- def create(*args, &b)
20
- hash_handler(:create, *args, &b)
21
- end
22
- def destroy(*args, &b)
23
- hash_handler(:destroy, *args, &b)
24
- end
25
- def restore(*args, &b)
26
- hash_handler(:restore, *args, &b)
27
- end
28
- def mount(*args, &b)
29
- hash_handler(:mount, *args, &b)
30
- end
8
+ dsl Rudy::Config::Accounts::DSL
9
+ dsl Rudy::Config::Defaults::DSL
10
+ dsl Rudy::Config::Routines::DSL
11
+ dsl Rudy::Config::Machines::DSL
12
+ dsl Rudy::Config::Networks::DSL
31
13
 
32
- #
33
- # Force the specified keyword to always be treated as a hash.
34
- # Example:
35
- #
36
- # startup do
37
- # disks do
38
- # create "/path/2" # Available as hash: [action][disks][create][/path/2] == {}
39
- # create "/path/4" do # Available as hash: [action][disks][create][/path/4] == {size => 14}
40
- # size 14
41
- # end
42
- # end
43
- # end
44
- #
45
- def hash_handler(caesars_meth, *args, &b)
46
- # TODO: Move to caesars
47
- return @caesars_properties[caesars_meth] if @caesars_properties.has_key?(caesars_meth) && args.empty? && b.nil?
48
- return nil if args.empty? && b.nil?
49
- return method_missing(caesars_meth, *args, &b) if args.empty?
50
-
51
- caesars_name = args.shift
52
-
53
- prev = @caesars_pointer
54
- @caesars_pointer[caesars_meth] ||= Caesars::Hash.new
55
- hash = Caesars::Hash.new
56
- @caesars_pointer = hash
57
- b.call if b
58
- @caesars_pointer = prev
59
- @caesars_pointer[caesars_meth][caesars_name] = hash
60
- @caesars_pointer = prev
61
- end
62
- end
63
-
64
- class Machines < Caesars
65
- end
66
-
67
- class Config < Caesars::Config
68
- dsl Rudy::AWSInfo::DSL
69
- dsl Rudy::Defaults::DSL
70
- dsl Rudy::Routines::DSL
71
- dsl Rudy::Machines::DSL
14
+ # TODO: auto-generate in caesars
15
+ def accounts?; self.respond_to?(:accounts) && !self[:accounts].nil?; end
16
+ def defaults?; self.respond_to?(:defaults) && !self[:defaults].nil?; end
17
+ def machines?; self.respond_to?(:machines) && !self[:machines].nil?; end
18
+ def routines?; self.respond_to?(:routines) && !self[:routines].nil?; end
19
+ def networks?; self.respond_to?(:networks) && !self[:networks].nil?; end
72
20
 
73
21
  def postprocess
74
- # TODO: give caesar attributes setter methods
75
- self.awsinfo.cert &&= File.expand_path(self.awsinfo.cert)
76
- self.awsinfo.privatekey &&= File.expand_path(self.awsinfo.privatekey)
22
+ #raise "There is no AWS info configured" if self.accounts.nil?
77
23
 
24
+ # These don't work anymore. Caesars bug?
25
+ #if accounts? && !self.accounts.aws.nil?
26
+ # self.accounts.aws.cert &&= File.expand_path(self.accounts.aws.cert)
27
+ # self.accounts.aws.privatekey &&= File.expand_path(self.accounts.aws.privatekey)
28
+ #end
78
29
  end
79
30
 
80
- def look_and_load
31
+ def look_and_load(adhoc_path=nil)
81
32
  cwd = Dir.pwd
82
- # Rudy looks for configs in all these locations
33
+ cwd_path = File.join(cwd, '.rudy', 'config')
34
+
35
+ # Attempt to load the core configuration file first.
36
+ # The "core" config file can have any or all configuration
37
+ # but it should generally only contain the access identifiers
38
+ # and defaults. That's why we only load one of them.
39
+ core_config_paths = [adhoc_path, cwd_path, RUDY_CONFIG_FILE]
40
+ core_config_paths.each do |path|
41
+ next unless path && File.exists?(path)
42
+ @paths << path
43
+ break
44
+ end
45
+
46
+ # Rudy then looks for the rest of the config in these locations
83
47
  @paths += Dir.glob(File.join('/etc', 'rudy', '*.rb')) || []
48
+ @paths += Dir.glob(File.join(cwd, 'Rudyfile')) || []
84
49
  @paths += Dir.glob(File.join(cwd, 'config', 'rudy', '*.rb')) || []
85
50
  @paths += Dir.glob(File.join(cwd, '.rudy', '*.rb')) || []
51
+ @paths &&= @paths.uniq
86
52
  refresh
87
53
  end
54
+
88
55
 
89
56
 
57
+ def self.init_config_dir
58
+
59
+ unless File.exists?(RUDY_CONFIG_DIR)
60
+ puts "Creating #{RUDY_CONFIG_DIR}"
61
+ Dir.mkdir(RUDY_CONFIG_DIR, 0700)
62
+ end
63
+
64
+ unless File.exists?(RUDY_CONFIG_FILE)
65
+ puts "Creating #{RUDY_CONFIG_FILE}"
66
+ rudy_config = Rudy::Utils.without_indent %Q{
67
+ # Amazon Web Services
68
+ # Account access indentifiers.
69
+ accounts do
70
+ aws do
71
+ name "Rudy Default"
72
+ accountnum ""
73
+ accesskey ""
74
+ secretkey ""
75
+ privatekey "~/path/2/pk-xxxx.pem"
76
+ cert "~/path/2/cert-xxxx.pem"
77
+ end
78
+ end
79
+
80
+ # Machine Configuration
81
+ # Specify your private keys here. These can be defined globally
82
+ # or by environment and role like in machines.rb.
83
+ machines do
84
+ users do
85
+ #root :keypair => "path/2/root-private-key"
86
+ end
87
+ zone :"us-east-1b" do
88
+ ami 'ami-235fba4a' # Amazon Getting Started AMI (US)
89
+ end
90
+ zone :"eu-west-1b" do
91
+ ami 'ami-e40f2790' # Amazon Getting Started AMI (EU)
92
+ end
93
+ end
94
+
95
+ # Global Defaults
96
+ # Define the values to use unless otherwise specified on the command-line.
97
+ defaults do
98
+ region :"us-east-1"
99
+ zone :"us-east-1b"
100
+ environment :stage
101
+ role :app
102
+ position "01"
103
+ user ENV['USER'].to_sym
104
+ end
105
+ }
106
+ Rudy::Utils.write_to_file(RUDY_CONFIG_FILE, rudy_config, 'w', 0600)
107
+ end
108
+ end
109
+
90
110
  end
91
111
  end
92
112