Sha256: 13e9f68823ed5ad6248cf425b13d1075444310df5fd15c955a7db13789684a90

Contents?: true

Size: 904 Bytes

Versions: 9

Compression:

Stored size: 904 Bytes

Contents

require 'tempfile'

module VagrantPlugins
  module GuestVyOS
    module Cap
      class ChangeHostName
        def self.change_host_name(machine, name)
          machine.communicate.tap do |comm|
            if !comm.test("sudo hostname | grep '^#{name}$'")

              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
set system host-name #{name}
commit
save
              EOS

              temp = Tempfile.new("vagrant")
              temp.binmode
              temp.write(commands)
              temp.close

              comm.upload(temp.path, "/tmp/vagrant-change-hostname")
              comm.execute("bash /tmp/vagrant-change-hostname")
              comm.execute("rm -f /tmp/vagrant-change-hostname")
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vagrant-vyos-1.1.12 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.10 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.9 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.7 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.6 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.5 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.4 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.3 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.2 lib/vagrant-vyos/cap/change_host_name.rb