// 2020 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package mydp import ( "github.com/kolo/xmlrpc" ) type ( // PortInfo type is the struct representation of the port info details returned from the // switchinfo service that contains details about a switch-port as defined in admin.mydatapipe. PortInfo struct { PortID string `xmlrpc:"PortID"` SwitchPort string `xmlrpc:"SwitchPort"` DeviceID string `xmlrpc:"DeviceID"` PrimaryIP string `xmlrpc:"PrimaryIP"` SpecificDeviceType string `xmlrpc:"SpecificDeviceType"` Name string `xmlrpc:"Name"` End2Port string `xmlrpc:"end2port"` SW2Port string `xmlrpc:"sw2_port"` Class string `xmlrpc:"class"` PortType string `xmlrpc:"porttype"` ID string `xmlrpc:"id"` VlanName string `xmlrpc:"Vlan_Name"` VlanID string `xmlrpc:"VlanID"` SwitchID string `xmlrpc:"SwitchID"` SwitchName string `xmlrpc:"SwitchName"` } ) // GetSwitchInfoPort method calls out to the mydatapipe.switchinfo.Get(int portid) signature and // returns a structure of PortInfo details. func (c *Client) GetSwitchInfoPort(portID int) (PortInfo, error) { var result PortInfo client, err := xmlrpc.NewClient(c.url("xmlrpc/switchinfo.php"), nil) if err != nil { return result, err } err = client.Call("mydatapipe.switchinfo.Get", portID, &result) return result, err } // GetSwitchInfoList method calls out to the mydatapipe.switchinfo.List(int switchid) signature and // returns a list of structures containing PortInfo details for an entire switch. func (c *Client) GetSwitchInfoList(switchID int) ([]PortInfo, error) { var result []PortInfo client, err := xmlrpc.NewClient(c.url("xmlrpc/switchinfo.php"), nil) if err != nil { return result, err } err = client.Call("mydatapipe.switchinfo.List", switchID, &result) return result, err } // GetSwitchInfoByName method calls out to the mydatapipe.switchinfo.GetByName(string switchname, string portname) // signature and returns a structure of PortInfo details. func (c *Client) GetSwitchInfoByName(switchName, portName string) (PortInfo, error) { var result PortInfo client, err := xmlrpc.NewClient(c.url("xmlrpc/switchinfo.php"), nil) if err != nil { return result, err } err = client.Call("mydatapipe.switchinfo.GetByName", []interface{}{switchName, portName}, &result) return result, err }