lib/vagrant-qienv/config/config_network.rb
# Builds a file with the list of pairs IP address: hostname which will be read
# by Ansible to setup the hosts file in each VM
# Params:
# +env_vms+: object with the definition of the virtual machines
Builds a file with the list of pairs IP address: hostname which will be read
by Ansible to setup the hosts file in each VM
Params:
+env_vms+: object with the definition of the virtual machines
Builds a file with the list of pairs IP address : hostname which will be read by Ansible to setup the hosts file in each VM Params : + env_vms + : object with the definition of the virtual machines
def build_hosts_list(env_vms)
  int_id = 10
  first = true
  env_vms.each do |vm, vmconfig|
    vmconfig["networks"].each do |name, netcfg|
      if netcfg["type"] == "private" then
        if netcfg['ip'].nil? then
          netcfg['ip'] = "192.168.50." + int_id.to_s
          env_vms[vm]["networks"][name]["ip"] = "192.168.50." + int_id.to_s
          int_id += 1
        end
        if first then
          $base_vars = "vms_hosts={"
          $base_vars << "\"#{netcfg['ip']}\":\"#{vm}\""
          first = false
        elsif
          $base_vars << ",\"#{netcfg['ip']}\":\"#{vm}\""
        end
      end
    end if vmconfig["networks"]
  end
  $base_vars << "}" if $base_vars
end
def build_hosts_list ( env_vms ) int_id = 10 first = true env_vms . each do | vm , vmconfig | vmconfig [ "networks" ] . each do | name , netcfg | if netcfg [ "type" ] == "private" then if netcfg [ 'ip' ] . nil? then netcfg [ 'ip' ] = "192.168.50." + int_id . to_s env_vms [ vm ] [ "networks" ] [ name ] [ "ip" ] = "192.168.50." + int_id . to_s int_id += 1 end if first then $base_vars = "vms_hosts={" $base_vars << "\"#{netcfg['ip']}\":\"#{vm}\"" first = false elsif $base_vars << ",\"#{netcfg['ip']}\":\"#{vm}\"" end end end if vmconfig [ "networks" ] end $base_vars << "}" if $base_vars end
Builds a file with the list of pairs IP address: hostname which will be read
by Ansible to setup the hosts file in each VM
Params:
+env_vms+: object with the definition of the virtual machines
Builds a file with the list of pairs IP address : hostname which will be read by Ansible to setup the hosts file in each VM Params : + env_vms + : object with the definition of the virtual machines
#add the default IP to the environment definnition
env_vms