Sha256: 5fbac52c3754e03051c3eb4ffe7028c2a09ea0448f6abae9712275b3c722d9a6
Contents?: true
Size: 1.38 KB
Versions: 9
Compression:
Stored size: 1.38 KB
Contents
require 'ipaddr' require 'tempfile' module VagrantPlugins module GuestVyOS module Cap class ConfigureNetworks def self.configure_networks(machine, networks) machine.communicate.tap do |comm| commands = <<-EOS if [ "$(id -g -n)" != 'vyattacfg' ] ; then exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@" fi source /opt/vyatta/etc/functions/script-template EOS networks.each do |network| commands << "delete interfaces ethernet eth#{network[:interface]}\n" if network[:type].to_sym == :static subnet = IPAddr.new(network[:netmask]).to_i.to_s(2).count("1") commands << "set interfaces ethernet eth#{network[:interface]} address #{network[:ip]}/#{subnet}\n" elsif network[:type].to_sym == :dhcp commands << "set interfaces ethernet eth#{network[:interface]} address dhcp\n" end end commands << <<-EOS commit save EOS temp = Tempfile.new("vagrant") temp.binmode temp.write(commands) temp.close comm.upload(temp.path, "/tmp/vagrant-configure-network") comm.execute("bash /tmp/vagrant-configure-network") comm.execute("rm -f /tmp/vagrant-configure-network") end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems