Azure CLI: Creating a VM

Although I had vowed not to create a VM again using the Classic deployment model, I was finding it hard to work with Chef in the ARM model. And as it seems that the Azure CLI operates by default against the Classic model… I’m using Azure CLI.


Get the Azure CLI

npm install azure-cli -g

Switch to ASM config mode

azure config mode asm

Download and apply your account settings file

Running this takes you to a browser which prompts you to save the .settings file to your local drive (e.g. c:\temp\ in the example here)

azure account download

Once downloaded, run this:

azure account import “C:\temp\My.publishsettings”

Login

If not authenticated currently, run this, which takes you to another browser:

azure login

List your VMs

azure vm list

List the available VM images from which you can build a VM

azure vm image list

From that list, right now, I am using this VHD, and an example command line of that follows:

a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-20160812-en.us-127GB.vhd

Create a VM

azure vm create ClassicVM01 a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-20160812-en.us-127GB.vhd username password --location "East US"

Note ref the US location that I am in the UK. But variations on “West Europe” do not seem to work in  CLI. Now I failed to specify [-r] in my command line, i.e. enable RDP. So I had to go in to the Azure portal after that and set RDP on port 3389. Also note that the default VM size is “small” if you do not specify a value. Once that is all done, the RDP session includes this:

That is, it is indeed 2012 R2, and it’s Small.

Now you have at least 1 (Classic) VM, running this should return stuff:

azure vm list

Note that it does take a while to get to the ReadyRole status. Before that I got [RoleStateUnknown] followed by [Provisioning]  and [BusyRole]. I think it took about 30 minutes to get to the Ready state.

For fun, I saw there was the nano-server. Let’s see how that plays:

a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2016-Nano-20160801-en.us-8GB.vhd 

azure vm create ClassicVM03 a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2016-Nano-20160801-en.us-8GB.vhd administrator99 HornetsNest99! --location "East US" -r

And actually, that was a bit quicker to deploy. But it turns out it is built to be headless, so no you can’t rdp to it. See here.

Information and errors

The .azure location contains a lot about configuration detail and errors. Take a look:

Create many VMs

Ultimately, I would want to do this through PowerShell (sure, that of course has its own API for this, so you could say a bit perverse). Code is here.

Delete many VMs

And then we want to tidy up. The help extract shows you all you need for the arguments. Code.

And the set created earlier has gone:

And to complete tidy up, update the script (of course you would make this a function after playing) to remove those others:


Hit Subscription Core Limits

Later… and then I tried to get fancy, and create LOTS of VMs. No, I don’t…

BadRequest : The subscription policy limit for resource type ‘cores count’ was exceeded. The limit for resource type ‘cores count’ is 20 per subscription, the current count is 20, and the requested increment is 4.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s