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 -
- Obviously Powershell. Resistance is futile.
- For non windows environments Azure cross Platform CLI.
- 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
Once its installed, you can use choco install myawesomepackage
to install wide variety of software. Coming back to installation of NodeJs, just enter this
Its that simple. Once done, use npm
to install Azurecli
After installation, if you just type azure
you’ll see info and help, including awesome ASCII art :)
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.
This will launch your default browser. Signin with your live credentials and download the settings file
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
Set the account you choose to use
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
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
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