Skip to content

NIM

Useful Commands

Verify NIM connectivity to all underlying AIX LPAR's

for srv in $(lsnim -t standalone | awk '{print $1}' | sort); do printf "%-20s" $srv; nim -o lslpp $srv >/dev/null 2>&1; [ "$?" == 0 ] && echo OK || echo "Problem";   done

Verify NIM connectivity to all underlying AIX LPAR's - List problem LPAR's only

for srv in $(lsnim -t standalone | awk '($1 ~ /<hostname_regex>/){ print $1 }' | sort); do if ! nim -o lslpp $srv >/dev/null 2>&1; then echo "$srv  Problem"; fi; done

Manually reset alloc_count to 0

/usr/lpp/bos.sysmgt/nim/methods/m_chattr -a alloc_count=0 <resource>

Change NIM master cpuid

/usr/lpp/bos.sysmgt/nim/methods/m_chattr -a cpuid=XXXXXXXX master

Show allocated resources

lsnim -a <resource>

Reset and deallocate resources from client

nim -Fo reset <client>
nim -Fo deallocate -a subclass=all <client>

Scripts

reset_nim_resource

This script takes NIM resources (matching the following regex '^7[12]00TL[0-9]+SP[0-9]+$') as input and;

  • resets the resource
  • sets the alloc_count to 0
  • resets the nim_script resource
  • unexports the NFS directory
  • remove the entry from /etc/exports
#!/bin/ksh
#
# Reset a nim resource
# Make sure script is run as root
if [[ "$(id -u)" -ne "0" ]]; then
  printf "%s\n" 'Can only be run as root'
  exit
fi
# Make sure an arguement (nim resource) has been provided
if [[ "$#" -eq 0 ]]; then
    printf "%s\n" 'No resource specified'
fi
# Reset allocation count
# Remove entry in /etc/exports
# Unexport NFS directory
for nimresource in "$@"; do
    if ! echo "${nimresource}" | grep -Eq '^7[12]00TL[0-9]+SP[0-9]+$'; then
        printf "%s\n" "${nimresource} incorrect format. Correct format example: 7200TL5SP1"
    else
        if lsnim aix"${nimresource}"_lpp > /dev/null 2>&1; then
            # Reset nim_script
            /usr/lpp/bos.sysmgt/nim/methods/m_chattr -a alloc_count=0 nim_script
            # Reset all matching nim resources
            for resource in $(lsnim | awk -v resource="${nimresource}" '$0~resource{ print $1 }'); do
                /usr/lpp/bos.sysmgt/nim/methods/m_chattr -a alloc_count=0 "${resource}"
            done
            # Remove entry from /etc/exports
            /opt/freeware/bin/sed -i "/${nimresource}/d" /etc/exports
            # Unexport NFS directory
            for export in $(showmount -e | awk -v resource="${nimresource}" '$0~resource{ print $1 }'); do
                exportfs -u "${export}" > /dev/null 2>&1
            done
            # Done
            printf "%s\n" "${nimresource} reset"
        else
            printf "%s\n" "${nimresource} not found"
        fi
    fi
done

reset_nim_client

This script takes the NIM client resource as input and;

  • resets the resource
  • deallocates any assigned resources
#!/bin/ksh
#
# Reset a nim client
# Make sure script is run as root
if [[ "$(id -u)" -ne "0" ]]; then
  printf "%s\n" 'Can only be run as root'
  exit
fi
# Make sure an arguement (nim client) has been provided
if [[ "$#" -eq 0 ]]; then
    printf "%s\n" 'No client specified'
fi
# Reset and deallocate nimclient
for nimclient in "$@"; do
    if ! lsnim "${nimclient}" > /dev/null 2>&1; then
        printf "%s\n" "${nimclient} is not managed by this NIM"
    else
        nim -Fo reset "${nimclient}"
        nim -Fo deallocate -a subclass=all "${nimclient}"
        printf "%s\n" "${nimclient} reset"
    fi
done