简体   繁体   中英

Running Azure-cli commands from python script

I have these azure-cli2 (which is python based) commands for creating rbac user and few other activities

az ad user create --display-name "user" --password Pass@word1 --user-principal-name "user@test.onmicrosoft.com"  --mail-nickname user
az role assignment create --role Contributor --assignee "user@test.onmicrosoft.com"
az ad sp create-for-rbac -n "testapp"

I am using the subprocess.check_output() to run these commands from python.

Is there any way directly initiate azure-cli commands from python

I am expecting for something like this:

import azure-core-cli
azure-core-cli.mycommand(param)

PS: I know ,I can get same functionality using azure Python SDK

Based on this file , try:

from azure.cli.core import get_default_cli

get_default_cli().invoke(['ad', 'user', 'create', '--display-name', 'user', ...])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM