Deallocating multiple VMs with azure-cli & bash

The great thing about Azure (and to that extent Azure Stack) is that you can quickly spin up and down test environments. If you’re like me, you prefer a command line over any browser interface any day of the week for repeatable tasks.
In the Azure world, the great azure-cli command line tool comes to the rescue. The great thing about it is that it is a) open source, and b) cross platform. So working with resources in Azure from my Linux workstation is no problem. Until I ran into one.

For testing out some network configurations, I spun up a bunch of VMs in Azure. Once I was done, I wanted to deallocate them to not have them consume resources, and thus cost money. That’s after all the great thing about a cloud.
All my VMs were in their own resource group to have a dedicated network for them and since it’s a test lab, easy to manage without interferring with other resources. The azure-cli provides the functionality on a per VM basis to deallocate a VM from the shell. That is all good for one, but not for multiples. Let’s take a look:

mschulz@eowyn:~$ azure vm list -g db2lab
 info:    Executing command vm list
 + Getting virtual machines
 data:    ResourceGroupName  Name       ProvisioningState  PowerState      Location  Size
 data:    -----------------  ---------  -----------------  --------------  --------  ----
 data:    db2lab             db2-node1  Succeeded          VM running       westus    Standard_A2
 data:    db2lab             db2-node2  Succeeded          VM running       westus    Standard_A2
 info:    vm list command OK
 This is the environment for the simple test. Two VMs (more to be added) to form a cluster in resource group db2lab.

The azure-cli tool provides us the name of the resource group, as well as the VM names.
From here we can do a simple one liner to get the respective VM names we want to target and write
them into an array for later processing:

mschulz@eowyn:~$ vmname=($(azure vm list |grep -i db2lab | awk '{print $3}'))
 mschulz@eowyn:~$ echo ${vmname[@]}
 db2-node1 db2-node2
 Now that we have those names in the array, we can then proceed to process them in a simple loop that
 will take the action on the VMs we want.
for i in "${vmname[@]}"
 do :
 azure vm deallocate –g db2lab -n $i

The above example reads the values from the array, passes them to the azure-cli and deallocates the VMs. In order to do the revers, we could simply replace deallocate with start.
Since this would be a bit cumbersome to do every time we need this operation, let’s pull all this together in a handy shell script:



startvms() {
         vmname=($(azure vm list |grep -i $rgroup | awk '{print $3}'))
         for i in "${vmname[@]}"
 do :
 azure vm start -g $rgroup -n $i

stopvms() {
         vmname=($(azure vm list |grep -i $rgroup | awk '{print $3}'))
         for i in "${vmname[@]}"
 do :
 azure vm stop -g $rgroup -n $i

deallocvms() {
         vmname=($(azure vm list |grep -i $rgroup | awk '{print $3}'))
         for i in "${vmname[@]}"
 do :
 azure vm deallocate -g $rgroup -n $i

case $2 in
 start)  startvms ;;
 stop)   stopvms ;;
 deallocate)     deallocvms ;;
 *)      echo "usage: $0 "resource group" start|stop|deallocate" >&2
 exit 1


Using this script, we can now on the command line specifiy the resource group in question, plus
define the action we want to be taken (start, stop, or deallocate).

The azure-cli tool is a fantastic resource in the tool belt of the Azure admin to perform many tasks from the command line of either Linux, WIndows, or Mac OS X. Look Ma’, no GUI.


Softrock Lite II build day 1

Finally made some time to start building the Softrock Lite II SDR
receiver. The original plan was to build it as a pan adapter for my
TS-940S which has an IF out port. Since I no longer have this rig,
and my K3S has a different first IF, I decided to build it for 30m as
a WSPR receiver.

20160117_235335715_iOS (2)
First test of the oscillator stage

Checking on the frequency counter confirms everything is working as
it is supposed to be.


Next up was the divider stage. All went fine, except with some need to
tidy up my soldering of SMD parts. First time I used a hot air rework
station for SMD parts. Not as easy as I thought, but turned out OK.

20160119_001549348_iOS (2)

Again tested all the steps and made sure the voltage readings for example
were correct. It is really important to do this for each stage to make sure no
errors sneak in and then are harder to find later.


The divider provided the expected signal at the test points with the expected
frequency. So on to the next stages ….


Made the board for the K5TRI Ardukeyer based on K3NG’s code so that
I can use paddles with the TS-940S.


I used Eagle for the schematics and PCB layout and then transparencies
printed in the laser printer and heat to get the layout onto the board. Some
time bathing in Ferrite-Chloride Acid does the rest.