glesys/glesys-go

CloudConfigParams not properly encoded

norrland opened this issue · 0 comments

When creating a server with the CloudConfigParams field set to:
{"email": "foo@example.com", "hostname":"example.com", "myArg":"123lol"}

The API returns http/400 error: "The cloudconfigparams must be an array."

Full example:

Run with: GLESYS_USERID=CL12345 GLESYS_TOKEN=YOURTOKEN go run main.go

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/glesys/glesys-go/v5"
)

func main() {
	userid := os.Getenv("GLESYS_USERID")
	token := os.Getenv("GLESYS_TOKEN")
	agent := "servers-cc/0.1.0"

	client := glesys.NewClient(userid, token, agent)

	cloudconfig := "## template: glesys\n#cloud-config\n{{>users}}"
	cloudconfigparams := `{"email": "foo@example.com", "hostname":"example.com", "myArg":"123lol"}`

	users := []glesys.User{}
	users = append(users, glesys.User{
		Username:   "bob",
		Password:   "hunter2!",
		PublicKeys: []string{"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINOCh8br7CwZDMGmINyJgBip943QXgkf7XdXrDMJf5Dl bob@bob-machine"},
	})

	createParams := glesys.CreateServerParams{
		Bandwidth:         100,
		CloudConfig:       cloudconfig,
		CloudConfigParams: cloudconfigparams,
		CPU:               1,
		Memory:            1024,
		IPv4:              "any",
		IPv6:              "any",
		Users:             users,
		Platform:          "KVM",
		Template:          "Ubuntu 20.04 LTS (Focal Fossa)",
		Hostname:          "exampledata",
		DataCenter:        "Stockholm",
		Storage:           20,
	}

	server, err := client.Servers.Create(context.Background(), createParams)

	if err != nil {
		fmt.Printf("error creating server: %s", err)
	}

	fmt.Printf("Server --\n%#v\n--\n", server)
	fmt.Printf("ERR: --\n%#v--\n", err)
}