Azure Command Line Tools: Cross Platform CLI aka xplat-cli

If you are launching an occasional VM, administering a small environment on Azure, the management console does the job but if you need to deal with multiple subscriptions and get things done pretty quick, cli tools are must. Fortunately, you have multiple choices with Azure here -

  1. Obviously Powershell . Resistance is futile .
  2. For non windows environments Azure cross Platform CLI .
  3. And then there is Python via Azure SDK for Python.

I still haven’t tried enough to figure out the extent to which you can manage using Python but the other two options are pretty powerful. Though Microsoft has excellent documentation I thought I’d write down the steps to configure these tools, for my clarity.

Setting up Azure cross platform CLI

I prefer this over Powershell because your scripts can run anywhere as long as you have NodeJs. I work predominantly on a windows machine so the steps below are applicable for windows platform.

If you are running a windows machine, do yourself a favor and install Chocolatey . Chocolatey is yum install equivalent for Windows crowd and it is awesome. Microsoft has actually shipped a package manager called OneGet on Windows 10 Technical Preview and Chocolatey is one of the package sources. Installing it is ridiculously easy. Open an elevated command prompt and paste the following

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString(''))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

Once its installed, you can use choco install myawesomepackage to install wide variety of software. Coming back to installation of NodeJs, just enter this

choco install nodejs

Its that simple. Once done, use npm to install Azurecli

npm install azure-cli -g

After installation, if you just type azure you’ll see info and help, including awesome ASCII art :)

info:             _    _____   _ ___ ___
info:            /_\  |_  / | | | _ \ __|
info:      _ ___/ _ \__/ /| |_| |   / _|___ _ _
info:    (___  /_/ \_/___|\___/|_|_\___| _____)
info:       (_______ _ _)         _ ______ _)_ _
info:              (______________ _ )   (___ _ _)
info:    Microsoft Azure: Microsoft's Cloud Platform
info:    Tool version 0.8.12
help:    Display help for a given command
help:      help [options] [command]
help:    Log in to an Azure subscription using Active Directory. Currently, the user can login only via Microsoft organizational account

Connect to Azure

Now that we have installed cli, lets set it up and play around a bit. There are two ways you could login - Using an organizational account (Azure AD Login) or a Microsoft live account. If you have Azure AD login, you can connect using azure login -u username -p password . I have a live account to which multiple subscriptions are attached so I first downloaded the azure publish settings file.

azure account download

This will launch your default browser. Signin with your live credentials and download the settings file

azure account import "E:\Azure Pass-1-25-2015-credentials.publishsettings"

If your account has multiple subscriptions attached to it, you might want to make sure that you are connected to the right subscription before doing anything

azure account list

Set the account you choose to use

azure account set "Azure Pass"

Azurecli has two modes - Service Management Mode and Resource Management Mode . Resource Manager is a relatively recent addition to Azure and its available on new portal. It allows you to manage a group of resources as a logical unit. Example - a bunch of servers on SQL Server AlwaysOn setup. There are a bunch of templates available which can be downloaded and modified. At the time of this writing, these two cli modes are exclusive and you can switch between them using commands below

azure config mode arm
azure config mode asm

Coming back to service management , following are the major commands available. The commands are easy to construct. They are generally like this azure [topic] [verb] [options]


Image source: Interpolarability Blog

Launch a VM

Lets try to launch a VM using cli. Lets say I would like to launch a new Ubuntu VM on a new cloud service and use a new storage account. Let’s check the related images available on Azure VMDepot

azure vm image list | findstr "Ubuntu" 

# Create storage account
azure storage account create mybasestorage --label PrimaryStorage --location "West US"

# Set Azure storage account
azure storage account set 

# Create VM

azure vm create Gotham 0b11de9248dd4d87b18621318e037d37__RightImage-Ubuntu-12.04-x64-v13.4  --vm-size extrasmall --location "Western US" --userName joker -password WhySoSiriousS! --blob-url

In the next post - I will write about some more azure cli commands and Azure Powershell.

Check out Azurecli complete command reference here

comments powered by Disqus