//nolint:golint package dcxAutohost import ( "encoding/json" "net/url" ) type ( // DeviceSwitchPorts tpe is the decoded type used for the companies switch_ports // DCX API call. DeviceSwitchPorts struct { Device string `json:"device_number" bson:"device_number"` SwitchPorts []*switchPort `json:"switch_port" bson:"switch_port"` } switchPort struct { SwitchPortData struct { ConfigNumber string `json:"configuration_number" bson:"configuration_number"` DeviceAccountNum string `json:"device_account_number" bson:"device_account_number"` DeviceNumber string `json:"device_number" bson:"device_number"` PortNumber int `json:"port_number" bson:"port_number"` PortType string `json:"port_type" bson:"port_type"` SwitchName string `json:"switch_name" bson:"switch_name"` } `json:"switch_port" bson:"switch_port"` } DeviceAndMAC struct { Device int `json:"device_number" bson:"device_number"` MACs []string `json:"mac_addresses" bson:"mac_addresses"` InterfaceType string `json:"interface_type" bson:"interface_type"` } ) // SwitchPorts method will return a DeviceSwitchPorts type that contains the switch // ports for a given device number // // See: https://pages.github.rackspace.com/dcx/gateway/#/companies/deviceSwitchPorts func (a *Client) SwitchPorts(device string) (*DeviceSwitchPorts, error) { body, err := a.get("/companies/rackspace/devices/"+device+"/switch_ports.json", nil) if err != nil { return nil, err } dsp := DeviceSwitchPorts{ Device: device, } if err = json.Unmarshal(body, &dsp.SwitchPorts); err != nil { return nil, err } return &dsp, nil } // DeviceAndMACs method will return a DeviceAndMACs type that contains the switch // ports for a given device number // // See: https://pages.github.rackspace.com/dcx/gateway/#/companies/deviceSwitchPorts func (a *Client) DeviceAndMACs(switchName, portNumber string) (DeviceAndMAC, error) { body, err := a.get("/switch_ports/device_and_macs", url.Values{"switch_name": []string{switchName}, "port_number": []string{portNumber}}) if err != nil { return DeviceAndMAC{}, err } var resp DeviceAndMAC if err = json.Unmarshal(body, &resp); err != nil { return DeviceAndMAC{}, err } return resp, nil }