Class: Eclair::Config
- Inherits:
-
Object
- Object
- Eclair::Config
- Defined in:
- lib/eclair/config.rb
Constant Summary collapse
- KEYS_DIR =
"#{ENV['HOME']}/.ecl/keys"
- CACHE_DIR =
"#{ENV['HOME']}/.ecl/.cache"
Instance Method Summary collapse
- #after_load ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/eclair/config.rb', line 15 def initialize @done = false @config_file = ENV["ECLRC"] || "#{ENV['HOME']}/.ecl/config.rb" @aws_region = nil @columns = 4 @group_by = lambda do |instance| if instance.security_groups.first instance.security_groups.first.group_name else "no_group" end end @ssh_username = lambda do |image| case image.name when /ubuntu/ "ubuntu" else "ec2-user" end end @ssh_command = "ssh" @ssh_keys = {} @ssh_ports = [22].freeze @ssh_options = "-o ConnectTimeout=1 -o StrictHostKeyChecking=no".freeze @dir_keys = {} @exec_format = "{ssh_command} {ssh_options} -p{port} {ssh_key} {username}@{host}" @provider = :ec2 @get_pods_option = "" instance_variables.each do |var| Config.class_eval do attr_accessor var.to_s.tr("@","").to_sym end end # Migrate old ~/.eclrc to ~/.ecl/config.rb old_conf = "#{ENV['HOME']}/.eclrc" new_dir = "#{ENV['HOME']}/.ecl" new_conf = "#{ENV['HOME']}/.ecl/config.rb" if !File.exists?(new_conf) && File.exists?(old_conf) FileUtils.mkdir_p new_dir FileUtils.mv old_conf, new_conf puts "#{old_conf} migrated to #{new_conf}" puts "Please re-run eclair" exit end unless File.exists? @config_file template_path = File.join(File.dirname(__FILE__), "..", "..", "templates", "eclrc.template") FileUtils.mkdir_p(File.dirname(@config_file)) FileUtils.cp(template_path, @config_file) puts "#{@config_file} successfully created. Edit it and run again!" exit end key_path = "#{new_dir}/keys" FileUtils.mkdir_p key_path unless Dir.exists? key_path # FileUtils.mkdir_p CACHE_DIR unless Dir.exists? CACHE_DIR end |
Instance Method Details
#after_load ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/eclair/config.rb', line 76 def after_load dir_keys = {} Dir["#{KEYS_DIR}/*"].each do |key| if File.file? key dir_keys[File.basename(key, ".*")] = key end end @ssh_keys.merge!(dir_keys) end |