aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/config/macros.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-02-07 00:00:12 -0800
committerelijah <elijah@riseup.net>2014-02-07 00:00:12 -0800
commite8533d45bf99036952e2465bde0e79faee1dda7c (patch)
treef4be8588d5794c9315acf9dea023b117a3f43e6b /lib/leap_cli/config/macros.rb
parent79afefc5c8a80da51fd735edfcd780c8be5b8ffc (diff)
downloadleap_cli-e8533d45bf99036952e2465bde0e79faee1dda7c.tar.gz
leap_cli-e8533d45bf99036952e2465bde0e79faee1dda7c.tar.bz2
added support for custom /etc/hosts files, fixed bug in ObjectList filters (when using negative value on an array attribute).
Diffstat (limited to 'lib/leap_cli/config/macros.rb')
-rw-r--r--lib/leap_cli/config/macros.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/leap_cli/config/macros.rb b/lib/leap_cli/config/macros.rb
index aaed77a..69c3049 100644
--- a/lib/leap_cli/config/macros.rb
+++ b/lib/leap_cli/config/macros.rb
@@ -157,15 +157,24 @@ module LeapCli; module Config
end
#
- # Generates entries needed for updating /etc/hosts on a node, but only including the IPs of the
- # other nodes we have encountered. Also, for virtual machines, use the local address if this
- # @node is in the same location.
+ # Generates entries needed for updating /etc/hosts on a node (as a hash).
#
- def hosts_file
- if @referenced_nodes && @referenced_nodes.any?
+ # Argument `nodes` can be nil or a list of nodes. If nil, only include the
+ # IPs of the other nodes this @node as has encountered.
+ #
+ # Also, for virtual machines, we use the local address if this @node is in
+ # the same location as the node in question.
+ #
+ def hosts_file(nodes=nil)
+ if nodes.nil?
+ if @referenced_nodes && @referenced_nodes.any?
+ nodes = @referenced_nodes
+ end
+ end
+ if nodes
hosts = {}
my_location = @node['location'] ? @node['location']['name'] : nil
- @referenced_nodes.each_node do |node|
+ nodes.each_node do |node|
next if node.name == @node.name
hosts[node.name] = {'ip_address' => node.ip_address, 'domain_internal' => node.domain.internal, 'domain_full' => node.domain.full}
node_location = node['location'] ? node['location']['name'] : nil
@@ -177,7 +186,6 @@ module LeapCli; module Config
end
end
end
- #hosts = @referenced_nodes.pick_fields("ip_address", "domain.internal", "domain.full")
return hosts
else
return nil