@@ -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 (
49
52
type Options struct {
50
53
* platform.Options
51
54
52
- // Config file. Defaults to $HOME/.config/openstack.json .
55
+ // Config file. The path to a clouds.yaml file .
53
56
ConfigPath string
54
57
// Profile name
55
58
Profile string
@@ -80,14 +83,41 @@ type API struct {
80
83
networkClient * gophercloud.ServiceClient
81
84
}
82
85
83
- func New (opts * Options ) (* API , error ) {
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 ) {
89
+ if 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
97
+ }
98
+ return clientconfig .LoadCloudsYAML ()
99
+ }
84
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 ) {
85
114
if opts .Profile == "" {
86
115
opts .Profile = "openstack"
87
116
}
88
117
89
118
osOpts := & clientconfig.ClientOpts {
90
- Cloud : opts .Profile ,
119
+ Cloud : opts .Profile ,
120
+ YAMLOpts : opts ,
91
121
}
92
122
93
123
if opts .Region != "" {
0 commit comments