Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | ) |
| 6 | |
| 7 | //The default generic openstack api |
| 8 | var OpenstackApi = map[string]interface{}{ |
Mohammed Naser | 15f7ac7 | 2014-06-07 18:00:16 -0400 | [diff] [blame] | 9 | "Name": "nova", |
Jon Perritt | 816d2a0 | 2014-03-11 20:49:46 -0500 | [diff] [blame] | 10 | "UrlChoice": PublicURL, |
| 11 | } |
| 12 | |
| 13 | // Api for use with rackspace |
| 14 | var RackspaceApi = map[string]interface{}{ |
| 15 | "Name": "cloudServersOpenStack", |
| 16 | "VersionId": "2", |
| 17 | "UrlChoice": PublicURL, |
| 18 | } |
| 19 | |
| 20 | //Populates an ApiCriteria struct with the api values |
| 21 | //from one of the api maps |
| 22 | func PopulateApi(variant string) (ApiCriteria, error) { |
| 23 | var Api ApiCriteria |
| 24 | var variantMap map[string]interface{} |
| 25 | |
| 26 | switch variant { |
| 27 | case "": |
| 28 | variantMap = OpenstackApi |
| 29 | |
| 30 | case "openstack": |
| 31 | variantMap = OpenstackApi |
| 32 | |
| 33 | case "rackspace": |
| 34 | variantMap = RackspaceApi |
| 35 | } |
| 36 | |
| 37 | err := mapstructure.Decode(variantMap, &Api) |
| 38 | if err != nil { |
| 39 | return Api, err |
| 40 | } |
| 41 | return Api, err |
| 42 | } |