// 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 ( // Datacenter type defines the information related to a specific DC // that exist within admin.mydatapipe Datacenter struct { Title string `xmlrpc:"Title"` LocationID string `xmlrpc:"LocationID"` DatacenterID string `xmlrpc:"DatacenterID"` DateLastModified string `xmlrpc:"DatacenterID"` DateCreated string `xmlrpc:"DateCreated"` WhoModified string `xmlrpc:"WhoModified"` WhoCreated string `xmlrpc:"WhoCreated"` } // Location type defines the information related to a specific DC location // that exist within admin.mydatapipe Location struct { Title string `xmlrpc:"Title"` LocationID string `xmlrpc:"LocationID"` AirportCode string `xmlrpc:"AirportCode"` } // Rack type defines the information related to a specific rack // that exist within admin.mydatapipe Rack struct { Title string `xmlrpc:"Title"` Description string `xmlrpc:"Description"` CageID string `xmlrpc:"CageID"` RackID string `xmlrpc:"RackID"` DateLastModified string `xmlrpc:"DateLastModified"` DateCreated string `xmlrpc:"DateCreated"` WhoModified string `xmlrpc:"WhoModified"` WhoCreated string `xmlrpc:"WhoCreated"` RackTypeID string `xmlrpc:"RackTypeID"` RackTypeTitle string `xmlrpc:"RackType_Title"` DatacenterID string `xmlrpc:"DatacenterID"` LocationID string `xmlrpc:"LocationID"` } ) // DatacenterList method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.datacenter.DatacenterList func (c *Client) DatacenterList() ([]Datacenter, error) { client, err := xmlrpc.NewClient(c.url("xmlrpc/datacenter.php"), nil) if err != nil { return nil, err } var result []Datacenter err = client.Call("mydatapipe.datacenter.DatacenterList", nil, &result) return result, err } // LocationList method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.location.LocationList func (c *Client) LocationList() ([]Location, error) { client, err := xmlrpc.NewClient(c.url("xmlrpc/location.php"), nil) if err != nil { return nil, err } var result []Location err = client.Call("mydatapipe.location.LocationList", nil, &result) return result, err } // RackList method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.rack.RackList func (c *Client) RackList(offset int) ([]Rack, error) { client, err := xmlrpc.NewClient(c.url("xmlrpc/rack.php"), nil) if err != nil { return nil, err } var result []Rack err = client.Call("mydatapipe.rack.RackList", offset, &result) return result, err } // RackListAll method uses the *mydp.Client to invoke an XMLRPC call to the // Service: mydatapipe.rack.RackList func (c *Client) RackListAll() ([]Rack, error) { var ( offset = 0 resp = make([]Rack, 0) ) for { r, err := c.RackList(offset) if err != nil { return nil, err } resp = append(resp, r...) if len(r) < 1000 { break } offset += 1000 } return resp, nil }