Skip to content

Commit

Permalink
NET-16: Name a NIC on a Compute Node
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Gulewich committed Mar 15, 2011
1 parent d664e25 commit b5375e0
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/sysinfo
Expand Up @@ -25,7 +25,7 @@ fi
# helper to set global "normalized" to the expanded version of MAC ($1)
function normalize_mac()
{
mac=$1
local mac=$1
if [ -z "${mac}" ]; then
echo "FATAL: unable to normalize empty mac!"
exit 1
Expand Down Expand Up @@ -167,6 +167,7 @@ function get_nic_mappings()
function get_network_interfaces()
{
count=1
nic_tag_count=1
# ignore 'LINK SLOT ADDRESS INUSE CLIENT' line
for line in $(pfexec /sbin/dladm show-phys -m | grep -v "^LINK " | awk '{ print $1,$3 }' | tr ' ' '='); do
nicnames=
Expand All @@ -191,6 +192,19 @@ function get_network_interfaces()
NIC_internal=${iface}
fi

for tag in "${NicTagsMacs[@]}"; do
tag_fields=(${tag//=/ })
tag_name=${tag_fields[0]}
normalize_mac ${tag_fields[1]}
tag_mac=${normalized}
if [[ "${tag_mac}" == "${mac}" ]]; then
[[ -n ${nicnames} ]] && nicnames="${nicnames},"
nicnames="${nicnames}${tag_name}"
NicTags[${nic_tag_count}]="${tag_name}=${iface}"
((nic_tag_count++))
fi
done

NetworkInterfaces[${count}]=${iface}
eval "Network_Interface_${iface}_MAC_Address=${mac}"
eval "Network_Interface_${iface}_IPv4_Address=${ip4addr}"
Expand All @@ -212,6 +226,19 @@ function get_network_interfaces()
#done
}

function get_nic_tags()
{
count=1
for line in $(/usr/bin/bootparams 2>/dev/null | grep "^[a-z0-9_]*_nic" ; grep "^[a-z0-9]*_nic" ${configfile} 2>/dev/null); do
fields=(${line//=/ })
key=${fields[0]}
if [[ $key != "admin_nic" ]] && [[ $key != "external_nic" ]] && [[ $key != "internal_nic" ]]; then
NicTagsMacs[${count}]=$(echo ${line} | sed -e 's/_nic//')
((count++))
fi
done
}

function get_bootparams()
{
count=1
Expand Down Expand Up @@ -265,6 +292,13 @@ END
[[ -n ${NIC_external} ]] && echo "NIC_external='${NIC_external}'"
[[ -n ${NIC_internal} ]] && echo "NIC_internal='${NIC_internal}'"

for tag in "${NicTags[@]}"; do
tag_fields=(${tag//=/ })
tag_name=${tag_fields[0]}
int=${tag_fields[1]}
echo "NIC_${tag_name}='${int}'"
done

for iface in "${NetworkInterfaces[@]}"; do
mac_var="Network_Interface_${iface}_MAC_Address"
ipv4_var="Network_Interface_${iface}_IPv4_Address"
Expand Down Expand Up @@ -370,6 +404,7 @@ get_live_image_buildstamp
get_disks
get_hostname
get_nic_mappings
get_nic_tags
get_network_interfaces
get_bootparams

Expand Down

0 comments on commit b5375e0

Please sign in to comment.