这个包提供了代理类,用于直接从Python调用azure命令。

AzurePyProx的Python项目详细描述


az pyproxy公司

这个Python包提供了一个代理类,用于直接从Python调用az命令。在

要求

安装

通过PIP

pip3 install azpyproxy

或者

^{pr2}$

源代码构建

wget https://github.com/tomasvotava/az-pyproxy/archive/master.zipunzip master.zipcd az-pyproxy-masterpython setup.py buildpython setup.py install

使用

fromazure_pyproxyimportAzureaz=Azure()# command: az vm start virtualaz.vm_start("virtual")# additional flags and parameters# next method call expands like this:# az resource list --resource-group="YOUR_RESOURCE_GROUP"az.resource_list(resource_group="YOUR_RESOURCE_GROUP")# positional arguments are simply concatenated after the command call, so commands can be also passed as argumentsaz.vm("deallocate",name="virtual",resource_group="YOUR_RESOURCE_GROUP")# expands as:# az vm deallocate --name="virtual" --resource_group="YOUR_RESOURCE_GROUP"# by default, underscores in flag names are replaced with dashesaz.vm_deallocate(name="virtual",resource_group="YOUR_RESOURCE_GROUP")# az vm deallocate --name="virtual" --resource_group="YOUR_RESOURCE_GROUP"# however, this can be overriden by specifying replace_underscore=Falseaz.vm_deallocate(name="virtual",resource_group="YOUR_RESOURCE_GROUP",replace_underscore=False)# az vm deallocate --name="virtual" --resource_group="YOUR_RESOURCE_GROUP"# the command returns json output from the commands, if you would like to redirect stdout/stderr/stdin instead, just pass keep_output=Trueaz.vm_deallocate(name="virtual",resource_group="YOUR_RESOURCE_GROUP",keep_stdout=True)# Returns True/False based on errorcode of the command, prints all output

默认订阅和资源组

如果您不想在每次调用中指定subscription/resource_group,并且没有使用az命令或azurewebui设置默认值,则可以使用为您设计的类方法来处理它。在

fromazure_pyproxyimportAzureaz=Azure()# Shows your default subscriptionaz.account_show()az.account_show(subscription="another_subscription")# Shows your "another_subscription"Azure.set_subscription("another_subscription")az.account_show()# Shows your "another_subscription"# If you have set your subscription using Azure.set_subscription# and you need to use few calls using another one,# you can always specify your subscription as a parameter (this overrides default setting)Azure.set_subscription("another_subscription")az.account_show(subscription="yet_another_one")# Shows info for "yet_another_one"# In case you want to switch back to your az default, you can reset your subscription:Azure.reset_subscription()

上述所有操作也适用于资源组:

fromazure_pyproxyimportAzureaz=Azure()Azure.set_resource_group("resource-group")az.vm_start(name="virtual")

上面的代码启动资源组resource-group中名为virtual的VM。以下代码为您重置设置:

Azure.reset_resource_group()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用Ibatis在插入时返回ID(使用返回关键字)   java(org.hibernate.TransactionException)org。冬眠TransactionException:事务未成功启动   java小程序jwindow始终位于JNLP顶部   在Java中重新解析JSON对象?   java单击后将ListView数据移动到新屏幕   Mule ESB中的java WSA寻址特性   Java,对象编程:获取返回0值的方法   hibernate的Java通用问题,如何处理T get(K id)   java在使用超级CSV读取CSV时忽略引用   ssh使用Java远程运行命令   java如何向具体用户发送websocket消息?   在JAVA中,我可以在不指定的情况下使用条件运算符吗?