// 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 ( // EtherPort defines the connection information for a single port, // associated to a device in admin.mydatapipe. This is similar to the location // assignment EtherPort struct { End1Port string `xmlrpc:"end1port"` Device1ID string `xmlrpc:"Device1_ID"` Device1Name string `xmlrpc:"Device1_Name"` Device1PrimaryIP string `xmlrpc:"Device1_PrimaryIP"` End2Port string `xmlrpc:"end2port"` Device2ID string `xmlrpc:"Device2_ID"` Device2Name string `xmlrpc:"Device2_Name"` Device2PrimaryIP string `xmlrpc:"Device2_PrimaryIP"` Class string `xmlrpc:"class"` } // EtherPortAdd type defines the structure to post to the mydatapipe.ether.Add service EtherPortAdd struct { End1 End `xmlrpc:"end1"` End2 End `xmlrpc:"end2"` // class of ethernet port, one of: ("internal", "external", "backup", "heartbeat", "VM") Class string `xmlrpc:"class"` } // End type contains the parameters about a specific end of the // cable in a connection. End struct { // ID based on type: Server ID, Switch ID, Firewall ID, Hub ID, Storage Array ID, Router ... ID string `xmlrpc:"id"` // name of port - must be unique per device Port string `xmlrpc:"port"` // type of device ("server", "switch", "firewall", "hub", "storage array", "router" ...) Type string `xmlrpc:"type"` } ) // EtherListByDevice method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.ether.EtherListByDevice func (c *Client) EtherListByDevice(deviceID int) ([]EtherPort, error) { client, err := xmlrpc.NewClient(c.url("xmlrpc/ether.php"), nil) if err != nil { return nil, err } var result []EtherPort err = client.Call("mydatapipe.ether.EtherListByDevice", deviceID, &result) return result, err } // EtherAdd method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.ether.Add func (c *Client) EtherAdd(e EtherPortAdd) (interface{}, error) { client, err := xmlrpc.NewClient(c.url("xmlrpc/ether.php"), nil) if err != nil { return nil, err } var result interface{} err = client.Call("mydatapipe.ether.Add", []interface{}{e.End1, e.End2, e.Class}, &result) return result, err }