2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-11 01:10:31 +00:00
cheat.sheets/sheets/az
2018-06-25 10:58:23 +00:00

92 lines
3.1 KiB
Plaintext

# Microsoft Azure CLI 2.0
# Command-line tools for Azure
# Install Azure CLI 2.0 with one curl command.
curl -L https://aka.ms/InstallAzureCli | bash
# create a resource group named "MyResourceGroup" in the westus2 region of Azure
az group create -n MyResourceGroup -l westus2
# create a Linux VM using the UbuntuTLS image, with two attached storage disks of 10 GB and 20 GB
az vm create -n MyLinuxVM -g MyResourceGroup --ssh-key-value $HOME/.ssh/id_rsa.pub --image UbuntuLTS --data-disk-sizes-gb 10 20
# list VMs
az vm list --output table
# list only VMs having distinct state
az vm list -d --query "[?powerState=='VM running']" --output table
# delete VM (with the name MyLinuxVM in the group MyResourceGroup)
az vm delete -g MyResourceGroup -n MyLinuxVM --yes
# Delete all VMs in a resource group
az vm delete --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)
# Create an Image based on a running VM
az vm deallocate -g MyResourceGroup -n MyLinuxVM
az vm generalize -g MyResourceGroup -n MyLinuxVM
az image create --resource-group MyResourceGroup --name MyTestImage --source MyLinuxVM
# Running VM based on a VHD
az storage blob upload --account-name "${account_name}" \
--account-key "${account_key}" --container-name "${container_name}" --type page \
--file "${file}" --name "${vhd_name}"
az disk create \
--resource-group ${resource_group} \
--name myManagedDisk \
--source https://${account_name}.blob.core.windows.net/${container_name}/${vhd_name}
# open port
az vm open-port --resource-group MyResourceGroup --name MyLinuxVM --port 443 --priority 899
# Show storage accounts
az storage account list --output table
# Show contaniers for an account
az storage container list --account-name mystorageaccount --output table
# Show blobs in a container
az storage blob list --account-name mystorageaccount --container-name mycontainer --output table
# list account keys
az storage account keys list --account-name STORAGE_NAME --resource-group RESOURCE_GROUP
# Show own images
az image list --output table
# Configure default storage location
az configure --defaults location=eastus2
# Show disks
az disk list --output table
# Copy blob
az storage blob copy start \
--source-uri 'https://md-ldh5nknx2rkz.blob.core.windows.net/jzwuuuzzapn0/abcd?sv=2017-04-17&sr=b&si=68041718-6828-4f5e-9e6e-a1b719975062&sig=XXX' \
--account-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX== \
--account-name destaccount \
--destination-container vms \
--destination-blob DESTINATION-blob.vhd
# List virtual networks
az network vnet list --output table
# List virtual networks adapters
az network nic list --output table
# List public IP addresses used by the VMs
az vm list-ip-addresses --output table
# create snapshot
az snapshot create --resource-group IC-EXASOL-001 --source vm1-disk1 -n vm1-snap1
# create SAS url for a snapshot
az snapshot grant-access --resource-group IC-EXASOL-001 --name vm1-snap1 --duration-in-seconds 36000 --query '[accessSas]' -o tsv
# attach disk
az vm disk attach --vm-name vm1 -g RESOURCE_GROUP --disk DISK1_ID
# detach disk
az vm disk detach --vm-name vm1 -g RESOURCE_GROUP --name DISK1_ID