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
mschulz@eowyn:~$

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
mschulz@eowyn:~$

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
done

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:

#!/bin/bash

vmname=”
rgroup=$1

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

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

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

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

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.

20160117_235327702_iOS

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.

divider-scope

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

K5TRI Ardukeyer complete

Finally finding some time to post the completed keyer I designed
the board for a while ago.

IMAG00215
The populated board

IMAG00205

IMAG00207

Now I can finally use paddles with my TS-940S. Next version will be the deluxe
edition with USB and LCD display.

2015 Salmon Run

Salmon Run is over. The salmon have arrived and what can I say, conditions were
piss poor, especially on Sunday. Most contacts were made on Saturday as SOHPCW.

IMAG00242
This was the first time I added an amp to contest operation. Certainly made a difference.

Band     QSOs     Pts  Mul
   3.5      64     186    5
     7     152     456    9
    14     203     606   44
    21      45     135    6
Total     464    1383   64
Score: 89,012
1 Mult = 7.3 Q’s

My goal was to make at least 500 Qs. After a very bad start on Sunday I eventually called
it quits as it was simply not going anywhere. Of course conditions improved after the fact
but such is life.

Some more statistics below:

QSO Party – 2015-09-19 1600Z to 2015-09-20 0000Z – 472 QSOs
K5TRI/7 Runs >10 QSOs:

2015-09-19 1650 – 1855Z,   14058 kHz, 70 Qs, 33.8/hr K5TRI
2015-09-19 1926 – 1953Z,   21046 kHz, 15 Qs, 32.7/hr K5TRI
2015-09-19 2003 – 2036Z,   14054 kHz, 22 Qs, 39.5/hr K5TRI
2015-09-19 2050 – 2111Z,   21042 kHz, 17 Qs, 49.1/hr K5TRI
2015-09-19 2123 – 2158Z,   14051 kHz, 33 Qs, 56.7/hr K5TRI
2015-09-19 2205 – 2227Z,    7055 kHz, 13 Qs, 35.8/hr K5TRI
2015-09-19 2236 – 2254Z,   14060 kHz, 19 Qs, 61.8/hr K5TRI
2015-09-19 2339 – 0001Z,   14056 kHz, 20 Qs, 53.9/hr K5TRI
2015-09-20 0010 – 0042Z,    7056 kHz, 26 Qs, 49.6/hr K5TRI
2015-09-20 0046 – 0312Z,    7050 kHz, 91 Qs, 37.2/hr K5TRI
2015-09-20 0322 – 0415Z,    3555 kHz, 54 Qs, 61.0/hr K5TRI
2015-09-20 0421 – 0445Z,    7057 kHz, 18 Qs, 45.8/hr K5TRI
2015-09-20 1715 – 1747Z,   14057 kHz, 12 Qs, 22.5/hr K5TRI
2015-09-20 1945 – 2010Z,   14057 kHz, 12 Qs, 29.2/hr K5TRI

QSO Party – 2015-09-19 1600Z to 2015-09-20 0000Z – 472 QSOs
K5TRI/7 Max Rates:

2015-09-19 2003Z – 3.0 per minute  (1 minute(s)), 180 per hour by K5TRI
2015-09-20 0332Z – 1.7 per minute  (10 minute(s)), 102 per hour by K5TRI
2015-09-20 0236Z – 1.0 per minute  (60 minute(s)), 61 per hour by K5TRI

salmonrun-sectionsband
Sections per band

 

sectionshour
Sections per hour

Ardukeyer board progress

After I botched the build of the K3NG based keyer for my TS-940S using perfboard,
I decided to do it right (and better looking) and make a real PCB.

IMAG00204

In the process I had to learn Eagle and also of course get to play with nasty chemicals.
For this board I used the photo resist method as the toner transfer method I used for
previous boards didn’t yield the results I was after.
All that’s left now is drilling and soldering …

Ardukeyer

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

IMAG00201

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.