简体   繁体   English

使用 python 脚本运行 Helm 命令

[英]Run Helm commands using python script

I wanted to run "helm repo add datawire https://app.getambassador.io " using python scripts.我想使用 python 脚本运行“helm repo add datawire https://app.getambassador.io ”。 I researched and found this link https://github.com/andriisoldatenko/pyhelm/blob/master/pyhelm/repo.py .我研究并找到了这个链接https://github.com/andriisoldatenko/pyhelm/blob/master/pyhelm/repo.py But I didn't found that I needed.但我没有发现我需要。 Could you help me with that?你能帮我解决这个问题吗?

If you want to run commands with Python, the best way is to use subprocess , it's very easy and works great, usually.如果您想使用 Python 运行命令,最好的方法是使用subprocess ,它通常非常简单并且效果很好。

Here's an example:这是一个例子:

import subprocess

subprocess.check_call(['helm',  'repo' 'add', 'datawire', 'https://app.getambassador.io/'])

Notice that this will just call the helm client and wait for it to complete.请注意,这只会调用 helm 客户端并等待它完成。 If the command which you started returns with error, then an Exception will be thrown.如果您启动的命令返回错误,则会抛出Exception

If you instead need the stdout output of the command, you can instead use check_output .如果您需要命令的stdout output ,则可以改用check_output


Subprocess documentation can be found here子流程文档可以在这里找到

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

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