summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-06-29 16:51:08 -0700
committerelijah <elijah@riseup.net>2015-06-29 16:51:08 -0700
commitfe0eb1c0c3101bd2c5dd665a6c4d1f1dba2e3b08 (patch)
treecec99abb94e4743f8d14165f8ea975966c968f82
parent98cf1714c70ac6833551bfdc26a50986c1e34944 (diff)
add sanity checking to compile (confirm ips are unique, not the same as current host)
-rw-r--r--lib/leap_cli/commands/compile.rb30
-rw-r--r--lib/leap_cli/log.rb2
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/leap_cli/commands/compile.rb b/lib/leap_cli/commands/compile.rb
index 3ddc0c3..c7ff58b 100644
--- a/lib/leap_cli/commands/compile.rb
+++ b/lib/leap_cli/commands/compile.rb
@@ -1,3 +1,4 @@
+require 'socket'
module LeapCli
module Commands
@@ -53,6 +54,7 @@ module LeapCli
#
def compile_hiera_files(nodes, clean_export)
update_compiled_ssh_configs # must come first
+ sanity_check(nodes)
manager.export_nodes(nodes)
manager.export_secrets(clean_export)
end
@@ -63,6 +65,34 @@ module LeapCli
update_known_hosts
end
+ def sanity_check(nodes)
+ # confirm that every node has a unique ip address
+ ips = {}
+ nodes.pick_fields('ip_address').each do |name, ip_address|
+ if ips.key?(ip_address)
+ bail! {
+ log(:fatal_error, "Every node must have its own IP address.") {
+ log "Nodes `#{name}` and `#{ips[ip_address]}` are both configured with `#{ip_address}`."
+ }
+ }
+ else
+ ips[ip_address] = name
+ end
+ end
+ # confirm that the IP address of this machine is not also used for a node.
+ Socket.ip_address_list.each do |addrinfo|
+ if !addrinfo.ipv4_private? && ips.key?(addrinfo.ip_address)
+ ip = addrinfo.ip_address
+ name = ips[ip]
+ bail! {
+ log(:fatal_error, "Something is very wrong. The `leap` command must only be run on your sysadmin machine, not on a provider node.") {
+ log "This machine has the same IP address (#{ip}) as node `#{name}`."
+ }
+ }
+ end
+ end
+ end
+
##
## SSH
##
diff --git a/lib/leap_cli/log.rb b/lib/leap_cli/log.rb
index c345107..0915151 100644
--- a/lib/leap_cli/log.rb
+++ b/lib/leap_cli/log.rb
@@ -80,7 +80,7 @@ module LeapCli
if title
prefix_options = case title
when :error then ['error', :red, :bold]
- when :fatal_error then ['fatal error', :red, :bold]
+ when :fatal_error then ['fatal error:', :red, :bold]
when :warning then ['warning:', :yellow, :bold]
when :info then ['info', :cyan, :bold]
when :updated then ['updated', :cyan, :bold]