Skip to content

Commit

Permalink
Use network interface on index 0 as the gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Hanwen <[email protected]>
  • Loading branch information
hanwen-cluster committed Feb 1, 2024
1 parent 03e2857 commit e44df13
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,44 @@ def cidr_to_netmask(cidr)
end

# Configure nw interfaces
interfaces = []
gw_ip_address = ""
macs.each do |mac|
device_name = device_name(mac)
device_number = device_number(mac, token)
gw_ip_address = gateway_address
device_ip_address = device_ip(mac, token)
if "#{device_number}" == "0"
gw_ip_address = device_ip_address
end
cidr_prefix_length = cidr_prefix_length(mac, token)
netmask = cidr_to_netmask(cidr_prefix_length)
cidr_block = subnet_cidr_block(mac, token)
log "device_number: #{device_number}, device_name: #{device_name}, device_ip_address: #{device_ip_address}"
interfaces.append(
{
"device_name": device_name,
"device_number": device_number,
"device_ip_address": device_ip_address,
"cidr_prefix_length": cidr_prefix_length,
"netmask": netmask,
"cidr_block": cidr_block,
}
)
end
interfaces.each do |interface|
log "device_number: #{interface['device_number']}, device_name: #{interface['device_name']}, device_ip_address: #{interface['device_ip_address']}"

execute 'configure_nw_interface' do
user 'root'
group 'root'
cwd "/tmp"
environment(
'DEVICE_NAME' => device_name,
'DEVICE_NUMBER' => "#{device_number}",
'DEVICE_NAME' => interface['device_name'],
'DEVICE_NUMBER' => "#{interface['device_number']}",
'GW_IP_ADDRESS' => gw_ip_address,
'DEVICE_IP_ADDRESS' => device_ip_address,
'CIDR_PREFIX_LENGTH' => cidr_prefix_length,
'NETMASK' => netmask,
'CIDR_BLOCK' => cidr_block
'DEVICE_IP_ADDRESS' => interface['device_ip_address'],
'CIDR_PREFIX_LENGTH' => interface['cidr_prefix_length'],
'NETMASK' => interface['netmask'],
'CIDR_BLOCK' => interface['cidr_block']
)

command 'sh /tmp/configure_nw_interface.sh'
Expand Down

0 comments on commit e44df13

Please sign in to comment.