vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
150 stars 33 forks source link

Improve the Xen orchestra go client's API design #189

Open ddelnano opened 2 years ago

ddelnano commented 2 years ago

While working on #179 and past tasks, it's become apparent that the XO client (github.com/terra-farm/terraform-provider-xenorchestra/client module) has an inconsistent API design.

API calls that operate on VMs typically require a deeply nested struct (as seen below and here)

    vm, err := c.CreateVm(client.Vm{
        AffinityHost:      d.Get("affinity_host").(string),
        BlockedOperations: blockedOperations,
        Boot: client.Boot{
            Firmware: d.Get("hvm_boot_firmware").(string),
        },
        ExpNestedHvm:    d.Get("exp_nested_hvm").(bool),
        NameLabel:       d.Get("name_label").(string),
        NameDescription: d.Get("name_description").(string),
        Template:        d.Get("template").(string),
        CloudConfig:     d.Get("cloud_config").(string),
        ResourceSet:     rs,
        CPUs: client.CPUs{
            Number: d.Get("cpus").(int),
        },
        CloudNetworkConfig: d.Get("cloud_network_config").(string),
        Memory: client.MemoryObject{
            Static: []int{
                0, d.Get("memory_max").(int),
            },
        },
        Tags:         vmTags,
        Disks:        ds,
        Installation: installation,
        // TODO: (#145) Uncomment this once issues with secure_boot have been figured out
        // SecureBoot:   d.Get("secure_boot").(bool),
        VIFsMap:    network_maps,
        StartDelay: d.Get("start_delay").(int),
        WaitForIps: d.Get("wait_for_ip").(bool),
        Videoram: client.Videoram{
            Value: d.Get("videoram").(int),
        },
        Vga: d.Get("vga").(string),
    },
        d.Timeout(schema.TimeoutCreate),
    )

This differs from the rest of the XO client API and it makes it awkward to use. This issue is to investigate ways to make the API design more consistent and implement the changes