Sha256: 5c1293e2dda516524403d50424b97fa863eccdbf58739117402fac30ee1f90d2

Contents?: true

Size: 801 Bytes

Versions: 3

Compression:

Stored size: 801 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
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

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-vyos-1.1.1 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.1.0 lib/vagrant-vyos/cap/change_host_name.rb
vagrant-vyos-1.0.0 lib/vagrant-vyos/cap/change_host_name.rb