exoscale / python-exoscale

Python bindings for the Exoscale APIs
https://exoscale.github.io/python-exoscale/
ISC License
14 stars 7 forks source link

user_data parameter in create_instance returns "bad request" #60

Closed astuanax closed 2 months ago

astuanax commented 2 months ago

I am unable to create a server and provide user_data in cloud-init format. Using API v2, version: 0.8, and the function create_instance

Cloud init script and code to test:

script = """#!/bin/bash echo "Test" """

ubuntu = c.create_instance( public_ip_assignment="inet4", security_groups=[{"id": SECURITY_GROUP_ID}], name="demo2", instance_type={"id": INSTANCE_TYPE_ID}, template={"id": TEMPLATE_ID}, ssh_keys=[{"name": SSH_KEY_NAME}], disk_size=50, user_data=script)

{'message': 'bad request'}

When removing the user_data parameter the function works fine, and the result is a new server. Adding the user_data back and it breaks.

Tested with several formats listed here: https://cloudbase-init.readthedocs.io/en/latest/userdata.html#bash

script = """#!/usr/bin/env python

print("test") """ Same problem.

Cloud config: script = """#cloud-config runcmd:

Same issue.

astuanax commented 2 months ago

Seem the API v2 is no longer encoding the string. Encoding the string beforehand, seems to have done the trick.

Might need some adjustments in the documentation to document this change in behavior.

tgrondier commented 2 months ago

Hi @astuanax, thanks for your bug report! We are updating the API V2 description in the next release to clarify that user-data must be base64 encoded :)