Switchq and automation container's maas client updated to 2.0
Change-Id: I910ad20ca16b019788b920da79ed22a8ee825300
diff --git a/switchq/switchq.go b/switchq/switchq.go
index 7d3022b..4be1c31 100644
--- a/switchq/switchq.go
+++ b/switchq/switchq.go
@@ -30,7 +30,10 @@
"time"
)
-const appName = "SWITCHQ"
+const(
+ appName = "SWITCHQ"
+ massApiVersion = "2.0"
+)
type Config struct {
VendorsURL string `default:"file:///switchq/vendors.json" envconfig:"VENDORS_URL" desc:"URL that specifies supported vendor OUI information"`
@@ -383,7 +386,7 @@
if len(context.config.MaasURL) > 0 {
// Attempt to connect to MAAS
- authClient, err := maas.NewAuthenticatedClient(context.config.MaasURL, context.config.MaasKey, "1.0")
+ authClient, err := maas.NewAuthenticatedClient(context.config.MaasURL, context.config.MaasKey, massApiVersion)
checkError(err, "Unable to connect to MAAS at '%s' : %s", context.config.MaasURL, err)
context.maasClient = maas.NewMAAS(*authClient)
diff --git a/switchq/sync.go b/switchq/sync.go
index 4452c6f..1e9e035 100644
--- a/switchq/sync.go
+++ b/switchq/sync.go
@@ -73,20 +73,21 @@
}
all[i].Name = name
- mac_set_arr, err := device["macaddress_set"].GetArray()
- if len(mac_set_arr) != 1 {
- return nil, nil, fmt.Errorf("Expecting a single MAC address, recived %d", len(mac_set_arr))
+ iface_arr, err := device["interface_set"].GetArray()
+ if len(iface_arr) != 1 {
+ return nil, nil, fmt.Errorf("Expecting a single interface, recived %d", len(iface_arr))
}
- mac_obj, err := mac_set_arr[0].GetMap()
+ iface_obj, err := iface_arr[0].GetMap()
if err != nil {
return nil, nil, err
}
- mac, err := mac_obj["mac_address"].GetString()
+ mac, err := iface_obj["mac_address"].GetString()
if err != nil {
return nil, nil, err
}
+
mac = strings.ToUpper(mac)
all[i].MAC = mac
@@ -106,7 +107,7 @@
for list := range request {
// Get current device list and convert it to some maps for quick indexing
devices := c.maasClient.GetSubObject("devices")
- deviceObjects, err := devices.CallGet("list", url.Values{})
+ deviceObjects, err := devices.CallGet("", url.Values{})
if err != nil {
log.Errorf("Unable to synchronize switches to MAAS, unable to get current devices : %s",
err)
@@ -230,7 +231,7 @@
// The device does not currently exist in MAAS, so add it
log.Infof("Adding device '%s (%s)' to MAAS", rec.Name, rec.MAC)
- deviceObj, err := devices.CallPost("new", url.Values{
+ deviceObj, err := devices.CallPost("", url.Values{
"hostname": []string{rec.Name},
"mac_addresses": []string{rec.MAC},
})