Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 2.37 KB

File metadata and controls

76 lines (57 loc) · 2.37 KB

Subprocess management

from subprocess import call   
call(["az", "vm", "list", "-g", "rgName"])

az login --service-principal -u http://sample-cli-login -p Test1234 --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a

from azure.cli.core import get_default_cli
get_default_cli().invoke(['vm', 'list', '-g', 'groupname'])

How to run Azure CLI commands using python? get_default_cli

Set up authentication from SDK

from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.compute import ComputeManagementClient

client = get_client_from_cli_profile(ComputeManagementClient)

Installation Step

conda create -n peak python=3.6 pip install azure-cli

How to save the output of Azure-cli commands in a variable

login_successfull = get_default_cli().invoke(['login',
                                                          '--tenant', tenant,
                                                          '--username', self.username,
                                                          '--password', self.password]) == 0
tenant = 'mytenant.onmicrosoft.com'
cmd = AzureCmd('login', 'mypassword')
cmd.login(tenant)
cmd.list_vm(tenant)

General

List account

az account list -o table

Set subsrabtion

az account set $SUBSCRIPTION_ID

KeyVault

Show

az keyvault list -o table

List

az keyvault network-rule list --name <kv name> -o table

DDOS

List

az network ddos-protection list

NSG

List

az network nsg list -o table

Show

az network nsg rule list --nsg-name <nsg-name> -g <RG>

Show

az storage account list -o table

List

az storage account network-rule list --account-name <accountname>

Reference Power Shell Audit Resources