package migrationAPI import ( "fmt" "net/http" "net/url" "strconv" "strings" "github.rackspace.com/gorax/clients/dcxAutohost" ) // VlanTranslations client calls the /vlan_translations/:environment resource from the migration API, which // acts as a proxy to first attempt to gather vlan translations from the migration database, can fallback to // the DCX API for migration vlans if a record does not exit. func (c *Client) VlanTranslations(environment string) ([]dcxAutohost.EnvironmentMigrationVlan, error) { uri := fmt.Sprintf("%s/vlan_translations/%s", c.URL, url.PathEscape(environment)) req, err := c.newRequest(uri, http.MethodGet, nil, new(Options)) if err != nil { return nil, err } resp := new([]dcxAutohost.EnvironmentMigrationVlan) if err = c.do(req, resp, new(Options)); err != nil { return nil, err } return *resp, nil } // PortMaps client calls the /port_maps?device_numbers= resource from the migration API, which // acts as a proxy to first attempt to gather device port-maps from the migration database, can fallback to // the DCX API for port-maps if a record does not exit. func (c *Client) PortMaps(devices []int) ([]dcxAutohost.DevicePortMap, error) { req, err := c.newRequest(fmt.Sprintf("%s/port_maps", c.URL), http.MethodGet, nil, new(Options)) if err != nil { return nil, err } req.URL.RawQuery = url.Values{"device_numbers": []string{splitToString(devices)}}.Encode() resp := new([]dcxAutohost.DevicePortMap) if err = c.do(req, resp, new(Options)); err != nil { return nil, err } return *resp, nil } func splitToString(a []int) string { if len(a) == 0 { return "" } b := make([]string, len(a)) for i, v := range a { b[i] = strconv.Itoa(v) } return strings.Join(b, ",") }