canonical / gomaasclient

Go MAAS client
Apache License 2.0
23 stars 28 forks source link

Cannot pass multiple mac addresses when adding a machine #83

Closed gnuoy closed 3 months ago

gnuoy commented 5 months ago

Maas supports specifying multiple mac addresses when manually adding a machine "... To specify more than one MAC address, the parameter must be specified twice." *1. However, there seems to be no way to do this with via the gomaasclient. "PXEMacAddress" is a string type and is passed verbatum in the request.

It can be worked around using the deprecated api client by calling qsp.Add("mac_addresses", mac) for each mac address to be added. Something like:

        qsp, err := query.Values(machineParams)
    if err != nil {
        return nil, err
    }
    qsp.Add("mac_addresses", mac1)
    qsp.Add("mac_addresses", mac2)
    machineAPI := apiClient.GetSubObject("machines")
    err = apiClient.Post("", qsp, func(data []byte) error {
        return json.Unmarshal(data, machine)
    })

1 https://github.com/canonical/maas/blob/master/src/maasserver/api/machines.py#L1847 2 https://github.com/canonical/gomaasclient/blob/master/entity/machine.go#L215