23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/vagrant-vmware-esxi/action/set_network_ip.rb', line 23
def set_network_ip(env)
@logger.info('vagrant-vmware-esxi, set_network_ip: start...')
@env = env
machine = env[:machine]
config = env[:machine].provider_config
if config.esxi_virtual_network.is_a? Array
number_of_adapters = config.esxi_virtual_network.count
else
number_of_adapters = 1
end
vm_network = []
env[:machine].config.vm.networks.each do |type, options|
next if type != :private_network && type != :public_network
next if vm_network.count >= number_of_adapters
vm_network << options
end
if (config.debug =~ %r{true}i)
puts "num adapters: #{number_of_adapters}, vm.network.count: #{vm_network.count}"
end
networks_to_configure = []
if (number_of_adapters > 1) and (vm_network.count > 0)
1.upto(number_of_adapters - 1) do |index|
if !vm_network[index - 1].nil?
options = vm_network[index - 1]
next if options[:auto_config] === false
if options[:ip]
ip_class = options[:ip].gsub(/\..*$/,'').to_i
if ip_class < 127
class_netmask = '255.0.0.0'
elsif ip_class > 127 and ip_class < 192
class_netmask = '255.255.0.0'
elsif ip_class >= 192 and ip_class <= 223
class_netmask = '255.255.255.0'
end
unless options[:netmask]
netmask = class_netmask
else
netmask = options[:netmask]
end
unless netmask =~ /^(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$/i
env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
message: "WARNING : Invalid netmask specified, using Class mask (#{class_netmask})")
netmask = class_netmask
end
network = {
interface: index,
type: :static,
use_dhcp_assigned_default_route: options[:use_dhcp_assigned_default_route],
guest_mac_address: options[:mac],
ip: options[:ip],
netmask: netmask,
gateway: options[:gateway]
}
ip_msg = options[:ip] + '/'
else
network = {
interface: index,
type: :dhcp,
use_dhcp_assigned_default_route: options[:use_dhcp_assigned_default_route],
guest_mac_address: options[:mac]
}
ip_msg = 'dhcp'
netmask = ''
end
networks_to_configure << network
env[:ui].info I18n.t('vagrant_vmware_esxi.vagrant_vmware_esxi_message',
message: "Configuring : #{ip_msg}#{netmask} on #{config.esxi_virtual_network[index]}")
end
end
sleep(1)
env[:machine].guest.capability(
:configure_networks, networks_to_configure)
end
end
|