8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/vagrant-solaris10/cap/change_host_name.rb', line 8
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
if !comm.test("hostname | grep '#{name}", sudo: true)
ifconfig = nil
comm.execute("ifconfig -a") do |type, data|
if type == :stdout
ifconfig ||= ""
ifconfig += data
end
end
broadcasting_interface = ifconfig.scan(/^(\w+).*BROADCAST/)[0][0]
broadcasting_ip = ifconfig.scan(/inet\s(\S+).*broadcast/)[0][0]
comm.sudo("sh -c \"echo '#{name}' > /etc/nodename\"")
comm.sudo("sh -c \"echo '#{name}' > /etc/hostname.#{broadcasting_interface}\"")
comm.sudo("sh -c \"gsed -i -e 's/\\(#{broadcasting_ip}\\s*\\).*/\\1#{name}/g' /etc/hosts\"")
comm.sudo("uname -S #{name}")
end
end
end
|