gpt4 book ai didi

python - 语法无效 : Azure CLI with Python

转载 作者:行者123 更新时间:2023-12-01 07:42:22 24 4
gpt4 key购买 nike

提前致谢,我正在尝试更新 Azure VM。最终我的代码从 Azure key 保管库获取证书并将其保存在本地证书存储中。我已在 Bash 上使用 Azure CLI 成功完成任务。代码如下

secret=$(az keyvault secret list-versions --vault-name aqrahyhkeyvault --name certificatename --query "[?attributes.enabled].id" --output tsv)

vm_secret=$(az vm secret format --secrets "$secret" --resource-group RAH-AQ --keyvault aqrahyhkeyvault --certificate-store My)

az vm update -g Archive-WSL -n win10new --set osProfile.secrets="$vm_secret"

我使用相同的命令,将其包装在 Python 中,因为我的大部分代码都是这种格式。但它抛出无效的语法错误。我已经用双引号尝试了所有可能的更改并对其进行了洗牌,但没有成功

import subprocess
import json

def Update_vm(vault_name,certificate_name,rscgroup_name):
Secret_command=["az","keyvault","secret","list-versions","--vault-name",vault_name,"--name",certificate_name,"--query","[?attributes.enabled].id","--output","tsv"]
create_vm=subprocess.run(Secret_command, stdout=subprocess.PIPE, stderr = subprocess.PIPE)
print(create_vm.stdout)
vm_secret=["az","vm","secret","format","--secrets",create_vm.stdout,"--resource-group",rscgroup_name,"--keyvault",vault_name,"--certificate-store","My"]
vm_new_secret=subprocess.run(vm_secret, stdout=subprocess.PIPE, stderr = subprocess.PIPE)
print(vm_new_secret.stdout)

update_vm_cmd=["az","vm","update","-g",rscgroup_name,"-n",avm_name,"--set","osProfile.secrets"=vm_new_secret.stdout] //Error is present here saying invalid syntax
vm_update=subprocess.run(update_vm_cmd, stdout=subprocess.PIPE, stderr = subprocess.PIPE)


if __name__=="__main__":
rscgroup_name="vm-test-group"
avm_name="testvm1"
avm_image="Win2019Datacenter"
avm_username="azuretest"
avm_password="mypass"
avm_size="Standard_D2_V3"
vault_name = "aqrahkeyvault"
certificate_name = "staticwebsite"

Update_vm(vault_name,certificate_name,rscgroup_name)

最佳答案

我认为这可能是 "osProfile.secrets"=vm_new_secret.stdout 中字符串的格式化方式您可以尝试以下方法吗?

update_vm_cmd=["az","vm","update","-g",rscgroup_name,"-n",avm_name,"--set",f"osProfile.secrets={vm_new_secret.stdout}"]

关于python - 语法无效 : Azure CLI with Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56635890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com