This blog is meant to be a reference for users that are using LU (Live Updates) for AIX in combination with NIM.
Little background:
In 2021 I created a cookbook how to setup a working environment for Live Update using AIX – NIM.
https://community.ibm.com/community/user/power/blogs/christian-sonnemans1/2021/03/27/live-update-cookbook
Meanwhile we have learned a lot, and we noticed that it might be handy to switch form HMC if one is in maintenance. This because if LU is used in a NIM environment I can only attach to one HMC.
For a critical process like LU for updates you like redundancy of course! Therefore my college and I found a method that can be used to switch form HMC, in a NIM environment.
I like to share this useful information.
The second example script can also be used to update all the NIM objects after a LPM (Live partition Mobility) operation. After LPM NIM client are not updated and not working, after using the second example script you can update all the NIM object so that NIM operations will work again.
Step 1:
For every CEC in your environment that is served by a HMC you have to change it in the NIM object:
Later on I will provide a little script that does the complete trick for this.
To discover every CEC (NIM Object) you can run:
lsnim -t cec | awk '{print $1}’
For every CEC you have to replace the old HMC name into the new HMC that is not in maintenance.
You can do this by:
nim -o change -a mgmt_source=<new_HMC_Name> <CEC_Name>
Possible script to achieve this:
Script example 1:
#!/bin/ksh93
# script to show/swap the hmc for all machines on this NIM server
# be aware that after this script is run , it is required to have all NIM
# object for lpars to be reconfigured
hmc=$1
prog=$(basename $0)
echo "$prog: current config :"
for cec in $(lsnim -t cec | awk '{print $1}')
do
show_hmc=$(lsnim -l $cec | awk '$1=="hmc" {print $NF}')
echo "cec=$cec hmc=$show_hmc "
done
echo
if [[ "$1" = "" ]]
then echo "$prog: for config updates please provide one of these HMC names :"
lsnim -t hmc | awk '{print $1}'
exit 1
else
if lsnim -t hmc | grep -q $hmc
then :
else echo "$prog: invalid name=$hmc please provide one of these HMC names :"
lsnim -t hmc | awk '{print $1}'
exit 1
fi
fi
for cec in $(lsnim -t cec | awk '{print $1}')
do
if [[ $(lsnim -l $cec | awk '$1=="hmc" {print $NF}') = $hmc ]]
then echo "$prog: not update - mgmt_source for cec=$cec is already set to hmc=$hmc"
else echo "$prog: changing mgmt_source for cec=$cec to hmc=$hmc "
nim -o change -a mgmt_source=$hmc $cec
echo "$prog: IMportant ! you need to run the script update_nim_from_hmc which reconfigures all NIM lpar objects to use the new HMC"
fi
done
Step 2:
After switching from HMC into the NIM CEC objects this step must be done for every Lpar that are part of those CEC’s:
I will first explain this how this works, later on I will also provide a script that can be used as a working example.
For every Lpar there is of course also a NIM object called NIM client.
The object that must be changed is normaly not vissable with a command like lsnim -l <Lpar_name>
e.g. NIM client.
But it’s only visible with the command lsnim -Fl <Lpar_name>
Running this command will provide you with much more interesting output see example output below:
Lpar_name :
id = 1527665014
class = machines
type = standalone
connect = nimsh
default_profile = type=hmc,ip=xxx.xxx.xxx.xxx,passwd_file=/etc/nim/hmc_passwd:type=lpar,identity=13:type=cec,serial=9105-42A*12345678:
platform = chrp
netboot_kernel = 64
if1 = networkname Lpar_name 2AC4A23Cbbcc ent
cable_type1 = N/A
mgmt_profile1 = HMC1 13 cecname
Cstate = ready for a NIM operation
prev_state = customization is being performed
Mstate = currently running
cpuid = 00C581234567
Cstate_result = success
With this information Lpar Object you might think you can set the mgmt_profile1 stanza, however there is no way to set this stanza field, but we found out that you just have to change it via the following command:
nim -o change -a mgmt_source=<cec_name> -a identity=<Lpar_ID> <Lpar_name>
the last example script below can be used to do this for every Lpar.
Be aware this was tested in our environment PLEASE TEST this and check the results in our environment, it’s just meant as an example!
Hopefully this contribution to the community is helpful for other customers who have the same intention that we had, a easy way of switching form HMC when using LU in combination of NIM.
Any commends on this blog are appreciated
Example Script2:
#!/bin/ksh93
# script to update the NIM database machine (lpars) objects if we make changes that affect the "hidden" default profile part
#
# important:
# - this script is normally to be run after you have attached the managed servers (cec) to a different HMC
# some details about this script
# the reconfig is done on "hidden" attributes of lpars only visible with
# - e.g lsnim -Fl [nim_client]
#
# this can occur when there is:
# - a lpar mobility done
# - the machine CEC object is attached to a new HMC
# - the live update was done not via NIM
#
# the script does:
# take the machinelist and lpar info from the HMC
# finds all nim clients of type standalone and checks the following records for mismatches
# - the hmc ip address
# - the lpar ID
# - the machine MTM/serial
# on any of above mismatch a update cmd is formulated
#
# not updated when:
# - there is no CEC object what matches the MTM/serial
# - the lpar is not aixlinux (excludes vioservers)
# - there is no nimclient found
# - all records match current config
#
# oher notes:
# an update to NIM e.g nim -o change does not accept parameters like default_profile
# but satisfying results are available when re-apply the mgmt_source and identity attributes of the nim_client
#
# not supported at this moment:
# the script assumes that the lpar is managed by the hmc not powervc
# if PowerVC is used the script must be adapted
# - see this example , it has "type=hmc", i guess that will be replaced by some "type=powervc" setting then
# default_profile = type=hmc, etc.
#
#
ssh_cmd="ssh -q -o StrictHostKeyChecking=no"
ssh_user=<sshuser2hmc>
export DEBUG=n
prog=$(basename $0)
my_lpar=$(uname -L | awk '{print $2}')
let changes=0
case $my_lpar in
nimserver1) hmc=<HMC_1>
;;
Nimserver2) hmc=<HMC_2>
;;
*) exit 1
;;
esac
for machine in $($ssh_cmd $ssh_user@$hmc "lssyscfg -r sys -F name")
do
machine_data=$($ssh_cmd $ssh_user@$hmc "lssyscfg -r sys -m $machine -F type_model,serial_num")
hmc_model=$(echo ${machine_data} | awk -F, '{print $1}')
hmc_serial=$(echo ${machine_data} | awk -F, '{print $2}')
[[ $DEBUG = y ]] && echo DEBUG hmc_model=$hmc_model hmc_serial=$hmc_serial
# based on this data we can try to find the matching serial cec object in NIM
cec_name=
for cec in $(lsnim -t cec | awk '{print $1}')
do
cec_serial=$(lsnim -l $cec | awk '$1=="serial" {print $NF}')
if [[ "$cec_serial" = "${hmc_model}*${hmc_serial}" ]]
then cec_name=$cec
break
fi
done
if [[ "$cec_name" = "" ]]
then echo "$prog: cannot find the NIM cec_name for machine=$machine "
else
# we need configured hmc from cec
cec_hmc_name=$(lsnim -l $cec_name | awk '$1=="hmc" {print $NF}')
cec_hmc_ip=$(host $cec_hmc_name | awk '{print $3}' | cut -d, -f1)
[[ $DEBUG = y ]] && echo DEBUG cec_name=$cec_name cec_hmc_name=$cec_hmc_name cec_hmc_ip=$cec_hmc_ip
for lpar_data in $($ssh_cmd $ssh_user@$hmc "lssyscfg -r lpar -m $machine -F name,lpar_env,lpar_id")
do
lpar_name=$(echo ${lpar_data} | awk -F, '{print $1}')
lpar_env=$(echo ${lpar_data} | awk -F, '{print $2}')
lpar_id=$(echo ${lpar_data} | awk -F, '{print $3}')
[[ $DEBUG = y ]] && echo DEBUG lpar_name=$lpar_name lpar_env=$lpar_env lpar_id=$lpar_id
if [[ $lpar_env = aixlinux ]]
then
if lsnim -t standalone | awk '{print $1}' | grep -xq $lpar_name
then
# get default_profile_data from nim
if lsnim -Fl $lpar_name | awk '{print $1}' | grep -q default_profile
then
default_profile_data=$(lsnim -Fl $lpar_name | awk '$1=="default_profile" {print $NF}')
default_profile_type=$(echo $default_profile_data | awk -F, '{print $1}' | awk -F= '{print $NF}')
if [[ $default_profile_type != hmc ]]
then :
# managed by powervc maybe ?
else
# if we are managed by HMC do this
default_profile_hmc_ip=$(echo $default_profile_data | awk -F, '{print $2}' | awk -F= '{print $NF}')
default_profile_identity=$(echo $default_profile_data | awk -F, '{print $4}' | awk -F':' '{print $1}' | awk -F= '{print $NF}')
default_profile_serial=$(echo $default_profile_data | awk -F, '{print $5}' | awk -F= '{print $NF}' | awk -F':' '{print $1}')
[[ $DEBUG = y ]] && echo DEBUG default_profile_hmc_ip=$default_profile_hmc_ip default_profile_identity=$default_profile_identity default_profile_serial=$default_profile_serial
update=n
if [[ $default_profile_hmc_ip != $cec_hmc_ip ]]
then echo "$prog: mismatch cec_hmc_ip=$cec_hmc_ip default_profile_hmc_ip=$default_profile_hmc_ip lpar_name=$lpar_name"
update=y
fi
if [[ $default_profile_identity != $lpar_id ]]
then echo "$prog: mismatch default_profile_identity=$default_profile_identity and lpar_id=$lpar_id lpar_name=$lpar_name"
update=y
fi
if [[ "$default_profile_serial" != "${hmc_model}*${hmc_serial}" ]]
then echo "$prog: mismatch default_profile_serial="$default_profile_serial" and hmc_model*hmc_serial="${hmc_model}*${hmc_serial}" lpar_name=$lpar_name"
update=y
fi
# note : there is no method of setting the HMC ip except by just issue the nim -o change cmd below
if [[ "$update" = y ]]
then echo "$prog: NIM config needed nim_client=$lpar_name "
nim -o change -a mgmt_source=$cec_name -a identity=$lpar_id $lpar_name
let changes=$changes+1
else echo "$prog: NIM config for nim_client=$lpar_name does match HMC config -> ok"
fi
fi
else echo "$prog: $lpar_name nim object has no default_profile "
fi
else echo "$prog: there is no nimclient for lpar_name=$lpar_name"
fi
# else echo "$prog: the lpar_type for lpar_name=$lpar_name is not aixlinux"
fi
done
fi
done
if [[ $changes = 0 ]]
then echo "\n$prog: result: no changes to NIM were made "
else echo "\n$prog: result: $changes NIM objects were updated"
fi