blob: ef058c8ba362793c6da8b2ed342327e0a90a6dbb [file] [log] [blame]
Torrent Glenn12bc4df2014-02-03 13:26:41 -08001package gophercloud
2
3import(
Marc Abramowitz91db07c2014-08-12 16:27:44 -07004 "fmt"
Torrent Glenn12bc4df2014-02-03 13:26:41 -08005 "github.com/mitchellh/mapstructure"
6)
7
8//The default generic openstack api
9var OpenstackApi = map[string]interface{}{
Mohammed Naser15f7ac72014-06-07 18:00:16 -040010 "Name": "nova",
Torrent Glenn12bc4df2014-02-03 13:26:41 -080011 "UrlChoice": PublicURL,
12}
13
14// Api for use with rackspace
15var 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
24func 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 Abramowitz91db07c2014-08-12 16:27:44 -070037
38 default:
39 var err = fmt.Errorf(
40 "PopulateApi: Unknown variant %# v; legal values: \"openstack\", \"rackspace\"", variant)
41 return Api, err
Torrent Glenn12bc4df2014-02-03 13:26:41 -080042 }
43
44 err := mapstructure.Decode(variantMap,&Api)
45 if err != nil{
46 return Api,err
47 }
48 return Api, err
49}