Skip to content

Conversation

@vishesh92
Copy link
Member

@vishesh92 vishesh92 commented Nov 28, 2025

Fixes #104

Details

This pull request updates the way userdatadetails are serialized to URL parameters across several CloudStack API parameter structs. Instead of using fixed .key and .value fields, the code now dynamically uses the map key as the parameter name, improving flexibility and aligning with expected API conventions. The code generator is also updated to reflect this change, ensuring future code generation remains consistent.

Parameter serialization changes:

  • Updated all usages of userdatadetails in toURLValues() methods to serialize each key-value pair as userdatadetails[i].<key>=<value> instead of userdatadetails[i].key=<key> and userdatadetails[i].value=<value>. This affects:
    • DeployVirtualMachineParams (cloudstack/VirtualMachineService.go)
    • UpdateVirtualMachineParams (cloudstack/VirtualMachineService.go)
    • ResetUserDataForVirtualMachineParams (cloudstack/VirtualMachineService.go)
    • DeployVnfApplianceParams (cloudstack/VirtualNetworkFunctionsService.go)
    • CreateAutoScaleVmProfileParams (cloudstack/AutoScaleService.go)
    • UpdateAutoScaleVmProfileParams (cloudstack/AutoScaleService.go)

Code generation update:

  • Modified the code generator (generate/generate.go) to emit the new serialization logic for userdatadetails, ensuring future generated code uses the correct format.

I used the below script for testing.

package main

import (
	"fmt"
	"log"

	"github.com/apache/cloudstack-go/v2/cloudstack"
)

func main() {
	cs := cloudstack.NewAsyncClient("API",
		"access-key",
		"secret",
		false)

	// Create a new parameter struct
	p := cs.VirtualMachine.NewDeployVirtualMachineParams("fa2e4525-307e-4882-921c-52c1353b2c12", "3abf9626-c94e-11f0-a79a-1e0058000137", "4ad5637c-b7f4-498c-8ebd-299ea07b9d2c")
	p.SetNetworkids([]string{"cfccbcc7-cc55-4b55-ae63-57cc5d772589"})

	p.SetUserdatadetails(map[string]string{
		"vm_id": "t",
		"abc":   "abc",
		"xy":    "xy",
	})

	p.SetStartvm(false)

	r, err := cs.VirtualMachine.DeployVirtualMachine(p)
	if err != nil {
		log.Fatalf("Error deploying the virtual machine %s", err)
	}

	fmt.Printf("UUID or the deployed virtual machine: id: %s, %+v", r.Id, r)
}

Used this to create the VM before and after the changes.
image

7 is after the changes
8 is before

Copy link
Contributor

@sureshanaparti sureshanaparti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

Copy link
Contributor

@Pearl1594 Pearl1594 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@sureshanaparti
Copy link
Contributor

sureshanaparti commented Nov 28, 2025

verified tests from @vishesh92

@sureshanaparti sureshanaparti merged commit 1b6b293 into apache:main Nov 28, 2025
3 checks passed
@sureshanaparti sureshanaparti deleted the fix-userdatadetails branch November 28, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error to create metadata files with userdatadetails

3 participants