@@ -16,6 +16,7 @@ package openstack
16
16
17
17
import (
18
18
"fmt"
19
+ "io/ioutil"
19
20
"os"
20
21
"strings"
21
22
"time"
@@ -40,6 +41,8 @@ import (
40
41
41
42
"github.com/coreos/mantle/platform"
42
43
"github.com/coreos/mantle/util"
44
+
45
+ "gopkg.in/yaml.v2"
43
46
)
44
47
45
48
var (
@@ -80,26 +83,41 @@ type API struct {
80
83
networkClient * gophercloud.ServiceClient
81
84
}
82
85
83
- func New (opts * Options ) (* API , error ) {
84
- // The clientconfig library tries to find a clouds.yaml in:
85
- // 1. OS_CLIENT_CONFIG_FILE
86
- // 2. Current directory.
87
- // 3. unix-specific user_config_dir (~/.config/openstack/clouds.yaml)
88
- // 4. unix-specific site_config_dir (/etc/openstack/clouds.yaml)
89
- // See https://github.com/gophercloud/utils/blob/8677e053dcf1f05d0fa0a616094aace04690eb94/openstack/clientconfig/utils.go#L93-L112
90
- //
91
- // If the user provided a path to a config file set the
92
- // $OS_CLIENT_CONFIG_FILE env var to it.
86
+ // LoadCloudsYAML defines how to load a clouds.yaml file.
87
+ // By default, this calls the local LoadCloudsYAML function.
88
+ func (opts Options ) LoadCloudsYAML () (map [string ]clientconfig.Cloud , error ) {
93
89
if opts .ConfigPath != "" {
94
- os .Setenv ("OS_CLIENT_CONFIG_FILE" , opts .ConfigPath )
90
+ var clouds clientconfig.Clouds
91
+ if content , err := ioutil .ReadFile (opts .ConfigPath ); err != nil {
92
+ return nil , err
93
+ } else if err := yaml .Unmarshal (content , & clouds ); err != nil {
94
+ return nil , fmt .Errorf ("failed to unmarshal yaml %s: %v" , opts .ConfigPath , err )
95
+ }
96
+ return clouds .Clouds , nil
95
97
}
98
+ return clientconfig .LoadCloudsYAML ()
99
+ }
96
100
101
+ // LoadSecureCloudsYAML defines how to load a secure.yaml file.
102
+ // By default, this calls the local LoadSecureCloudsYAML function.
103
+ func (opts Options ) LoadSecureCloudsYAML () (map [string ]clientconfig.Cloud , error ) {
104
+ return clientconfig .LoadSecureCloudsYAML ()
105
+ }
106
+
107
+ // LoadPublicCloudsYAML defines how to load a public-secure.yaml file.
108
+ // By default, this calls the local LoadPublicCloudsYAML function.
109
+ func (opts Options ) LoadPublicCloudsYAML () (map [string ]clientconfig.Cloud , error ) {
110
+ return clientconfig .LoadPublicCloudsYAML ()
111
+ }
112
+
113
+ func New (opts * Options ) (* API , error ) {
97
114
if opts .Profile == "" {
98
115
opts .Profile = "openstack"
99
116
}
100
117
101
118
osOpts := & clientconfig.ClientOpts {
102
- Cloud : opts .Profile ,
119
+ Cloud : opts .Profile ,
120
+ YAMLOpts : opts ,
103
121
}
104
122
105
123
if opts .Region != "" {
0 commit comments