Class: Messhy::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/messhy/cli.rb

Instance Method Summary collapse

Instance Method Details

#dnsObject



32
33
34
35
36
37
# File 'lib/messhy/cli.rb', line 32

def dns
  config = load_config
  DnsManager.new(config, dry_run: options[:dry_run], skip: options[:skip_node]).setup
rescue SSHKit::Runner::ExecuteError => e
  handle_ssh_error(e, config)
end

#keygenObject



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: options[:skip_node])
rescue SSHKit::Runner::ExecuteError => e
  handle_ssh_error(e, config)
end

#listObject



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

#setupObject



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: options[:dry_run])

  if options[:only_node]
    installer.setup_node(options[:only_node])
  elsif options[:skip_node]
    installer.setup(skip: options[: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

#statsObject



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: options[:node])
rescue SSHKit::Runner::ExecuteError => e
  handle_ssh_error(e, config)
end

#statusObject



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_connectivityObject



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_hostsObject



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 = (options[:timeout] || HostTrustManager::DEFAULT_TIMEOUT).to_i
  manager = HostTrustManager.new(
    config,
    known_hosts_path: options[:known_hosts] || File.expand_path('~/.ssh/known_hosts'),
    timeout: timeout,
    hash_hosts: options[:hash_hosts],
    replace_existing: options[:force]
  )

  success = manager.trust_all_hosts
  exit 1 unless success
end

#versionObject



136
137
138
# File 'lib/messhy/cli.rb', line 136

def version
  puts "messhy #{Messhy::VERSION}"
end