Azure Python SDK - 带 cloud-init 的 Spinup VM [英] Azure Python SDK- Spinup VM with cloud-init
问题描述
我正在尝试使用 Azure SDK 通过 cloud-init 启动 VM.脚本基于此示例:https://github.com/Azure-Samples/virtual-machines-python-manage/blob/master/example.py 我添加了以下内容:
I'm trying to spin up VM with cloud-init using Azure SDK. Script is based on this example: https://github.com/Azure-Samples/virtual-machines-python-manage/blob/master/example.py I have added following:
with open(cloudinit, "r") 作为 cl:clcont=cl.read()# CUSTOM_DATA=base64.b64encode(clcont.encode('utf-8')).decode('ascii')CUSTOM_DATA=clcont
接下来在 create_vm_parameters
函数中添加:'custom-data': CUSTOM_DATA
Next in the function create_vm_parameters
added:
'custom-data': CUSTOM_DATA
我尝试了以下示例:
- 通过 base64、base64 ascii 解码以及纯脚本上下文.
- 在
os_profile
中提供custom-data
以及分隔块.
- passed base64, base64 ascii decoded as well as plain script context.
- provide
custom-data
inos_profile
as well as separated block.
当尝试使用 az cli
启动 vm 时,cloud-init 脚本工作正常.你有什么想法如何让它与python sdk一起工作吗?也许我在创建 vm 参数时将它添加到了不正确的部分?
When trying to spin up vm with az cli
, the cloud-init script works fine.
Do you have any ideas how to make it work with python sdk? Perhaps I am adding it in the incorrect section while creating the vm parameters?
推荐答案
既然没人回答,我同事就解决了.
Since no one has answer, my colleague solved it.
将 cloudinit 保存为 yaml 文件,并且:
Saved cloudinit as yaml file, and:
clcont== '\n'.join(['', yaml.dump(cloudinit), ])CUSTOM_DATA = base64.b64encode(clcont.encode('utf-8')).decode('latin-1')
并将其放入os_profile
: 'custom_data': CUSTOM_DATA,
这篇关于Azure Python SDK - 带 cloud-init 的 Spinup VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!