Table of Contents

Azure - VM

About

VM management in Azure

Library

Most of the commands in this article are created with the cli but your can also used third party library.

Example with:

Management

Create

Everything you can specify on the web portal is available via a command-line flag or switch. +

Example with the azure cli:

az.cmd vm create ^
    --resource-group groupName ^
    --name vmName ^
    --image Oracle:Oracle-Linux:7.4:7.4.20170908 ^
    --size Standard_DS1_v2 ^
    --authentication-type password ^
    --admin-username userName ^
    --admin-password userPwd ^
    --location westeurope

where:

Output:

{\ Finished ..
  "fqdns": "",
  "id": "/subscriptions/a3c34725-da6a-41ac-87fa-090f6b96d44d/resourceGroups/VGZ_OBIEE/providers/Microsoft.Compute/virtualMachines/HI-ORACLE-12-SE",
  "location": "westeurope",
  "macAddress": "00-0D-3A-26-99-A6",
  "powerState": "VM running",
  "privateIpAddress": "10.0.0.4",
  "publicIpAddress": "52.166.234.80",
  "resourceGroup": "groupName",
  "zones": ""
} 

Start / Stop

az.cmd vm start --name vmName --resource-group groupName
az.cmd vm stop --name vmName --resource-group groupName

Reboot

logged in as root

reboot
Broadcast message from hi-adm@HI-ORACLE-DB-02
        (/dev/pts/0) at 2:04 ...

The system is going down for reboot NOW!

Delete

az.cmd vm delete --name vmName --resource-group groupName

Info

Show

az.cmd vm show  --name vmName --resource-group groupName

List

az.cmd vm list --output table
Name             ResourceGroup    Location
---------------  ---------------  ----------
ORACLE-12-SE  groupName        westeurope

# Without headers
az.cmd vm list --output table --query "[*].[name, resourceGroup]"
# With headers
az.cmd vm list --output table --query "[*].{VMName:name, OSType:storageProfile.osDisk.osType}"

Nic

Get the Nic id

az.cmd vm show --resource-group myResourceGroup --name myVM -d --o tsv --query "networkProfile.networkInterfaces[].id"
/subscriptions/a3c34725-da090f6b96d44d/resourceGroups/myResrouceGroup/providers/Microsoft.Network/networkInterfaces/MY_MACHINE_01VMNic

Get IP

az vm show --resource-group myResourceGroup --name myVM -d --query [publicIps] --o tsv

State

az vm show --resource-group myResourceGroup --name myVM -d --query [powerState] --o tsv
VM running
or
VM stopped

az.cmd vm list --output table -d --query "[*].{Name:name, Group:resourceGroup, Power:powerState}"

Run Command

Example:

az vm run-command invoke -g RG20ETL200-A -n su20etl201a --command-id RunShellScript --scripts "echo nico"
{
  "value": [
    {
      "code": "ProvisioningState/succeeded",
      "displayStatus": "Provisioning succeeded",
      "level": "Info",
      "message": "Enable succeeded: \n[stdout]\nnico\n\n[stderr]\n",
      "time": null
    }
  ]
}