【问题标题】:Azure Python SDK- Spinup VM with cloud-initAzure Python SDK - 使用 cloud-init 启动 VM
【发布时间】:2018-10-17 14:02:20
【问题描述】:

我正在尝试使用 Azure SDK 使用 cloud-init 启动 VM。 脚本基于此示例:https://github.com/Azure-Samples/virtual-machines-python-manage/blob/master/example.py 我添加了以下内容:

with open(cloudinit, "r") as cl: clcont=cl.read() # CUSTOM_DATA=base64.b64encode(clcont.encode('utf-8')).decode('ascii') CUSTOM_DATA=clcont

在函数create_vm_parameters 的下一个添加: 'custom-data': CUSTOM_DATA

我尝试了以下示例:

  • 通过 base64、base64 ascii 解码以及纯脚本上下文。
  • os_profile 中提供custom-data 以及单独的块。

当尝试使用 az cli 启动 vm 时,cloud-init 脚本工作正常。 你有什么想法如何让它与 python sdk 一起工作吗?也许我在创建 vm 参数时将其添加到了不正确的部分?

【问题讨论】:

  • 您在哪里添加自定义数据?它在 os_profile 中吗?
  • 我都试过了:在 os_profile 和同一级别。两者都不起作用。

标签: python python-3.x azure virtual-machine azure-sdk


【解决方案1】:

由于没有人回答,我的同事解决了。

将 cloudinit 保存为 yaml 文件,并且:

clcont== '\n'.join([ '', yaml.dump(cloudinit), ]) CUSTOM_DATA = base64.b64encode(clcont.encode('utf-8')).decode('latin-1')

并把它放在os_profile:'custom_data': CUSTOM_DATA,

【讨论】:

    猜你喜欢
    • 2021-08-19
    • 2019-09-01
    • 2022-08-11
    • 1970-01-01
    • 2020-07-19
    • 1970-01-01
    • 2018-03-01
    • 2016-07-13
    • 2018-08-20
    相关资源
    最近更新 更多