Run VMware PowerCLI on your Docker Container

If you have a vSphere environment in your Infrastructure and want to automate provisioning steps, you are most likely need PowerCLI which mostly requires Windows Guest or supported GNU/Linux guest on your environment. By the way, Terraform also very nice tool to provision new virtual machine, but it is very limited.

If you stumble upon the same case above, this post for you. Actually you do not need any GNU/Linux or Window guest but docker. If you have a docker environment you can pull vmware/powerclicore image, run it in your docker environment and connect your vcenter server in that docker container.

I used it to set boot priority of virtual guests. One of the good thing with docker is that you can also pass your environment variables inside the container to use that variables.

docker run  --rm -it --entrypoint="/usr/bin/pwsh"  \
   -e VI_SERVER=${TF_VAR_vsphere_server} \
   -e VI_USERNAME=${TF_VAR_vsphere_user} \
   -v ${pwd}/scripts:/tmp/scripts vmware/powerclicore /tmp/scripts/setboot-priority.ps1

What above shell script does that, it instantiates docker image vmware/powerclicore mounts <pwd>/scripts/ folder(where config.txt and setboot-priority.ps1 lives) on the host to /tmp/scripts in the container and run setboot-priority.ps1 in the container.

You can get setboot-priority.ps1 script from my github repo.

VMware Hot-Add RAM on Rhel 5

Last week, I  confronted a problem. Even though virtual guest which is rhel5.11(Tikanga) enabled for hot-add RAM, It did not update the new memory size,  after adding 4 GBs of RAM without power off the machine.

Solution:

Finally, I have found the solution. We need to apply some couple of commands to hit the kernel force rescan memory blocks.

First let’s see state of the memory blocks by applying command below. For my case I have no offline memory blocks. But, after adding a new memory most likely you will see some memory blocks as an offline.

root@gns3:~# grep line /sys/devices/system/memory/*/state
/sys/devices/system/memory/memory0/state:online
/sys/devices/system/memory/memory10/state:online
/sys/devices/system/memory/memory11/state:online
/sys/devices/system/memory/memory12/state:online
/sys/devices/system/memory/memory13/state:online
/sys/devices/system/memory/memory14/state:online
/sys/devices/system/memory/memory15/state:online
/sys/devices/system/memory/memory1/state:online
/sys/devices/system/memory/memory2/state:online
/sys/devices/system/memory/memory3/state:online
/sys/devices/system/memory/memory4/state:online
/sys/devices/system/memory/memory5/state:online
/sys/devices/system/memory/memory6/state:online
/sys/devices/system/memory/memory7/state:online
/sys/devices/system/memory/memory8/state:online
/sys/devices/system/memory/memory9/state:online

To make them online, we need to apply command below. After applying the command, you may get some weird errors. You can ignore them. You can check the state of the  memory by reissuing the first command.

for i in $(ls /sys/devices/system/memory/*/state); do echo online > $i; done
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument
-su: echo: write error: Invalid argument

For more information please check the solution here.