问题
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
inos_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