Class: DanarchySys::ConfigManager::Config
- Inherits:
-
Object
- Object
- DanarchySys::ConfigManager::Config
- Defined in:
- lib/danarchy_sys/config_manager.rb
Class Method Summary collapse
- .config_template ⇒ Object
- .global_setting_add(config, name, value) ⇒ Object
- .global_setting_delete(config, name) ⇒ Object
- .new ⇒ Object
- .new_config(danarchysys_cfg_path, config_yml) ⇒ Object
- .providers ⇒ Object
- .save(config_file, param_hash) ⇒ Object
Class Method Details
.config_template ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/danarchy_sys/config_manager.rb', line 25 def self.config_template config_template = { global_settings: { ssh_key_path: nil }, connections: {} } end |
.global_setting_add(config, name, value) ⇒ Object
108 109 110 |
# File 'lib/danarchy_sys/config_manager.rb', line 108 def self.global_setting_add(config, name, value) config[:global_settings][name.to_sym] = value end |
.global_setting_delete(config, name) ⇒ Object
112 113 114 |
# File 'lib/danarchy_sys/config_manager.rb', line 112 def self.global_setting_delete(config, name) config[:global_settings].delete(name.to_sym) end |
.new ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/danarchy_sys/config_manager.rb', line 9 def self.new danarchysys_cfg_path = File.join(File.realpath(ENV['HOME']), '.danarchy_sys') config_yml = File.join(danarchysys_cfg_path, 'danarchysys.yml') if File.exists?(config_yml) return YAML.load_file(config_yml) else puts 'No existing configuration found!' return new_config(danarchysys_cfg_path, config_yml) end end |
.new_config(danarchysys_cfg_path, config_yml) ⇒ Object
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/danarchy_sys/config_manager.rb', line 34 def self.new_config(danarchysys_cfg_path, config_yml) config = config_template ssh_path = File.join(danarchysys_cfg_path, 'ssh') puts "dAnarchy_sys config location: #{danarchysys_cfg_path}" FileUtils.mkdir_p(danarchysys_cfg_path, mode: 0700) unless Dir.exist?(danarchysys_cfg_path) print "Default ssh key location: #{ssh_path}. Is this location okay?: (Y/N) " answer = gets.chomp until answer =~ /^y(es)?$/i print 'Enter a path for SSH keys: ' ssh_path = gets.chomp print "Setting SSH key path to: #{ssh_path}. Is this location okay? (Y/N): " answer = gets.chomp end puts "SSH key path set to: #{ssh_path}" FileUtils.mkdir_p(ssh_path, mode: 0700) unless Dir.exist?(ssh_path) global_setting_add(config, 'ssh_key_path', ssh_path) provider = nil if providers.count > 1 num_providers = Helpers.array_to_numhash(providers) fields = PrintFormats.printf_hash(num_providers) printf("#{fields}\n", 'Id', 'Provider') num_providers.each do |k, v| printf("#{fields}\n", "#{k}.", v) end provider = nil until providers.include?(provider) print 'Please choose a provider: ' provider = gets.chomp if provider =~ /^[0-9]*$/ if num_providers.keys.include?(provider) provider = num_providers[provider] else print "#{provider} is not a valid Id. " end end if provider.empty? || providers.include?(provider) == false print 'Invalid input! ' end end else provider = providers[0] end if provider == 'openstack' puts 'Creating a new OpenStack connection!' print 'Enter a provider name for this connection: ' provider = gets.chomp cfg_os = DanarchySys::ConfigManager::OpenStack.new(provider, config) config = cfg_os.new_connection_prompt elsif provider == 'aws' # Placeholder puts 'AWS not yet implemented!' end save(config_yml, config) puts "Configuration has been saved to #{config_yml}" puts "Copy any existing #{provider} SSH keys to: #{ssh_path}" config end |
.providers ⇒ Object
21 22 23 |
# File 'lib/danarchy_sys/config_manager.rb', line 21 def self.providers ['openstack'] # , 'aws'] end |
.save(config_file, param_hash) ⇒ Object
103 104 105 |
# File 'lib/danarchy_sys/config_manager.rb', line 103 def self.save(config_file, param_hash) File.write(config_file, param_hash.to_yaml) end |