简体   繁体   English

为Azure-PowerShell SDK制作python包装器是一个愚蠢的主意吗?

[英]Is making a python wrapper for the Azure-PowerShell SDK a stupid idea?

My opinion of the Azure-Python SDK is not high for Azure RM. 对于Azure RM,我对Azure-Python SDK的看法不高。 What takes 1 line in PowerShell takes 10 in Python. 在PowerShell中需要1行,在Python中需要10行。 That is the opposite of what python is supposed to do. 那与python应该做的相反。

So, my idea is to create python package which comes with a directory containing a few template .ps1 scripts. 因此,我的想法是创建一个python软件包,该软件包带有一个包含一些模板.ps1脚本的目录。 You would define a few variables like vmname, resourcegroup, location, etc... inject these into the .ps1 templates, then call commands from the REPL. 您将定义一些变量,例如vmname,resourcegroup,location等...将它们注入.ps1模板,然后从REPL调用命令。

Right now I'm having trouble using the subprocess module to keep PS open until I tell it to close. 现在,我在使用子流程模块来保持PS处于打开状态,直到我告诉它关闭之前遇到了麻烦。 As it stands now, I need to include 就目前而言,我需要包括

login-azurerm

and authenticate before running any command. 在运行任何命令之前进行身份验证。 This won't do. 这不会。 I'd like to fix this, but frankly right now I'm wondering whether or not the premise is a good idea to start with. 我想解决此问题,但坦率地说,现在我想知道前提是否是一个好主意。

Any input is much appreciated! 任何输入,不胜感激!

@RobTruxal, the new CLI for Azure will be in Python and will be released as a preview soon. @RobTruxal,适用于Azure的新CLI将使用Python,并将作为预览发布。 You can already try it from the github account: https://github.com/Azure/azure-cli 您已经可以从github帐户尝试它: https : //github.com/Azure/azure-cli

The Azure SDK for Python is not supposed to mimic the Powershell cmdlets, but to be a language SDK (like C#, Java, Ruby, etc.). 用于Python的Azure SDK不应模仿Powershell cmdlet,而应是一种语言SDK(例如C#,Java,Ruby等)。

If you have any suggestion/comments about the Python SDK itself, please do not hesitate to fill an issue on the issue tracker: https://github.com/Azure/azure-sdk-for-python/issues 如果您对Python SDK本身有任何建议/意见,请随时在问题跟踪器上填写问题: https : //github.com/Azure/azure-sdk-for-python/issues

(FYI, I'm the owner of the Python SDK repo at MS) (仅供参考,我是MS的Python SDK库的所有者)

@RobTruxal, It seems that a feasible way to call PowerShell in Python is using the module subprocess , such as the code below as reference. @RobTruxal,似乎在Python中调用PowerShell的一种可行方法是使用模块subprocess进程,例如下面的代码作为参考。

import subprocess
subprocess.call(["C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", "your-script.ps1", "arguments"])

You need to write your powershell script which includes login-azurerm command, and interaction with cmd that running python script. 您需要编写login-azurerm脚本,其中包括login-azurerm命令,以及与运行python脚本的cmd的交互。

Or you can choose the AzureCLI for cross platform in node.js as the command line tool for managing Azure Resoure. 或者,您可以在node.js中选择用于跨平台的AzureCLI作为管理Azure资源的命令行工具。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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