Class: Messhy::CLI
- Inherits:
-
Thor
- Object
- Thor
- Messhy::CLI
- Defined in:
- lib/messhy/cli.rb
Instance Method Summary collapse
- #dns ⇒ Object
- #keygen ⇒ Object
- #list ⇒ Object
- #ping(node) ⇒ Object
- #setup ⇒ Object
- #show(name) ⇒ Object
- #stats ⇒ Object
- #status ⇒ Object
- #test_connectivity ⇒ Object
- #trust_hosts ⇒ Object
- #version ⇒ Object
Instance Method Details
#dns ⇒ Object
32 33 34 35 36 37 |
# File 'lib/messhy/cli.rb', line 32 def dns config = load_config DnsManager.new(config, dry_run: [:dry_run], skip: [:skip_node]).setup rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#keygen ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/messhy/cli.rb', line 41 def keygen config = load_config installer = Installer.new(config) installer.generate_keys(skip: [:skip_node]) rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#list ⇒ Object
107 108 109 110 111 112 |
# File 'lib/messhy/cli.rb', line 107 def list config = load_config config.each_node do |name, node_config| puts "#{name}: #{node_config['host']} (#{node_config['private_ip']})" end end |
#ping(node) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/messhy/cli.rb', line 59 def ping(node) config = load_config health_checker = HealthChecker.new(config) health_checker.ping_node(node) rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#setup ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/messhy/cli.rb', line 14 def setup config = load_config installer = Installer.new(config, dry_run: [:dry_run]) if [:only_node] installer.setup_node([:only_node]) elsif [:skip_node] installer.setup(skip: [:skip_node]) else installer.setup end rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#show(name) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/messhy/cli.rb', line 115 def show(name) config = load_config node_config = config.node_config(name) unless node_config puts "Node not found: #{name}" exit 1 end puts "Node: #{name}" puts "Host: #{node_config['host']}" puts "Private IP: #{node_config['private_ip']}" puts "Region: #{node_config['region']}" if node_config['region'] health_checker = HealthChecker.new(config) health_checker.show_node_status(name) rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#stats ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/messhy/cli.rb', line 78 def stats config = load_config health_checker = HealthChecker.new(config) health_checker.show_stats(node: [:node]) rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#status ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/messhy/cli.rb', line 50 def status config = load_config health_checker = HealthChecker.new(config) health_checker.show_status rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#test_connectivity ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/messhy/cli.rb', line 68 def test_connectivity config = load_config health_checker = HealthChecker.new(config) health_checker.test_all rescue SSHKit::Runner::ExecuteError => e handle_ssh_error(e, config) end |
#trust_hosts ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/messhy/cli.rb', line 91 def trust_hosts config = load_config timeout = ([:timeout] || HostTrustManager::DEFAULT_TIMEOUT).to_i manager = HostTrustManager.new( config, known_hosts_path: [:known_hosts] || File.('~/.ssh/known_hosts'), timeout: timeout, hash_hosts: [:hash_hosts], replace_existing: [:force] ) success = manager.trust_all_hosts exit 1 unless success end |