«

»

Change AHV Based Nutanix Controller Virtual Machine (CVM) RAM

A few days ago i changed Nutanix Controller Virtual Machine (CVM) Memory configuration for a customer. There is a Nutanix KB about this which can be found here here but since it includes manual steps i figure i create a script which you can run from the AHV host. This blog post is divided into the following sections:

  • Information – What I’m trying to achieve and important information that must not be ignored.
  • Procedure Overview – Includes the procedure and can be used for everyone with Linux skills.
  • Change CVM RAM Script – The actual script you can use to change CVM RAM.
  • Detailed Procedure – Includes the commands needed to create the script, make it executable and finally run the script.

Information

Yes, you need to run the script on all AHV hosts.
The only thing you need to change in the below script to meet your needs is the amount of memory, called RAM and marked in red, you want to assign to our CVMs.
The customer wanted to go from 24 GB Memory per CVM to 32 GB Memory per CVM.

 

screen-shot-2017-01-07-at-07-13-13

Important: In my case i was allowed to shut down the Nutanix Cluster before i made the changes and that mean i could run the script on all AHV hosts same time. If you can’t shut down the Nutanix Cluster you need to change Memory for one CVM at the time.
Before you start the change Memory process on any CVM, make sure PRISM shows OK in the “Data Resiliency Status” section in PRISM 

screen-shot-2017-01-07-at-06-57-08

Procedure Overview

Follow the below procedure to change the CVM Memory.

  • Log in to the AHV host where the CVM is running via SSH
  • Create the change-memory.sh file with your required RAM configuration value and make the script executable.
  • Run the script

This is the output when running the script on one of my AHV hosts:

screen-shot-2017-01-07-at-13-10-50

Log in to PRISM and verify the amount of Memory per CVM.

screen-shot-2017-01-07-at-13-15-44

Change CVM RAM Script

This is the script you can use to change CVM RAM configuration.

#!/bin/bash
# Script to change CVM RAM
# Author: Magnus Andersson Staff Solutions Architect at Nutanix
# Version 1.0
#
# Define amount of RAM needed for the CVM
RAM=32
#
# Do not change anything below this line
# --------------------------------------
echo Start CVM reconfiguration process
echo ""
# Find CVM
cvm=`/usr/bin/virsh list --all | grep CVM | awk '{print $2}'`
# Shutdown CVM
if /usr/bin/virsh list --all | grep CVM | awk '{print $3}' | grep -i run; then
echo Shutting down CVM: $cvm
/usr/bin/virsh shutdown $cvm
else
echo CVM not running, proceeding without trying to shut down the CVM
fi
sleep 20
# Get current configuration
if /usr/bin/virsh list --all | grep CVM | awk '{print $3}' | grep -i run; then
echo "The CVM, $cvm, could not be shut down, manual investigation required"
echo "Exiting the script........"
exit 1
else
echo "Current $cvm RAM (maxmem & mem) configuration in KiB is:"
/usr/bin/virsh dumpxml $cvm | egrep -i "KiB" | awk -F"<" '{print $2}' | awk -F">" '{print $2}'
fi
#echo ""
# Set new configuration
echo Setting new RAM configuration for $cvm
sleep 4
/usr/bin/virsh setmaxmem $cvm --config --size "${RAM}GiB"
/usr/bin/virsh setmem $cvm --config --size "${RAM}GiB"
# Get new configuration
echo "New $cvm RAM (maxmem & mem) configuration in KiB is:"
sleep 10
/usr/bin/virsh dumpxml $cvm | egrep -i "KiB" | awk -F"<" '{print $2}' | awk -F">" '{print $2}'
#echo ""
# Start CVM
echo Starting CVM: $cvm
/usr/bin/virsh start $cvm
# Verify CVM is running
echo Verifying if the CVM is running
sleep 8
if /usr/bin/virsh list --all | grep CVM | awk '{print $3}' | grep -i run;then
echo ""
echo "CVM $cvm is running"
echo "Configuration process finished"
else
echo "The CVM $cvm is not running! Manual investigation is required...."
fi

 

This script has been tested on AOS 5.0 and AHV 20160925.30

Detailed Procedure Overview

  • Copy the change-memory.sh script above.
  • Log in the the AHV host where the CVM is running via SSH using e.g. putty
  • Create a file called change-memory.sh and paste the script into the file:
    • vi change-memory.sh (to start editor vi and create a new file)
    • press i (to insert text)
    • paste the script
    • change the Memory configuration by going to the RAM line and step out to the number 2 and then:
      • press cw
      • type the new amount of RAM
    • save the script by pressing the below characters followed by enter:
      • :wq!
  • Make the script executable by running the following command:
    • chmod 700 change-memory.sh
  • Run the script by typing:
    • ./change-memory

3 pings

Comments have been disabled.