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