#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2019,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # @(#) 7d4c34b 43haes/usr/sbin/cluster/events/utils/clnovacmd.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM ######################################################################### # # COMPONENT_NAME: hacmp.events # # FUNCTIONS: # # usage # parse_cmd_line # format_list # get_nova_param # check_partition # check_managed_system # get_shared_processor_pool # get_local_partition # sort_and_output # execute_query_cmds # gather_and_convert # novacmdexec # clnovaexec # process_change # process_query # process_acquire # process_release # process_halt # ######################################################################### #================================================ # The following, commented line enforces coding # standards when this file is edited via vim. #================================================ # vim:tabstop=4:shiftwidth=4:expandtab:smarttab #================================================ #============================================================================= # # NAME # clnovacmd - perform NovaLink commands on cluster ROHA resources # # SYNOPSIS # To query configuration information for LPAR/Managed System/etc: # clnovacmd -o query -a {ALL|GEN|PROC|MEM|NOVA|CEC|LPAR|SPP|} # [-M ] [-L ] [-h] [-H ] # # To change configuration parameter: # clnovacmd -o change -a "attr_name1=value:attr_name2=value:..." [-H ] # # To acquire/release DLPAR resources: # clnovacmd -o {acquire|release} [-f] -r {dlpar} [-m ] [-p ] # [-q ] [-d ] [-t ] [-H ] # # To halt current partition: # clnovacmd -o halt [-L ] [-H ] # # DESCRIPTION # This clnovacmd command line interfaces NovaLink to perform NovaLink commands for the # account of PowerHA SystemMirror 'Resource Optimized High Availability' # (ROHA) functionality. # # This clnovacmd command line is the common pipe for PowerHA SystemMirror to # interface NovaLinks. # # This clnovacmd command line can run on any node of the cluster. # # PowerHA SystemMirror configuration must be done as far as NovaLinks are concerned: # - NovaLinks have to be configured at the node level. # # This clnovacmd command line encapsulates with ssh all commands run on NovaLink, # but the ssh link has to be properly configured first. # # This clnovacmd command line encapsulates a retry mechanism in case of repeated failure. # # This clnovacmd command line translates applicative level request to commands # comprehensible by the NovaLink, taking into account the version of NovaLink, and is # able to perform the following types of operations: # - Query operation on configuration attributes. # - Change operation on configuration attributes. # - Allocation of memory and processor DLPAR resources (in shared and dedicated processing modes). # - Release of memory and processor DLPAR resources (in shared and dedicated processing modes). # - Administrative actions on CEC to immediately halt LPARs. # Note: Currently novalink doesn't support On/Off CoD and EPCoD, You will have to use HMC for these operations. # # OPTIONS # -a The colon-separated list of attributes. Only valid and mandatory with # -o {query|change} option. # Valid values for -o query option are: # nova_list, nova_version. # local_sys_name, sys_name, # sys_lpar_names, sys_state, # sys_type_model, cod_mem_capable, # cod_proc_capable, mem_region_size, # installed_sys_mem, configurable_sys_mem, # sys_firmware_mem, curr_avail_sys_mem, # curr_free_sys_mem, deconfig_sys_mem, # installed_sys_proc_units, deconfig_sys_proc_units, # configurable_sys_proc_units, curr_avail_sys_proc_units, # curr_free_sys_proc_units, min_proc_units_per_virtual_proc. # local_lpar_name, lpar_name, # lpar_id, uuid, # lpar_state, curr_proc_mode, # lpar_avail_priority, curr_mem, # curr_min_mem, curr_min_procs, # curr_max_mem, curr_max_procs, # curr_procs, curr_proc_units, # curr_min_proc_units, curr_shared_proc_pool_name. # curr_max_proc_units, prof_name, # local_prof_name, prof_sharing_mode, # prof_proc_mode, prof_minimum_procs, # prof_shared_procpool, prof_maximum_procs, # prof_desired_procs, prof_desired_proc_units, # prof_minimum_proc_units, prof_minimum_mem, # prof_maximum_prof_units, prof_maximum_mem. # prof_desired_mem, procpool_name, # local_procpool_name, curr_free_pool_proc_units, # max_pool_proc_units, curr_reserved_pool_proc_units, # curr_profile, sys_mtms_str # # Valid values for -o change option are: # max_pool_proc_units reserved_pool_proc_units # -f Force allocation/release of resources to the best effort even if failure. # -h Display help usage. # -H The space-separated list of NovaLinks to interrogate. # -l Display labels. # -L The LPAR name. May be specified if information from another LPAR # than the one on which the command is issued are needed. # -m The amount of memory (in MBytes). Only valid with -o acquire and -o release. # -M The Managed System name. May be specified if information from another Managed System # than the one the LPAR belongs to are needed. # -o The operation to perform. Valid values are query, change, acquire and release. # The query operation displays information about configuration by # interrogating the first NovaLinks in the list. Option -a is mandatory. # The change operation sets attributes to new values. Option -a is # mandatory. # The acquire operation tries to allocate/activate/acquire/ resources for the account # of the LPAR. If no -m, -p or -q option are set, acquire all possible # resources. # The release operation tries to release resources for the account of # the LPAR. If no -m, -p or -q option is set, release all possible # resources. # The halt operation tries to immediately shutdown the LPAR. # -p The decimal number of processing units. Only valid with -o acquire and -o release. # -P The profile name. May be specified if information from another profile than # the one on which the command is issued are needed. # -q The number of processors. Only valid with -o acquire and -o release. # -r The type of resources. Only valid and mandatory with -o acquire and -o release. # Valid values are dlpar for Dynamic LPAR resources. # -s Safe option to tell that no check is to be done on parameter. # -S The shared processor pool name. May be specified if information from another # shared processor pool than the one the partition belongs to are needed. # # EXIT STATUS # This command has the following return codes: # 0 Success # 1 Error - Wrong parameter # 2 Error - Last NovaLink tried cannot be pinged # 3 Error - Remote command cannot be ssh'ed on the last NovaLink tried # 4 Error - Remote command returned a resource busy error on the last NovaLink tried # 5 Error - Remote command returned a managed system busy error on the last NovaLink tried # 6 Error - Remote command returned a not enough resources error on the last NovaLink tried # 7 Error - Remote command returned an other type of error on the last NovaLink tried # # EXAMPLES # To query multiple configuration information: # # To query all configuration information with labels: # clnovacmd -o query -a ALL -l # # To query multiple configuration information for a specific Managed System: # clnovacmd -o query -a sys_state:sys_type_model -M 3node-9117-MMB-100082P # # To change maximum size of shared processor pool: # clnovacmd -o change -a "max_pool_proc_units=8.5" # # To allocate 9.75 GBytes of memory, 2.2 processing units and 4 virtual CPUs of DLPAR resources: # clnovacmd -o acquire -m 9984 -p 2.2 -q 4 -r dlpar # # To release 100 GBytes of DLPAR memory resources with a 50 minutes timeout: # clnovacmd -o release -m 102400 -r dlpar -t 50 # # To shutdown current partition: # clnovacmd -o halt # #============================================================================= #####################################Functions start#################################### #============================================================================= # # Name: usage # # Description: Prints usage. # # Arguments: None # # Returns: None # #============================================================================= function usage { printf "%s: Usage:\n" "$PROGNAME" printf "\tclnovacmd -o query -a {ALL|GEN|PROC|MEM|NOVA|CEC|LPAR|PROF|SPP|} [-l] [-H ] [-M ] [-L ] [-P ] [-S ]\n" printf "\tclnovacmd -o change -a \"attr_name1=value:attr_name2=value:...\" [-H ]\n" printf "\tclnovacmd -o {acquire|release} [-f] -r {dlpar} [-m ] [-p ] [-q ] [-d ] [-t ] [-H ]\n" printf "\tclnovacmd -o halt [-L ] [-H ]\n" printf "\n" printf "Note: -m must be passed in MB, 1GB=1024MB.\n" printf "Note: verbose output is shown by setting VERBOSE_LOGGING=high.\n" printf "Note: to display output messages, run clnovacmd with \" 3>&2\"" } # End of "usage()" #============================================================================= # # Name: parse_cmd_line # # Description: Parse and check the command line arguments. # # Arguments: $@ [IN] list of arguments # # Environment: g_attributes # g_nova_list # g_labels # g_partition # g_memory # g_managed_system # g_operation # g_proc_units # g_profile # g_quantity # g_resource # g_shared_proc_pool # # Returns: RC_SUCCESS # RC_PARAM_ERROR # #============================================================================= function parse_cmd_line { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS #======================================================= # Get options #======================================================= while getopts ":a:fhH:lL:m:M:o:p:P:q:r:sS:" opt ; do case $opt in a) g_attributes=$OPTARG ;; # attributes to list f) g_force=1 ;; # force allocation/release h) usage ; exit $RC_SUCCESS ;; # usage H) if [[ -z $g_nova_list ]] ; then # list of NovaLinks g_nova_list=${g_nova_list:+${g_nova_list} }${OPTARG//[,:]/ } fi ;; l) g_labels=1 ;; # display labels L) g_partition=$OPTARG ;; # partition name m) g_memory=$OPTARG ;; # MBytes of memory M) g_managed_system=$OPTARG ;; # managed system name o) g_operation=$OPTARG ;; # operation {query|change|acquire|release} p) g_proc_units=$OPTARG ;; # processing units for shared proc LPARs P) g_profile=$OPTARG ;; # profile name q) g_quantity=$OPTARG ;; # quantity of CPUs r) g_resource=$OPTARG ;; # resource type {dlpar} s) g_safe_option=1 ;; S) g_shared_proc_pool=$OPTARG ;; # shared processor pool name \?) dspmsg $ROHA_MSGS -s $ROHA_SET 400 \ "%1\$s: ERROR: unknown -%2\$s parameter.\n" \ "$PROGNAME" "$OPTARG" >&3 exit $RC_PARAM_ERROR ;; :) dspmsg $ROHA_MSGS -s $ROHA_SET 401 \ "%1\$s: ERROR: -%2\$s option requires an argument.\n" \ "$PROGNAME" "$OPTARG" >&3 exit $RC_PARAM_ERROR ;; esac done #======================================================= # Check operation #======================================================= if [[ -z $g_operation ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 402 \ "%1\$s: ERROR: missing operation.\n" \ "$PROGNAME" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 404 \ "\tSupported operations for -o flag are: %1\$s.\n" \ "$OPERATION_LIST" >&3 exit $RC_PARAM_ERROR fi case $g_operation in q*) #======================================================= # Check query options #======================================================= g_operation="query" if [[ -z $g_attributes ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 405 \ "%1\$s: ERROR: missing attribute for %2\$s operation.\n" \ "$PROGNAME" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 407 \ "\tSupported attributes for -a flag are:\n%1\$s\n" \ "$(format_list "$QUERY_ATTR_LIST")" >&3 exit $RC_PARAM_ERROR fi for attribute in ${g_attributes//:/ } ; do #======================================================= # Convert generic g_attributes #======================================================= case $attribute in ALL) g_attributes=${g_attributes/ALL/${QUERY_ATTR_LIST// /:}} ;; NOVA) g_attributes=${g_attributes/NOVA/${NOVA_ATTRS// /:}} ;; CEC) g_attributes=${g_attributes/CEC/${MANAGED_SYSTEM_ATTRS// /:}} ;; LPAR) g_attributes=${g_attributes/LPAR/${PARTITION_ATTRS// /:}} ;; PROF) g_attributes=${g_attributes/PROF/${PROFILE_ATTRS// /:}} ;; SPP) g_attributes=${g_attributes/SPP/${SHARED_PROC_POOL_ATTRS// /:}} ;; GEN) g_attributes=${g_attributes/GEN/${GENERAL_ATTRS// /:}} ;; PROC) g_attributes=${g_attributes/PROC/${PROCESSOR_ATTRS// /:}} ;; MEM) g_attributes=${g_attributes/MEM/${MEMORY_ATTRS// /:}} ;; AVAIL) g_attributes=${g_attributes/AVAIL/${AVAIL_ATTRS// /:}} ;; CURRENT) g_attributes=${g_attributes/CURRENT/${CURRENT_ATTRS// /:}} ;; *) if [[ $attribute != @(${QUERY_ATTR_LIST// /\|}) ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 406 \ "%1\$s: ERROR: unsupported %2\$s attribute for %3\$s operation.\n" \ "$PROGNAME" "$attribute" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 407 \ "\tSupported attributes for -a flag are:\n%1\$s\n" \ "$(format_list "$QUERY_ATTR_LIST")" >&3 exit $RC_PARAM_ERROR fi esac done ;; c*) #======================================================= # Check change options #======================================================= g_operation="change" if [[ -z $g_attributes ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 405 \ "%1\$s: ERROR: missing attribute for %2\$s operation.\n" \ "$PROGNAME" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 407 \ "\tSupported attributes for -a flag are:\n%1\$s\n" \ "$(format_list "$CHANGE_ATTR_LIST")" >&3 exit $RC_PARAM_ERROR fi for attribute in ${g_attributes//:/ } ; do print -- $attribute | IFS='=' read key value if [[ $key != @(${CHANGE_ATTR_LIST// /\|}) ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 406 \ "%1\$s: ERROR: unsupported %2\$s attribute for %3\$s operation.\n" \ "$PROGNAME" "$key" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 407 \ "\tSupported attributes for -a flag are:\n%1\$s\n" \ "$(format_list "$CHANGE_ATTR_LIST")" >&3 exit $RC_PARAM_ERROR fi done ;; a*) #======================================================= # Check acquire options #======================================================= g_operation="acquire" if [[ -z $g_resource ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 408 \ "%1\$s: ERROR: missing resource type for %2\$s operation.\n" \ "$PROGNAME" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 410 \ "\tSupported resource types for -r flag are: %1\$s.\n" \ "$RESOURCE_LIST" >&3 exit $RC_PARAM_ERROR fi if [[ $g_resource != dlpar ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 409 \ "%1\$s: ERROR: unsupported %2\$s resource type for %3\$s operation.\n" \ "$PROGNAME" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 410 \ "\tSupported resource types for -r flag are: %1\$s.\n" \ "$RESOURCE_LIST" >&3 exit $RC_PARAM_ERROR fi if (( $g_memory == 0 && $g_quantity == 0 && $g_proc_units == 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 411 \ "%1\$s: ERROR: missing resource quantity for %2\$s operation. Provide -m, -q or -p option.\n" \ "$PROGNAME" "$g_operation" >&3 exit $RC_PARAM_ERROR fi ;; r*) #======================================================= # Check release options #======================================================= g_operation="release" if [[ -z $g_resource ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 408 \ "%1\$s: ERROR: missing resource type for %2\$s operation.\n" \ "$PROGNAME" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 410 \ "\tSupported resource types for -r flag are: %1\$s.\n" \ "$RESOURCE_LIST" >&3 exit $RC_PARAM_ERROR fi if [[ $g_resource != dlpar ]] ; then dspmsg $ROHA_MSGS -s $ROHA_SET 409 \ "%1\$s: ERROR: unsupported %2\$s resource type for %3\$s operation.\n" \ "$PROGNAME" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 410 \ "\tSupported resource types for -r flag are: %1\$s.\n" \ "$RESOURCE_LIST" >&3 exit $RC_PARAM_ERROR fi if (( $g_memory == 0 && $g_quantity == 0 && $g_proc_units == 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 411 \ "%1\$s: ERROR: missing resource quantity for %2\$s operation. Provide -m, -q or -p option.\n" \ "$PROGNAME" "$g_operation" >&3 exit $RC_PARAM_ERROR fi ;; h*) #======================================================= # Check halt options #======================================================= g_operation="halt" ;; *) dspmsg $ROHA_MSGS -s $ROHA_SET 403 \ "%1\$s: ERROR: unsupported %2\$s operation.\n" \ "$PROGNAME" "$g_operation" >&3 dspmsg $ROHA_MSGS -s $ROHA_SET 404 \ "\tSupported operations for -o flag are: %1\$s.\n" \ "$OPERATION_LIST" >&3 exit $RC_PARAM_ERROR esac #======================================================= # Check Nova list & partition #======================================================= if [[ -n $g_nova_list ]] ; then if [[ -n $g_partition ]] ; then if (( g_safe_option == 0)); then check_partition $g_partition if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_partition" >&3 exit $RC_PARAM_ERROR fi fi else get_local_partition g_local_partition if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_local_partition" >&3 exit $RC_PARAM_ERROR fi fi else #======================================================= # cl_get_nova_list needs a node name as argument. #======================================================= if [[ -n $g_partition ]] ; then #======================================================= # nodename/lparname match and nodename/cecname match are # stored into HACMPdynresop ODM # We use cl_dynresop to retrieve match between lparname # and nodename into HACMPdynresop ODM #======================================================= nodename=$(LC_ALL=C cl_dynresop -l $g_partition -N) rc=$? if (( rc != 0 )) || [[ -z $nodename ]] ; then # : best can do, nodename is set to g_partition $g_partition # nodename=$g_partition rc=$RC_SUCCESS fi g_nova_list=$(cl_get_nova_list -n $nodename) if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 525 \ "%1\$s: ERROR: no list of NovaLink defined for %2\$s node. Provide -H option.\n" \ "$PROGNAME" "$nodename" >&3 exit $RC_PARAM_ERROR fi check_partition $g_partition if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_partition" >&3 exit $RC_PARAM_ERROR fi else get_local_partition g_local_partition if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_local_partition" >&3 exit $RC_PARAM_ERROR fi g_nova_list=$(cl_get_nova_list) if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 413 \ "%1\$s: ERROR: no list of NovaLink defined for %2\$s node. Provide -H option.\n" \ "$PROGNAME" "$(get_local_nodename)" >&3 exit $RC_PARAM_ERROR fi fi fi #======================================================= # Check managed system #======================================================= if [[ -n $g_managed_system ]] ; then check_managed_system $g_managed_system if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 416 \ "%1\$s: ERROR: unknown %2\$s Managed System. Provide valid name through -M option.\n" \ "$PROGNAME" "$g_managed_system" >&3 exit $RC_PARAM_ERROR fi fi #======================================================= # Check shared processor pool #======================================================= typeset spp_name="" if [[ -n $g_shared_proc_pool ]] ; then if [[ -n $g_partition ]] ; then if (( g_safe_option == 0 )); then get_shared_processor_pool $g_partition spp_name if (( $? == 0 )) && [[ $spp_name != $g_shared_proc_pool ]]; then dspmsg $ROHA_MSGS -s $ROHA_SET 418 \ "%1\$s: ERROR: unknown %2\$s Shared Processor Pool for %3\$s LPAR. Provide valid name through -S option.\n" \ "$PROGNAME" "$g_shared_proc_pool" "$g_partition" >&3 exit $RC_PARAM_ERROR fi fi else get_local_partition g_local_partition if (( $? > 0 )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_local_partition" >&3 exit $RC_PARAM_ERROR fi get_shared_processor_pool $g_partition spp_name if (( $? == 0 )) && [[ $spp_name != $g_shared_proc_pool ]]; then dspmsg $ROHA_MSGS -s $ROHA_SET 418 \ "%1\$s: ERROR: unknown %2\$s Shared Processor Pool for %3\$s LPAR. Provide valid name through -S option.\n" \ "$PROGNAME" "$g_shared_proc_pool" "$g_partition" >&3 exit $RC_PARAM_ERROR fi fi fi return $rc } # End of "parse_cmd_line()" #============================================================================= # # Name: format_list # # Description: Prints format_list. # # Arguments: $1 [IN] list of elements # # Returns: None # #============================================================================= function format_list { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset list=$1 list="$(print "${list// /\\n}" | sort -u)" print $list | read -A array for (( i=0; i<${#array[@]}; i+=2 )) ; do printf "\t%-32s %-32s\n" "${array[$i]}" "${array[$((i+1))]}" done } # End of "format_list()" #============================================================================= # # Name: get_nova_param # # Description: Obtain NovaLink parameter by looking into HACMPnova ODM object. # if not found or default is set, look into HACMPnovaparam ODM # object. Otherwise set to default value. # # Arguments: $1 [INOUT] - output_value reference to the parameter # $2 [IN] - nova NovaLink to get parameter from # $3 [IN] - attribute name of the NovaLink parameter to set # $4 [IN] - default_value default value to be set # # Environment: None # # Returns: RC_SUCCESS # #============================================================================= function get_nova_param { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset -n output_value=$1 typeset nova=$2 typeset attribute=$3 typeset -i default_value=$4 #======================================================= : First, look into HACMPnova ODM. #======================================================= output_value=$(clodmget -q name=$nova -f $attribute -n HACMPnova 2>/dev/null) rc=$? if (( $rc > 0 || output_value == -1 || output_value == 0 )) ; then #========================================================================== : Then, look into HACMPnovaparam ODM, : which stores the default for all NovaLinks. #========================================================================== output_value=$(clodmget -f default_$attribute -n HACMPnovaparam 2>/dev/null) rc=$? if (( $rc > 0 || output_value == 0 )) ; then #======================================================= : Then, set to default value received in parameter. #======================================================= output_value=$default_value rc=$RC_SUCCESS fi fi return $rc } # End of "get_nova_param()" #============================================================================= # # Name: check_partition # # Description: Check partition name by asking NovaLink. # # Arguments: $1 [IN] lpar_name - partition name to check for. # # Returns: RC_SUCCESS # RC_FAILURE # #============================================================================= function check_partition { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset lpar_name=$1 typeset lpar_name_ref="" [[ -z $lpar_name ]] && get_local_partition lpar_name # : Retrieve complete lpar_name_ref $lpar_name_ref against NovaLink # clnovaexec "pvmctl lpar list -i name=$lpar_name -d LogicalPartition.name --hide-label" lpar_name_ref if (( $? == 0 )) ; then # : Check lpar_name $lpar_name against NovaLink # if [[ $lpar_name != $lpar_name_ref ]] ; then rc=$RC_FAILURE fi fi return $rc } # End of "check_partition()" #============================================================================= # # Name: check_managed_system # # Description: Check managed system name by asking NovaLink. # # Arguments: $1 [IN] sys_name - managed system name to check for. # # Returns: RC_SUCCESS # RC_FAILURE # #============================================================================= function check_managed_system { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset sys_name=$1 #======================================================= : Check managed system name #======================================================= clnovaexec "pvmctl sys list --hide-label -d system_name" res rc=$? if (( $rc > 0 )) || [[ $res != $sys_name ]] ; then #Check if managed system name argument is passed as MachineType-Model-SerialNumber string format clnovaexec "pvmctl sys list --hide-label -d mtms_str" res rc=$? if (( $rc > 0 )) || [[ $res != $sys_name ]] ; then rc=$RC_FAILURE fi fi return $rc } # End of "check_managed_system()" #======================================================================================= # # Name: get_shared_processor_pool # # Description: Obtain shared processor pool name. The name is gotten from the # NovaLink, or default to null. # # Arguments: $1 [IN] lpar_name - partition name to search shared processor pool for. # $2 [INOUT] spp_name - reference to the shared processor pool name. # # Returns: RC_SUCCESS # RC_FAILURE # #======================================================================================= function get_shared_processor_pool { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_FAILURE typeset lpar_name=$1 typeset -n spp_name=$2 typeset spp_id="" #======================================================= : Check shared processor pool name #======================================================= if [[ -n $lpar_name ]] ; then clnovaexec "pvmctl lpar list --hide-label -i name=$lpar_name -d SharedProcessorConfiguration.pool_id" spp_id if (( $? == 0 )) && [[ -n $spp_id ]]; then clnovaexec "pvmctl spp list --hide-label --where SharedProcessorPool.id=$spp_id -d SharedProcessorPool.name" spp_name if (( $? == 0 )) && [[ -n $spp_name && $spp_name != "null" ]]; then rc=$RC_SUCCESS fi fi fi return $rc } # End of "get_shared_processor_pool()" #============================================================================= # # Name: get_local_partition # # Description: Obtain local partition name. The partition name is got from # 'uname -L'. # # Arguments: $1 [INOUT] lpar_name - reference to the local partition name. # # Environment: HOSTNAME # # Returns: RC_SUCCESS # RC_FAILURE # #============================================================================= function get_local_partition { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset -n lpar_name=$1 if [[ -z $lpar_name ]] ; then #======================================================= : It refers to this one. Get it from uname. #======================================================= lpar_name=$(uname -L | cut -d \ -f2 2>/dev/null) if [[ -z $lpar_name ]] ; then #======================================================= : If failed, return failure. #======================================================= rc=$RC_FAILURE fi fi return $rc } # End of "get_local_partition()" #============================================================================= # # Name: sort_and_output # # Description: Sort results from novalink commands to match input order of # attributes. # # Arguments: $1 [IN] res - reference to the array of results for each command. # $2 [IN] list_in - space-separated list of attributes. # $3 [INOUT] list_out - colon-separated list of value for each attributes. # # Environment: g_partition # g_managed_system # g_local_partition # g_local_profile # # Returns: RC_SUCCESS # #============================================================================= function sort_and_output { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset -n res=$1 typeset list_in=$2 typeset -n list_out=$3 typeset -i cec_info_idx=0 typeset -i lpar_info_idx=0 typeset -i lpar_procpool_idx=0 for attr in $list_in ; do case $attr in #======================================================= # 0. local #======================================================= nova_list) if [[ -n $g_nova_list ]] ; then nova_list=$g_nova_list else nova_list=$(cl_get_nova_list) g_nova_list=$nova_list fi list_out=${list_out:+"$list_out:"}${nova_list:-unknown} ;; nova_version) clnovaexec "pvmctl --version" nova_version nova_version=$(print "$nova_version" | cut -d - -f 1) list_out=${list_out:+"$list_out:"}${nova_version:-unknown} ;; local_lpar_name) [[ -z $g_local_partition ]] && get_local_partition g_local_partition list_out=${list_out:+"$list_out:"}${g_local_partition:-unknown} ;; local_procpool_name) [[ -z $g_shared_proc_pool ]] && [[ -z $g_local_partition ]] && get_local_partition g_local_partition if [[ -n $g_local_partition ]] ; then get_shared_processor_pool $g_local_partition g_shared_proc_pool fi list_out=${list_out:+"$list_out:"}${g_shared_proc_pool:-unknown} ;; #============================================================================== # 1. cec_info (pvmctl sys list --hide-label --field-delim=: -d ${cmd.cec_info}) #============================================================================== local_sys_name|sys_name|sys_state|sys_type_model|sys_mtms_str|mem_region_size \ |installed_sys_mem|configurable_sys_mem|sys_firmware_mem|curr_avail_sys_mem \ |installed_sys_proc_units|configurable_sys_proc_units|curr_avail_sys_proc_units \ |deconfig_sys_mem|deconfig_sys_proc_units|curr_free_sys_mem|curr_free_sys_proc_units \ |min_proc_units_per_virtual_proc) print "${res.cec_info}" | IFS=: read -A tab list_out=${list_out:+"$list_out:"}${tab[$cec_info_idx]} (( cec_info_idx += 1 )) ;; sys_lpar_names) clnovaexec "pvmctl lpar list --hide-label -d name" sys_lpar_names sys_lpar_names=$(print $sys_lpar_names|wc -w) list_out=${list_out:+"$list_out:"}${sys_lpar_names:-unknown} ;; #====================================================================================================== # 4. lpar_info (pvmctl lpar list --hide-label --field-delim=: -i name=$g_partition -d ${cmd.lpar_info}) #====================================================================================================== lpar_name|lpar_id|uuid|lpar_state|lpar_avail_priority \ |prof_sharing_mode|prof_minimum_mem|prof_minimum_procs \ |prof_minimum_proc_units|prof_desired_mem|prof_desired_procs|prof_desired_proc_units \ |prof_maximum_mem|prof_maximum_procs|prof_maximum_proc_units \ |curr_min_mem|curr_mem|curr_max_mem \ |curr_min_procs|curr_procs|curr_max_procs|curr_min_proc_units \ |curr_proc_units|curr_max_proc_units) print "${res.lpar_info}" | IFS=: read -A tab list_out=${list_out:+"$list_out:"}${tab[$lpar_info_idx]} (( lpar_info_idx += 1 )) ;; #====================================================================================================== # lpar_procpool (pvmctl spp list --hide-label --field-delim=: -i name=$g_shared_proc_pool -d ${cmd.lpar_procpool}) #====================================================================================================== curr_shared_proc_pool_name|procpool_name|max_pool_proc_units|curr_reserved_pool_proc_units) print "${res.lpar_procpool}" | IFS=: read -A tab list_out=${list_out:+"$list_out:"}${tab[$lpar_procpool_idx]} (( lpar_procpool_idx += 1 )) ;; prof_proc_mode|curr_proc_mode) print "${res.lpar_info}" | IFS=: read -A tab if [[ ${tab[$lpar_info_idx]} == True ]] ; then list_out=${list_out:+"$list_out:"}"ded" elif [[ ${tab[$lpar_info_idx]} == False ]] ; then list_out=${list_out:+"$list_out:"}"shared" else list_out=${list_out:+"$list_out:"}"unknown" fi (( lpar_info_idx += 1 )) ;; *) list_out=${list_out:+"$list_out:"}"unknown" ;; esac done return $RC_SUCCESS } # End of "sort_and_output()" #============================================================================= # # Name: execute_query_cmds # # Description: Execute sequentially at most 14 NovaLink commands, if needed among # 'pvmctl'. If the command # can not be issued or returns an error, the corresponding # attributes are default to null and the function succeeds. # # Arguments: $1 [IN] cmds - reference to the array of attributes for each command. # $2 [INOUT] res - reference to the array of results for each command. # # Environment: g_partition # g_managed_system # g_profile # g_shared_proc_pool # # Returns: RC_SUCCESS # #============================================================================= function execute_query_cmds { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset -n cmd=$1 typeset -n res=$2 typeset attrs_list= list_out= #======================================================= # This function sets all fields from input to unknown. # It has to be defined as func() to allow compound # variable res.xxx to be known inside this embedded # function, or else a 'no parent' error will occur. #======================================================= fill_with_unknown() { typeset -n out=$2 for attr in ${1//:/ } ; do out=${out:+"$out:"}"unknown" done } # End of "fill_with_unknown()" #======================================================= # 1. cec_info #======================================================= if [[ -n ${cmd.cec_info} ]] ; then clnovaexec "pvmctl sys list --hide-label --field-delim=: -d ${cmd.cec_info}" list_out rc=$? if (( rc > 0 )) ; then fill_with_unknown ${cmd.cec_info} res.cec_info else res.cec_info=$list_out fi fi #======================================================= # 4. lpar_info #======================================================= if [[ -n ${cmd.lpar_info} ]] ; then [[ -z $g_partition ]] && get_local_partition g_partition if [[ -z $g_partition ]] ; then fill_with_unknown ${cmd.lpar_info} res.lpar_info else clnovaexec "pvmctl lpar list --hide-label --field-delim=: -i name=$g_partition -d ${cmd.lpar_info}" list_out rc=$? if (( rc > 0 )) ; then fill_with_unknown ${cmd.lpar_info} res.lpar_info else res.lpar_info=$list_out fi fi fi #======================================================= # 8. lpar_procpool #======================================================= if [[ -n ${cmd.lpar_procpool} ]] ; then if [[ -z $g_shared_proc_pool ]] ; then [[ -z $g_partition ]] && get_local_partition g_partition [[ -n $g_partition ]] && get_shared_processor_pool $g_partition g_shared_proc_pool fi if [[ -z $g_shared_proc_pool ]] ; then fill_with_unknown ${cmd.lpar_procpool} res.lpar_procpool else clnovaexec "pvmctl spp list --hide-label --field-delim=: -i name=$g_shared_proc_pool -d ${cmd.lpar_procpool}" list_out rc=$? if (( rc > 0 )) ; then fill_with_unknown ${cmd.lpar_procpool} res.lpar_procpool else res.lpar_procpool=$list_out fi fi fi return $RC_SUCCESS } # End of "execute_query_cmds()" #============================================================================= # # Name: gather_and_convert # # Description: Gather together attributes that should be executed by the same # NovaLink command. Also convert attributes to be NovaLink compatible. # # Arguments: $1 [IN] attrs - space-separated list of attributes. # $2 [INOUT] cmds - reference to the array of attributes for each command. # # Environment: g_convtabnova # # Returns: RC_SUCCESS # #============================================================================= function gather_and_convert { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset attrs=$1 typeset -n cmds=$2 for attr in $attrs ; do case $attr in #=========================================================================== # cec_info (pvmctl sys list --hide-label --field-delim=: -d ${cmd.cec_info}) #=========================================================================== local_sys_name|sys_name|sys_state|sys_type_model|sys_mtms_str|mem_region_size \ |installed_sys_mem|configurable_sys_mem|sys_firmware_mem|curr_avail_sys_mem \ |installed_sys_proc_units|configurable_sys_proc_units|curr_avail_sys_proc_units \ |deconfig_sys_mem|deconfig_sys_proc_units|min_proc_units_per_virtual_proc \ |curr_free_sys_mem|curr_free_sys_proc_units) cmds.cec_info=${cmds.cec_info:+"${cmds.cec_info} "}${g_convtabnova[$attr]} ;; #=================================================================================================== # lpar_info (pvmctl lpar list --hide-label --field-delim=: -i name=$g_partition -d ${cmd.lpar_info}) #=================================================================================================== lpar_name|lpar_id|uuid|lpar_state|lpar_avail_priority \ |prof_proc_mode|prof_sharing_mode|prof_minimum_mem \ |prof_minimum_proc_units|prof_desired_mem|prof_minimum_procs \ |prof_desired_procs|prof_maximum_procs|prof_desired_proc_units \ |prof_maximum_mem|prof_maximum_proc_units \ |curr_min_mem|curr_mem|curr_max_mem|curr_min_procs|curr_procs|curr_max_procs \ |curr_proc_mode|curr_min_proc_units \ |curr_proc_units|curr_max_proc_units) cmds.lpar_info=${cmds.lpar_info:+"${cmds.lpar_info} "}${g_convtabnova[$attr]} ;; #================================================================================================================= # lpar_procpool (pvmctl spp list --hide-label --field-delim=: -i name=$g_shared_proc_pool -d ${cmd.lpar_procpool}) #================================================================================================================= curr_shared_proc_pool_name|procpool_name|max_pool_proc_units|curr_reserved_pool_proc_units) cmds.lpar_procpool=${cmds.lpar_procpool:+"${cmds.lpar_procpool} "}${g_convtabnova[$attr]} ;; *) # Do nothing here. unknown will be added to the output list in sort_and_output ;; esac done return $RC_SUCCESS } # End of "gather_and_convert()" #============================================================================= # # Name: novacmdexec # # Description: Execute the specified command on an NovaLink. The command run # via a password-less remote ssh connection, thus the NovaLink # must have the public key of the local node in its authorized # keys list. # # Retry delay and retry count are obtained from HACMPnovaparam ODM. # # The "-o StrictHostKeyChecking=no" tells ssh to automatically # add new host keys to the host key database file, without user # confirmation, for all first-time connection. # The "-o LogLevel=quiet" tells ssh to disable the display of the # warning message 'Warning: Permanently added 'host,ip' (RSA) to # the list of known hosts.'. # The "-o AddressFamily=any" tells ssh to work with both # IPv4 and IPv6. # The "-o BatchMode=yes" option forces ssh to not prompt for a # password. In order to run commands remotely via ssh the target # ssh machine must have the public key of this client machine. # If the target ssh machine does not have the public key of this # machine, then normally ssh prompts for a password, and # that causes this script to hang. But by using BatchMode, # if the target does not have our public key, then ssh # immediately returns an error. # The "-o ConnectTimeout=3" and "-o ConnectionAttempts=3" # tells ssh to wait for a maximum timeout of 9 seconds if # connection with the target machine cannot be established. # The "-o TCPKeepAlive=yes" tells ssh to send an empty TCP ACK # packet in order to keep the connection with remote target # opened. # # Arguments: $1 [IN] cmd - command to run on the NovaLink. # $2 [OUT] ssh_ouput - reference to the output of the ssh command. # # Environment: g_nova # # Returns: RC_SUCCESS # RC_PING_ERROR # RC_SSH_ERROR # RC_REM_RES_BUSY_ERROR # RC_REM_CEC_BUSY_ERROR # RC_REM_NOT_ENOUGH_RES_ERROR # RC_REM_OTHER_ERROR # RC_REM_PROCUNITS_ERROR # RC_REM_MEM_ERROR # RC_REM_PU_VP_RATIO_ERROR # RC_POWEROFF_ERROR # #============================================================================= function novacmdexec { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset nova=$1 cmd=$2 ccmd="" typeset ping_output="" typeset nova_label="" typeset ping_cmd="ping -c 1 -w 3" typeset -i ping_rc=0 typeset -n ssh_output=$3 typeset ssh_cmd="eval LC_ALL=C ssh -o StrictHostKeyChecking=no -o LogLevel=quiet -o AddressFamily=any -o BatchMode=yes -o ConnectTimeout=3 -o ConnectionAttempts=3 -o TCPKeepAlive=no" typeset -i ssh_rc=0 typeset res="" ccmd="$cmd" #================================ : Convert Host name/Ip to Name #================================ nova_label=$(LC_ALL=C host $nova) rc=$? if (( $rc == $RC_SUCCESS ));then nova=${nova_label%% *} fi #======================================================= : Get retry count and retry delay. #======================================================= typeset -i nova_retry_cnt=0 nova_retry_dly=0 typeset nova_user="" get_nova_param nova_retry_cnt "$nova" retry_count 5 get_nova_param nova_retry_dly "$nova" retry_delay 10 nova_user=$(clodmget -q name=$nova -f user -n HACMPnova 2>/dev/null) rc=$? #get from HACMPcustom ODM during Verify and Sync if [[ -z $nova_user ]]; then typeset user_name=$nova"_user" nova_user=$(clodmget -q "type=verify_dlpar AND description=$user_name" -f value -n HACMPcustom) fi if (( $rc > 0 )) || [[ -z $nova_user ]]; then return $RC_FAILURE fi for (( i=1 ; i <= nova_retry_cnt ; i++ )) ; do #======================================================= : Try to ssh the command on NovaLink at address $nova. #======================================================= : Start ssh command at $(LC_ALL=C date) ssh_output=$($ssh_cmd "$nova_user@$nova '$ccmd 2>&1'") ssh_rc=$? : Return from ssh command at $(LC_ALL=C date) if (( $ssh_rc == 255 )) ; then #======================================================= : Cannot ssh the command. Do not retry. Break out from : the retry loop. #======================================================= rc=$RC_SSH_ERROR break elif (( $ssh_rc > 0 )) ; then typeset code=${ssh_output%%-*} code=$(echo $code | cut -c 2- ) case $code in "PVME010500A9") # PVME010500A9 Value for desired processing units (desired_proc_units) must be less than or equal to the value for maximum # processing units (max_proc_units). dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #======================================================= : Break out from the retry loop. #======================================================= rc=$RC_REM_PROCUNITS_ERROR break ;; "PVME010500A8") # PVME010500A8 Value for minimum processing units (min_proc_units) must be less than or equal to # the value for desired processing units (desired_proc_units). dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #======================================================= : Break out from the retry loop. #======================================================= rc=$RC_REM_PROCUNITS_ERROR break ;; "PVME01050061") # PVME01050061 Value for desired memory (desired_mem) must be less than or equal to the value for maximum # memory (max_mem). dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #====================================================== : Break out from the retry loop. #============================================= rc=$RC_REM_MEM_ERROR break ;; "PVME03000042") # PVME03000042 There is not Enough Available Memory to complete the request. dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #=================================================== : Break out from the retry loop. #=================================================== rc=$RC_REM_NOT_ENOUGH_RES_ERROR break ;; "PVME010500AE") # PVME010500AE Value for desired processors (desired_procs) cannot be greater than 20 times # the value for desired processing units (desired_proc_units). dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #=================================================== : Break out from the retry loop. #=================================================== rc=$RC_REM_PU_VP_RATIO_ERROR break ;; "PVME01050901") # PVME01050901 Failed to power off Virtual Machine.The 'PowerOff' operation failed. # Partition must be running to shut down. dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #=================================================== : Break out from the retry loop. #=================================================== rc=$RC_POWEROFF_ERROR break ;; "PVME01050060") # PVME01050060 Value for minimum memory (min_mem) must be less than or equal to the value for # desired memory (desired_mem). dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #=================================================== : Break out from the retry loop. #=================================================== rc=$RC_REM_MEM_ERROR break ;; *) if [[ $code != REST* ]] ; then code="unknown" fi dspmsg $ROHA_MSGS -s $ROHA_SET 544 \ "%1\$s: ERROR: NOVALINK %2\$s returns %3\$s error code when running command \"%4\$s\":\n%5\$s\n" \ "$PROGNAME" "$nova" "$code" "$ccmd" "$ssh_output" >&3 #======================================================= : Error executing the remote command. Break out from the : retry loop. #======================================================= rc=$RC_REM_OTHER_ERROR break ;; esac else #======================================== : Success. Break out from the retry loop #======================================== rc=$RC_SUCCESS break fi sleep $nova_retry_dly done return $rc } # End of "novacmdexec()" #============================================================================= # # Name: clnovaexec # # Description: Execute the specified command on an NovaLink. Each NovaLink defined on # the local node will be contacted until one responds. The # command is run via a password-less remote ssh connection, thus # the NovaLink must have the public key of the local node in its # authorized keys list. Retry delay and retry count are obtained # from ODM object HACMPnovaparam. # # The "-o StrictHostKeyChecking=no" tells ssh to automatically # add new host keys to the host key database file, without user # confirmation, for all first-time connection. # The "-o LogLevel=quiet" tells ssh to disable the display of the # warning message 'Warning: Permanently added 'host,ip' (RSA) to # the list of known hosts.'. # The "-o AddressFamily=any" tells ssh to work with both # IPv4 and IPv6. # The "-o BatchMode=yes" option forces ssh to not prompt for a # password. In order to run commands remotely via ssh the target # ssh machine must have the public key of this client machine. # If the target ssh machine does not have the public key of this # machine, then normally ssh prompts for a password, and # that causes this script to hang. But by using BatchMode, # if the target does not have our public key, then ssh # immediately returns an error. # The "-o ConnectTimeout=3" and "-o ConnectionAttempts=3" # tells ssh to wait for a maximum timeout of 9 seconds if # connection with the target machine cannot be established. # The "-o TCPKeepAlive=yes" tells ssh to send an empty TCP ACK # packet in order to keep the connection with remote target # opened. # # Arguments: $1 [IN] cmd - command line to run on the NovaLink. # $2 [OUT] ssh_ouput - reference to the output of the ssh command. # # Environment: g_nova_list # # Returns: RC_SUCCESS # RC_PING_ERROR # RC_SSH_ERROR # RC_REM_RES_BUSY_ERROR # RC_REM_CEC_BUSY_ERROR # RC_REM_NOT_ENOUGH_RES_ERROR # RC_REM_OTHER_ERROR # RC_REM_PROCUNITS_ERROR # RC_REM_MEM_ERROR # RC_REM_PU_VP_RATIO_ERROR # RC_POWEROFF_ERROR # #============================================================================= function clnovaexec { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset cmd=$1 ccmd="" typeset ping_output="" typeset ping_cmd="ping -c 1 -w 3" typeset -i ping_rc=0 typeset -n ssh_output=$2 typeset -i ssh_rc=0 typeset res="" for nova in $g_nova_list ; do #============================================ : Try to ping the NovaLink at address $nova. #============================================ ping_output=$($ping_cmd $nova >/dev/null 2>&1) ping_rc=$? if (( $ping_rc > 0 )) ; then #===================================================== : Cannot contact this NovaLink. Ask following NovaLink in list. #===================================================== dspmsg $ROHA_MSGS -s $ROHA_SET 526 \ "%1\$s: WARNING: unable to ping NovaLink at address %2\$s.\n" \ "$PROGNAME" "$nova" >&3 rc=$RC_PING_ERROR continue fi novacmdexec $nova "$cmd" ssh_output rc=$? if (( rc == RC_SSH_ERROR || rc == RC_CEC_NOT_FOUND )); then continue else break fi done if (( rc == RC_CEC_NOT_FOUND )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 521 \ "%1\$s: ERROR: Failed to get the Managed System when running command \"%2\$s\":\n%3\$s\n" \ "$PROGNAME" "$cmd" "$ssh_output" >&3 fi return $rc } # End of "clnovaexec()" #============================================================================= # # Name: process_change # # Description: Process a 'change' operation on some attributes. # # Arguments: None # # Environment: g_attributes # g_shared_proc_pool # # Returns: RC_SUCCESS # RC_PARAM_ERROR # or clnovaexec error code if an error occurs. # #============================================================================= function process_change { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset -i chg_rc= typeset out_str= print "${g_attributes//:/\\n}" | \ while IFS='=' read key value ; do { case $key in max_pool_proc_units|reserved_pool_proc_units) [[ -z $g_partition ]] && get_local_partition g_partition [[ -z $g_shared_proc_pool ]] && get_shared_processor_pool $g_partition g_shared_proc_pool if [[ -n $g_shared_proc_pool ]] ; then clnovaexec "pvmctl spp update -i name=$g_shared_proc_pool -s ${g_convtabnova[$key]}=$value" out_str chg_rc=$? if (( chg_rc > 0 )) ; then rc=$chg_rc fi else dspmsg $ROHA_MSGS -s $ROHA_SET 421 \ "%\1$s: ERROR: %\2$s Shared Processor Pool does not belong to %\3$s LPAR. Provide valid name through -S or -L option.\n" \ "$PROGNAME" "$g_shared_proc_pool" "$g_partition" >&3 rc=$RC_PARAM_ERROR break fi ;; esac } < /dev/null ; done # Avoid ssh to break while loop by redirecting standard input return $rc } # End of "process_change()" #============================================================================= # # Name: process_query # # Description: Process a 'query' operation on some attributes. # # Arguments: None # # Environment: g_attributes # g_labels # # Returns: RC_SUCCESS # #============================================================================= function process_query { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset attr_list=${g_attributes//:/ } typeset lbl_str="" out_str="" if (( g_labels == 1 )) ; then #======================================================= : Display header #======================================================= lbl_str="$g_attributes\n" fi typeset commands=( # colon-separated list of attributes typeset cec_info typeset lpar_info typeset lpar_procpool ) typeset results=( # colon-separated list of results typeset cec_info typeset lpar_info typeset lpar_procpool ) #========================================================== : Get profile proc mode to assign valid NovaLink attributes : for processor related attributes. #========================================================== typeset cmd_out="" [[ -z $g_partition ]] && get_local_partition g_partition if [[ -n $g_partition ]] ; then clnovaexec "pvmctl lpar list --hide-label -i name=$g_partition \ -d PartitionProcessorConfiguration.has_dedicated" cmd_out if (( $? == 0 )) ; then if [[ $cmd_out == "True" ]] ; then g_convtabnova[prof_minimum_procs]="DedicatedProcessorConfiguration.min" g_convtabnova[prof_desired_procs]="DedicatedProcessorConfiguration.desired" g_convtabnova[prof_maximum_procs]="DedicatedProcessorConfiguration.max" g_convtabnova[curr_min_procs]="DedicatedProcessorConfiguration.min" g_convtabnova[curr_procs]="DedicatedProcessorConfiguration.desired" g_convtabnova[curr_max_procs]="DedicatedProcessorConfiguration.max" elif [[ $cmd_out == "False" ]] ; then g_convtabnova[prof_minimum_procs]="SharedProcessorConfiguration.min_virtual" g_convtabnova[prof_desired_procs]="SharedProcessorConfiguration.desired_virtual" g_convtabnova[prof_maximum_procs]="SharedProcessorConfiguration.max_virtual" g_convtabnova[curr_min_procs]="SharedProcessorConfiguration.min_virtual" g_convtabnova[curr_procs]="SharedProcessorConfiguration.desired_virtual" g_convtabnova[curr_max_procs]="SharedProcessorConfiguration.max_virtual" fi fi fi #======================================================= : First, gather attributes together by NovaLink commands and : convert them to comprehensible ones. #======================================================= gather_and_convert "$attr_list" commands #======================================================= : Then, execute all commands on NovaLink and obtain results. #======================================================= execute_query_cmds commands results #======================================================= : Finally, sort results to match attributes order and : format output. #======================================================= sort_and_output results "$attr_list" out_str print -- "${lbl_str}${out_str}" return $RC_SUCCESS } # End of "process_query()" #============================================================================= # # Name: process_acquire # # Description: Process an 'acquire' operation of DLPAR memory, # processing unit(s) and/or CPU(s) # for the partition. Memory is acquired first, then CPU/PU. # # Arguments: None # # Environment: g_resource # g_memory # g_quantity # g_proc_units # g_force # g_partition # # Returns: RC_SUCCESS # RC_PARAM_ERROR # RC_PING_ERROR # RC_SSH_ERROR # RC_REM_RES_BUSY_ERROR # RC_REM_CEC_BUSY_ERROR # RC_REM_NOT_ENOUGH_RES_ERROR # RC_REM_OTHER_ERROR # # #============================================================================= function process_acquire { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset -i current_mem= required_acquire= typeset -i current_cpus= req_procs= typeset -F4 current_pus= req_proc_units= typeset out_str= typeset proc_mode="" [[ -z $g_partition ]] && get_local_partition g_partition if [[ -n $g_partition ]] ; then case $g_resource in dlpar) if (( $g_force == 1 )) ; then #======================================================= : case where g_force = 1 #======================================================= #======================================================= : mem and procs are separately done #======================================================= typeset mem_rc=$RC_UNKNOWN typeset procs_rc=$RC_UNKNOWN #======================================================= : Acquire memory. #======================================================= if (( $g_memory > 0 )) ; then clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d PartitionMemoryConfiguration.current" current_mem mem_rc=$? if (( $mem_rc == $RC_SUCCESS )) ; then required_acquire=$(( current_mem + g_memory )) clnovaexec "pvmctl lpar update -i name=$g_partition -s PartitionMemoryConfiguration.desired=$required_acquire" out_str mem_rc=$? if (( $mem_rc == $RC_SUCCESS )) ; then typeset -F4 mem_gb=$g_memory #As actual acquire operation is in multiple of 256, modifying the memory to display the actual value. typeset -i mem_256_chunks=$(( mem_gb/256 )) mem_gb=$(( mem_256_chunks*256 )) (( mem_gb /= 1024 )) dspmsg $ROHA_MSGS -s $ROHA_SET 527 \ "%1\$s: %2\$s GB of DLPAR resources have been acquired.\n" \ "$PROGNAME" "$mem_gb" else rc=$mem_rc fi else rc=$mem_rc fi fi #============================================================ : Acquire processors. Here the variable g_quantity is : used to check for both Dedicated Mode and Shared Proc Mode : and the variable g_proc_units : is used to check for only Shared Proc Mode. #============================================================= if (( $g_quantity > 0 || $g_proc_units > 0 )) ; then typeset opt_procs= opt_proc_units= (( $g_quantity > 0 )) && clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d PartitionProcessorConfiguration.has_dedicated" cmd_out rc=$? if (( $rc == $RC_SUCCESS )); then if [[ $cmd_out == "False" ]];then clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d SharedProcessorConfiguration.desired_virtual" current_cpus rc=$? else clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d DedicatedProcessorConfiguration.desired" current_cpus rc=$? fi fi if (( $rc == $RC_SUCCESS )) ; then req_procs=$(( current_cpus + g_quantity )) if [[ $cmd_out == "True" ]] ;then opt_procs="DedicatedProcessorConfiguration.desired=$req_procs" else opt_procs="SharedProcessorConfiguration.desired_virtual=$req_procs" fi fi (( $g_proc_units > 0 )) && clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d SharedProcessorConfiguration.desired_units" current_pus rc=$? if (( $rc == $RC_SUCCESS )) ; then req_proc_units=$(( current_pus + g_proc_units )) opt_proc_units="SharedProcessorConfiguration.desired_units=$req_proc_units" fi clnovaexec "pvmctl lpar update -i name=$g_partition -s $opt_procs $opt_proc_units" out_str procs_rc=$? if (( $procs_rc == $RC_SUCCESS )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 528 \ "%1\$s: %2\$d VP(s) or CPU(s) and %3\$s PU(s) of DLPAR resources have been acquired.\n" \ "$PROGNAME" "$g_quantity" "$g_proc_units" else rc=$procs_rc fi fi #======================================================= # in case of force, and for last loop of reassment, # we do not undo what was potentially done #======================================================= return $rc fi #======================== : case where g_force = 0 #======================== #======================================================= : Acquire memory. #======================================================= if (( $g_memory > 0 )) ; then clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d PartitionMemoryConfiguration.current" current_mem rc=$? if (( $rc == $RC_SUCCESS )) ; then required_acquire=$(( current_mem + g_memory )) clnovaexec "pvmctl lpar update -i name=$g_partition -s PartitionMemoryConfiguration.desired=$required_acquire" out_str rc=$? if (( $rc == $RC_SUCCESS )) ; then typeset -F4 mem_gb=$g_memory #As actual acquire operation is in multiple of 256, modifying the memory to display the actual value. typeset -i mem_256_chunks=$(( mem_gb/256 )) mem_gb=$(( mem_256_chunks*256 )) (( mem_gb /= 1024 )) dspmsg $ROHA_MSGS -s $ROHA_SET 527 \ "%1\$s: %2\$s GB of DLPAR resources have been acquired.\n" \ "$PROGNAME" "$mem_gb" fi fi fi if (( $rc == $RC_SUCCESS )) ; then #======================================================= : Acquire processors. Here the variable g_quantity is : used to check for both Dedicated Mode and Shared Proc Mode : and the variable g_proc_units : is used to check for only Shared Proc Mode. #======================================================= if (( $g_quantity > 0 || $g_proc_units > 0 )) ; then typeset opt_procs= opt_proc_units= (( $g_quantity > 0 )) && clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d PartitionProcessorConfiguration.has_dedicated" cmd_out rc=$? if (( $rc == $RC_SUCCESS ));then if [[ $cmd_out == "False" ]];then clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d SharedProcessorConfiguration.desired_virtual" current_cpus rc=$? else clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d DedicatedProcessorConfiguration.desired" current_cpus rc=$? fi fi if (( $rc == $RC_SUCCESS )) ; then req_procs=$(( current_cpus + g_quantity )) if [[ $cmd_out == "True" ]];then opt_procs="DedicatedProcessorConfiguration.desired=$req_procs" else opt_procs="SharedProcessorConfiguration.desired_virtual=$req_procs" fi fi (( $g_proc_units > 0 )) && clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d SharedProcessorConfiguration.desired_units" current_pus rc=$? if (( $rc == $RC_SUCCESS )) ; then req_proc_units=$(( current_pus + g_proc_units )) opt_proc_units="SharedProcessorConfiguration.desired_units=$req_proc_units" fi clnovaexec "pvmctl lpar update -i name=$g_partition -s $opt_procs $opt_proc_units" out_str rc=$? if (( $rc == $RC_SUCCESS )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 528 \ "%1\$s: %2\$d VP(s) or CPU(s) and %3\$s PU(s) of DLPAR resources have been acquired.\n" \ "$PROGNAME" "$g_quantity" "$g_proc_units" fi fi if (( $rc != $RC_SUCCESS )) ; then #========================================================= : Error while acquiring processors. : Since memory has succeeded, undo what has been acquired. #========================================================= if (( $g_memory > 0 )) ; then clnovaexec "pvmctl lpar update -i name=$g_partition -s PartitionMemoryConfiguration.desired=$current_mem" out_str if (( $? == $RC_SUCCESS )) ; then typeset -F4 mem_gb=$g_memory #As actual acquire operation is in multiple of 256, modifying the memory to display the actual value. typeset -i mem_256_chunks=$(( mem_gb/256 )) mem_gb=$(( mem_256_chunks*256 )) (( mem_gb /= 1024 )) dspmsg $ROHA_MSGS -s $ROHA_SET 530 \ "%1\$s: WARNING: The operation have completed partially. So,the acquisition of %2\$s GB of DLPAR resources has been undone.\n" \ "$PROGNAME" "$mem_gb" >&3 fi fi fi else #======================================================= : Error while acquiring memory. The operation may have : completed partially. Undo what has been acquired. #======================================================= typeset substr=$out_str print $substr | grep -q -i "Attention: Operation completed partially." if (( $? == 0 )) ; then substr=${substr##*Amount of memory added: } substr=${substr%% *} typeset -F4 mem_mb=$substr if (( $mem_mb > 0 )) ; then clnovaexec "pvmctl lpar update -i name=$g_partition -s PartitionMemoryConfiguration.desired=$current_mem" out_str if (( $? == $RC_SUCCESS )) ; then typeset -F4 mem_gb=$mem_mb #As actual acquire operation is in multiple of 256, modifying the memory to display the actual value. typeset -i mem_256_chunks=$(( mem_gb/256 )) mem_gb=$(( mem_256_chunks*256 )) (( mem_gb /= 1024 )) dspmsg $ROHA_MSGS -s $ROHA_SET 530 \ "%1\$s: WARNING: The operation have completed partially. So,the acquisition of %2\$s GB of DLPAR resources has been undone.\n" \ "$PROGNAME" "$mem_gb" >&3 fi fi fi fi ;; esac else dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_partition" >&3 rc=$RC_PARAM_ERROR fi return $rc } # End of "process_acquire()" #============================================================================= # # Name: process_release # # Description: Process a 'release' operation of some DLPAR memory, # processing unit(s) and/or CPU(s) for the partition. # # Arguments: None # # Environment: g_resource # g_memory # g_quantity # g_proc_units # g_force # g_partition # # Returns: RC_SUCCESS # RC_PARAM_ERROR # RC_PING_ERROR # RC_SSH_ERROR # RC_REM_RES_BUSY_ERROR # RC_REM_CEC_BUSY_ERROR # RC_REM_NOT_ENOUGH_RES_ERROR # RC_REM_OTHER_ERROR # #============================================================================= function process_release { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset out_str= typeset cmd_out= typeset release_order="memory cpu" typeset -i memory_released=0 typeset -i cpu_released=0 typeset proc_out_str= # : Release order should be based on the tunable $ROHA_RELEASE_CPU_BEFORE_MEM, : use default one if tunable is not updated # if (( ROHA_RELEASE_CPU_BEFORE_MEM == 1 )); then release_order="cpu memory" fi [[ -z $g_partition ]] && get_local_partition g_partition if [[ -n $g_partition ]] ; then case $g_resource in dlpar) for resourceloop in $release_order do case $resourceloop in memory) typeset -i CHUNK_SIZE=10240 #======================================================= : Release memory by chunk of $CHUNK_SIZE MB. #======================================================= if (( $g_memory > 0 )) ; then typeset -i qty=0 tmp=0 while (( qty < g_memory )) ; do tmp=$(( g_memory - qty )) mem_mb=$(( CHUNK_SIZE < tmp ? CHUNK_SIZE : tmp )) clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d PartitionMemoryConfiguration.current" current_mem rc=$? if (( $rc == $RC_SUCCESS )) ; then required_release=$(( current_mem - mem_mb )) clnovaexec "pvmctl lpar update -i name=$g_partition -s PartitionMemoryConfiguration.desired=$required_release" out_str rc=$? fi if (( $rc == $RC_SUCCESS )) ; then (( qty += $mem_mb )) typeset -F4 mem_gb=$qty #As actual release operation is in multiple of 256, modifying the memory to display the actual value. typeset -i total_256_mem_chunks=$(( mem_gb/256 )) typeset -i remainig_256_mem_chunks=$(( mem_gb%256 )) mem_gb=$(( remainig_256_mem_chunks == 0 ? $(( total_256_mem_chunks*256 )) : $(( total_256_mem_chunks*256 + 256 )) )) (( mem_gb /= 1024 )) dspmsg $ROHA_MSGS -s $ROHA_SET 531 \ "%1\$s: %2\$s GB of DLPAR resources have been released.\n" \ "$PROGNAME" "$mem_gb" elif (( $rc == $RC_REM_RES_BUSY_ERROR )) ; then #======================================================= : Error while releasing memory. The operation may have : completed partially. Also, undo what has been released. #======================================================= typeset substr=$out_str print $substr | grep -q -i "Attention: Operation completed partially." if (( $? == 0 )) ; then substr=${substr##*Amount of memory removed: } substr=${substr%% *} (( qty += $substr )) fi # Continue by releasing CHUNK smaller if (( $CHUNK_SIZE == 10240 )) ; then CHUNK_SIZE=5120 elif (( $CHUNK_SIZE == 5120 )) ; then CHUNK_SIZE=2048 elif (( $CHUNK_SIZE == 2048 )) ; then CHUNK_SIZE=1024 elif (( $CHUNK_SIZE == 1024 )) ; then CHUNK_SIZE=256 else break fi else break fi done fi if (( $rc == $RC_SUCCESS || $g_force == 1 )) ; then #======================================================= : Force return code to success. #======================================================= rc=$RC_SUCCESS memory_released=1 else #======================================================= : Also, despite memory has succeeded, undo what has been : released. #======================================================= if (( $qty > 0 )) ; then clnovaexec "pvmctl lpar update -i name=$g_partition -s PartitionMemoryConfiguration.desired=$current_mem" out_str if (( $? == $RC_SUCCESS )) ; then typeset -F4 mem_gb=$qty #As actual release operation is in multiple of 256, modifying the memory to display the actual value. typeset -i total_256_mem_chunks=$(( mem_gb/256 )) typeset -i remainig_256_mem_chunks=$(( mem_gb%256 )) mem_gb=$(( remainig_256_mem_chunks == 0 ? $(( total_256_mem_chunks*256 )) : $(( total_256_mem_chunks*256 + 256 )) )) (( mem_gb /= 1024 )) dspmsg $ROHA_MSGS -s $ROHA_SET 534 \ "%1\$s: WARNING: release of %2\$s GB of DLPAR resources has been undone.\n" \ "$PROGNAME" "$mem_gb" >&3 fi fi if (( $cpu_released == 1 )); then #======================================================= : Error while releasing processors. The operation may : have completed partially. Undo what has been released. #======================================================= typeset substr=$proc_out_str print "out_str is $proc_out_str" substr=${substr##*Amount of processors removed: } substr=${substr%% *} typeset -i cpu=$substr typeset -F4 pu=$substr if (( $cpu > 0 || $pu > 0 )) ; then typeset opt_procs= opt_proc_units= if [[ $cmd_out == "True" ]]; then (( $cpu > 0 )) && opt_procs="DedicatedProcessorConfiguration.desired=$current_cpus" else (( $cpu > 0 )) && opt_procs="SharedProcessorConfiguration.desired_virtual=$current_cpus" fi (( $pu > 0 )) && opt_proc_units="SharedProcessorConfiguration.desired_units=$pus" clnovaexec "pvmctl lpar update -i name=$g_partition -s $opt_procs $opt_proc_units" out_str if (( $? == $RC_SUCCESS )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 533 \ "%1\$s: WARNING: release of %2\$d VP(s) or CPU(s) and %3\$s PU(s) of DLPAR resources has been undone.\n" \ "$PROGNAME" "$cpu" "$pu" >&3 fi fi fi #end of cpu_released fi ;; cpu) #========================================================== : Release processors.Here the variable g_quantity is used : to check for both Dedicated Mode and Shared Proc Mode : and the variable g_proc_units is used to check : for only Shared Proc Mode #=========================================================== if (( $g_quantity > 0 || $g_proc_units > 0 )) ; then typeset opt_procs= opt_proc_units= (( $g_quantity > 0 )) && clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d PartitionProcessorConfiguration.has_dedicated" cmd_out rc=$? if (( $rc == $RC_SUCCESS ));then if [[ $cmd_out == "False" ]]; then clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d SharedProcessorConfiguration.desired_virtual" current_cpus rc=$? else clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d DedicatedProcessorConfiguration.desired" current_cpus rc=$? fi fi if (( $rc == $RC_SUCCESS )) ; then req_procs=$(( current_cpus - g_quantity )) if [[ $cmd_out == "True" ]] ; then opt_procs="DedicatedProcessorConfiguration.desired=$req_procs" else opt_procs="SharedProcessorConfiguration.desired_virtual=$req_procs" fi fi (( $g_proc_units > 0 )) && clnovaexec "pvmctl lpar list -i name=$g_partition --hide-label -d SharedProcessorConfiguration.desired_units" current_pus rc=$? if (( $rc == $RC_SUCCESS )) ; then req_proc_units=$(( current_pus - g_proc_units )) opt_proc_units="SharedProcessorConfiguration.desired_units=$req_proc_units" fi clnovaexec "pvmctl lpar update -i name=$g_partition -s $opt_procs $opt_proc_units" proc_out_str rc=$? if (( $rc == $RC_SUCCESS )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 532 \ "%1\$s: %2\$d VP(s) or CPU(s) and %3\$s PU(s) of DLPAR resources have been released.\n" \ "$PROGNAME" "$g_quantity" "$g_proc_units" fi fi if (( $rc == $RC_SUCCESS || $g_force == 1 )) ; then #======================================================= : Force return code to success. #======================================================= rc=$RC_SUCCESS cpu_released=1 else #======================================================= : Error while releasing processors. The operation may : have completed partially. Undo what has been released. #======================================================= typeset substr=$proc_out_str print "proc_out_str is $proc_out_str" substr=${substr##*Amount of processors removed: } substr=${substr%% *} typeset -i cpu=$substr typeset -F4 pu=$substr if (( $cpu > 0 || $pu > 0 )) ; then typeset opt_procs= opt_proc_units= if [[ $cmd_out == "True" ]]; then (( $cpu > 0 )) && opt_procs="DedicatedProcessorConfiguration.desired=$current_cpus" else (( $cpu > 0 )) && opt_procs="SharedProcessorConfiguration.desired_virtual=$current_cpus" fi (( $pu > 0 )) && opt_proc_units="SharedProcessorConfiguration.desired_units=$pus" clnovaexec "pvmctl lpar update -i name=$g_partition -s $opt_procs $opt_proc_units" out_str if (( $? == $RC_SUCCESS )) ; then dspmsg $ROHA_MSGS -s $ROHA_SET 533 \ "%1\$s: WARNING: release of %2\$d VP(s) or CPU(s) and %3\$s PU(s) of DLPAR resources has been undone.\n" \ "$PROGNAME" "$cpu" "$pu" >&3 fi fi #======================================================= : Also, despite memory has succeeded, undo what has been : released. #======================================================= if (( $g_memory > 0 )) ; then clnovaexec "pvmctl lpar update -i name=$g_partition -s PartitionMemoryConfiguration.desired=$current_mem" out_str if (( $? == $RC_SUCCESS )) ; then typeset -F4 mem_gb=$g_memory #As actual release operation is in multiple of 256, modifying the memory to display the actual value. typeset -i total_256_mem_chunks=$(( mem_gb/256 )) typeset -i remainig_256_mem_chunks=$(( mem_gb%256 )) mem_gb=$(( remainig_256_mem_chunks == 0 ? $(( total_256_mem_chunks*256 )) : $(( total_256_mem_chunks*256 + 256 )) )) (( mem_gb /= 1024 )) dspmsg $ROHA_MSGS -s $ROHA_SET 534 \ "%1\$s: WARNING: release of %2\$s GB of DLPAR resources has been undone.\n" \ "$PROGNAME" "$mem_gb" >&3 fi fi fi ;; esac #end of case for resource release order done #end of loop for resource release order ;; esac else dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_partition" >&3 rc=$RC_PARAM_ERROR fi return $rc } # End of "process_release()" #============================================================================= # # Name: process_halt # # Description: Process a 'halt' operation for the partition. # # Arguments: None # # Environment: g_partition # # Returns: RC_SUCCESS # RC_PARAM_ERROR # or clnovaexec error code if an error occurs. # #============================================================================= function process_halt { [[ ${VERBOSE_LOGGING:-} == high ]] && set -x typeset -i rc=$RC_SUCCESS typeset out_str= [[ -z $g_partition ]] && get_local_partition g_partition if [[ -n $g_partition ]] ; then clnovaexec "pvmctl lpar power-off -i name=$g_partition" out_str rc=$? else dspmsg $ROHA_MSGS -s $ROHA_SET 414 \ "%1\$s: ERROR: unknown %2\$s LPAR. Provide valid name through -L option.\n" \ "$PROGNAME" "$g_partition" >&3 rc=$RC_PARAM_ERROR fi return $rc } # End of "process_halt()" #####################################Functions end###################################### ############################################################################### ############################################################################### ## ## MAIN ## ############################################################################### ############################################################################### #============================================================================= # Attributes #============================================================================= typeset -r NOVA_ATTRS="\ nova_list \ nova_version" typeset -r MANAGED_SYSTEM_ATTRS="\ local_sys_name \ sys_name \ sys_lpar_names \ sys_state \ sys_type_model \ sys_mtms_str \ cod_mem_capable \ cod_proc_capable \ mem_region_size \ installed_sys_mem \ deconfig_sys_mem \ configurable_sys_mem \ sys_firmware_mem \ curr_avail_sys_mem \ curr_free_sys_mem \ installed_sys_proc_units \ configurable_sys_proc_units \ deconfig_sys_proc_units \ curr_avail_sys_proc_units \ curr_free_sys_proc_units \ min_proc_units_per_virtual_proc" typeset -r PARTITION_ATTRS="\ local_lpar_name \ lpar_name \ lpar_id \ uuid \ lpar_state \ lpar_avail_priority \ curr_proc_mode \ curr_min_mem \ curr_mem \ curr_max_mem \ curr_min_procs \ curr_procs \ curr_max_procs \ curr_min_proc_units \ curr_proc_units \ curr_max_proc_units \ curr_shared_proc_pool_name" typeset -r PROFILE_ATTRS="\ local_prof_name \ prof_name \ curr_profile \ prof_proc_mode \ prof_sharing_mode \ prof_shared_procpool \ prof_minimum_mem \ prof_minimum_procs \ prof_minimum_proc_units \ prof_desired_mem \ prof_desired_procs \ prof_desired_proc_units \ prof_maximum_mem \ prof_maximum_procs \ prof_maximum_proc_units" typeset -r SHARED_PROC_POOL_ATTRS="\ local_procpool_name \ procpool_name \ max_pool_proc_units \ curr_free_pool_proc_units \ curr_reserved_pool_proc_units" typeset -r GENERAL_ATTRS="\ nova_list \ nova_version \ local_sys_name \ sys_name \ sys_lpar_names \ sys_state \ sys_type_model \ sys_mtms_str \ local_lpar_name \ lpar_name \ lpar_id \ uuid \ lpar_state \ local_prof_name \ prof_name \ local_procpool_name \ procpool_name" typeset -r PROCESSOR_ATTRS="\ cod_proc_capable \ installed_sys_proc_units \ configurable_sys_proc_units \ deconfig_sys_proc_units \ curr_avail_sys_proc_units \ curr_free_sys_proc_units \ min_proc_units_per_virtual_proc \ prof_minimum_procs \ prof_minimum_proc_units \ prof_desired_procs \ prof_desired_proc_units \ prof_maximum_procs \ prof_maximum_proc_units \ prof_proc_mode \ prof_sharing_mode \ prof_shared_procpool \ curr_proc_mode \ curr_min_procs \ curr_procs \ curr_max_procs \ curr_min_proc_units \ curr_proc_units \ curr_max_proc_units \ curr_shared_proc_pool_name \ max_pool_proc_units \ curr_free_pool_proc_units \ curr_reserved_pool_proc_units" typeset -r MEMORY_ATTRS="\ cod_mem_capable \ mem_region_size \ installed_sys_mem \ deconfig_sys_mem \ configurable_sys_mem \ sys_firmware_mem \ curr_avail_sys_mem \ curr_free_sys_mem \ prof_minimum_mem \ prof_desired_mem \ prof_maximum_mem \ curr_min_mem \ curr_mem \ curr_max_mem" typeset -r AVAIL_ATTRS="\ curr_free_sys_mem \ curr_free_sys_proc_units" typeset -r CURRENT_ATTRS="\ curr_mem \ curr_procs \ curr_proc_units" typeset -r QUERY_ATTR_LIST="\ $NOVA_ATTRS \ $MANAGED_SYSTEM_ATTRS \ $PARTITION_ATTRS \ $PROFILE_ATTRS \ $SHARED_PROC_POOL_ATTRS" typeset -r CHANGE_ATTR_LIST="\ max_pool_proc_units \ reserved_pool_proc_units" typeset -r OPERATION_LIST="\ query \ change \ acquire \ release \ halt" typeset -r RESOURCE_LIST="\ dlpar" #============================================================================= # Conversion tables # Intended to convert attributes to be comprehensible by an NovaLink. # Key used in g_convtabnova is the attribute passed to clnovacmd, while value # is the attribute passed to nova pvmctl command. #============================================================================= typeset -A g_convtabnova #======================================================= # 0. local #======================================================= g_convtabnova[nova_list]="" # Not supported by NovaLink - internally computed g_convtabnova[nova_version]="" g_convtabnova[local_sys_name]="ManagedSystem.system_name" g_convtabnova[local_lpar_name]="" # Not supported by NovaLink - internally computed g_convtabnova[local_prof_name]="" # Not supported by NovaLink - internally computed g_convtabnova[local_procpool_name]="" # Not supported by NovaLink - internally computed #======================================================= # 1. cec_info (pvmctl sys list -d attributes) #======================================================= g_convtabnova[sys_name]="ManagedSystem.system_name" g_convtabnova[sys_state]="ManagedSystem.system_state" g_convtabnova[sys_lpar_names]="" # Not supported by NovaLink - internally computed g_convtabnova[sys_type_model]="MachineTypeModelAndSerialNumber.model" g_convtabnova[sys_mtms_str]="mtms_str" g_convtabnova[mem_region_size]="ManagedSystem.memory_region_size" g_convtabnova[installed_sys_mem]="ManagedSystem.memory_total" g_convtabnova[configurable_sys_mem]="ManagedSystem.memory_configurable" g_convtabnova[deconfig_sys_mem]="ManagedSystem.memory_deconfigurable" g_convtabnova[sys_firmware_mem]="ManagedSystem.firmware_memory" g_convtabnova[curr_avail_sys_mem]="ManagedSystem.memory_free" g_convtabnova[curr_free_sys_mem]="ManagedSystem.memory_free" g_convtabnova[installed_sys_proc_units]="ManagedSystem.proc_units" g_convtabnova[configurable_sys_proc_units]="ManagedSystem.proc_units_configurable" g_convtabnova[deconfig_sys_proc_units]="ManagedSystem.proc_units_deconfigurable" g_convtabnova[curr_avail_sys_proc_units]="ManagedSystem.proc_units_avail" g_convtabnova[min_proc_units_per_virtual_proc]="ManagedSystem.min_proc_units" g_convtabnova[curr_free_sys_proc_units]="ManagedSystem.proc_units_avail" #======================================================= # 2. lpar_info (pvmctl lpar list -i name=$gpartition -d attributes) #======================================================= g_convtabnova[lpar_name]="LogicalPartition.name" g_convtabnova[lpar_state]="LogicalPartition.state" g_convtabnova[lpar_id]="LogicalPartition.id" g_convtabnova[uuid]="LogicalPartition.uuid" g_convtabnova[lpar_avail_priority]="avail_priority" g_convtabnova[prof_name]="" g_convtabnova[curr_profile]="" g_convtabnova[prof_proc_mode]="PartitionProcessorConfiguration.has_dedicated" g_convtabnova[prof_sharing_mode]="PartitionProcessorConfiguration.sharing_mode" g_convtabnova[prof_shared_procpool]="" g_convtabnova[prof_minimum_mem]="PartitionMemoryConfiguration.min" g_convtabnova[prof_minimum_procs]="" g_convtabnova[prof_minimum_proc_units]="SharedProcessorConfiguration.min_units" g_convtabnova[prof_desired_mem]="PartitionMemoryConfiguration.desired" g_convtabnova[prof_desired_procs]="" g_convtabnova[prof_desired_proc_units]="SharedProcessorConfiguration.desired_units" g_convtabnova[prof_maximum_mem]="PartitionMemoryConfiguration.max" g_convtabnova[prof_maximum_procs]="" g_convtabnova[prof_maximum_proc_units]="SharedProcessorConfiguration.max_units" g_convtabnova[curr_min_mem]="PartitionMemoryConfiguration.min" g_convtabnova[curr_mem]="PartitionMemoryConfiguration.current" g_convtabnova[curr_max_mem]="PartitionMemoryConfiguration.max" g_convtabnova[curr_proc_mode]="PartitionProcessorConfiguration.has_dedicated" g_convtabnova[curr_min_procs]="" g_convtabnova[curr_procs]="" g_convtabnova[curr_max_procs]="" g_convtabnova[curr_min_proc_units]="SharedProcessorConfiguration.min_units" g_convtabnova[curr_proc_units]="SharedProcessorConfiguration.desired_units" g_convtabnova[curr_max_proc_units]="SharedProcessorConfiguration.max_units" #======================================================================================================================== # 8. lpar_proc_procpool (pvmctl spp list --hide-label --field-delim=: -i name=$g_shared_proc_pool -d ${cmd.lpar_procpool}) #======================================================================================================================== g_convtabnova[curr_shared_proc_pool_name]="SharedProcessorPool.name" g_convtabnova[procpool_name]="SharedProcessorPool.name" g_convtabnova[max_pool_proc_units]="SharedProcessorPool.max_proc_units" g_convtabnova[curr_free_pool_proc_units]="SharedProcessorPool.avail_proc_units" g_convtabnova[curr_reserved_pool_proc_units]="SharedProcessorPool.curr_rsrv_proc_units" g_convtabnova[reserved_pool_proc_units]="SharedProcessorPool.pend_rsrv_proc_units" #======================================================= # Return codes #======================================================= typeset -ri RC_SUCCESS=0 typeset -ri RC_FAILURE=1 typeset -ri RC_PARAM_ERROR=1 typeset -ri RC_PING_ERROR=2 typeset -ri RC_SSH_ERROR=3 typeset -ri RC_REM_RES_BUSY_ERROR=4 typeset -ri RC_REM_CEC_BUSY_ERROR=5 typeset -ri RC_REM_NOT_ENOUGH_RES_ERROR=6 typeset -ri RC_REM_OTHER_ERROR=7 typeset -ri RC_CEC_NOT_FOUND=8 typeset -ri RC_REM_PROCUNITS_ERROR=9 typeset -ri RC_REM_MEM_ERROR=10 typeset -ri RC_REM_PU_VP_RATIO_ERROR=11 typeset -ri RC_POWEROFF_ERROR=12 #======================================================= # Dspmsg codes #======================================================= typeset ROHA_SET=38 typeset ROHA_MSGS="scripts.cat" #======================================================= # Global variables #======================================================= typeset g_operation="" typeset g_nova_list="" typeset g_partition="" typeset g_local_partition="" typeset g_profile="" typeset g_local_profile="" typeset g_managed_system="" typeset -i g_memory=0 typeset g_attributes="" typeset -i g_force=0 typeset -i g_quantity=0 typeset -F4 g_proc_units=0.00 #======================================================= # Export environment #======================================================= PROGNAME=${0##*/} export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)" eval export $(cllsparam -x) [[ ${VERBOSE_LOGGING:-} == high ]] && set -x #======================================================= : Parse and check command line arguments #======================================================= parse_cmd_line "${@:-}" ; rc=$? (( $rc > 0 )) && exit $rc #======================================================= : Execute operation $g_operation #======================================================= case $g_operation in "query") process_query rc=$? ;; "change") process_change rc=$? ;; "acquire") process_acquire rc=$? ;; "release") process_release rc=$? ;; "halt") process_halt rc=$? ;; esac (( $rc > 0 )) && exit $rc exit 0