Azure Python SDK- Spinup VM with cloud-init

自作多情 提交于 2019-12-11 17:43:00

问题


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") as cl: clcont=cl.read() # CUSTOM_DATA=base64.b64encode(clcont.encode('utf-8')).decode('ascii') CUSTOM_DATA=clcont

Next in the function create_vm_parameters added: 'custom-data': CUSTOM_DATA

I have tried following examples:

  • passed base64, base64 ascii decoded as well as plain script context.
  • provide custom-data in os_profile as well as separated block.

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?


回答1:


Since no one has answer, my colleague solved it.

Saved cloudinit as yaml file, and:

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

And put it in os_profile: 'custom_data': CUSTOM_DATA,



来源:https://stackoverflow.com/questions/52856792/azure-python-sdk-spinup-vm-with-cloud-init

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!