Skip to content

Commit bb9bebf

Browse files
dustymabejlebon
authored andcommitted
mantle/openstack: point bindings to OpenStack config file
We need to tell the OpenStack bindings where to find the user-provided `clouds.yaml` file. Do this using the `YAMLOpts` field of the `ClientOpts`. See also discussions in coreos#1840.
1 parent 0ea928d commit bb9bebf

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

mantle/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ require (
4747
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f
4848
golang.org/x/text v0.3.3
4949
google.golang.org/api v0.34.0
50+
gopkg.in/yaml.v2 v2.3.0
5051
)
5152

5253
replace google.golang.org/cloud => cloud.google.com/go v0.0.0-20190220171618-cbb15e60dc6d

mantle/platform/api/openstack/api.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package openstack
1616

1717
import (
1818
"fmt"
19+
"io/ioutil"
1920
"os"
2021
"strings"
2122
"time"
@@ -40,6 +41,8 @@ import (
4041

4142
"github.com/coreos/mantle/platform"
4243
"github.com/coreos/mantle/util"
44+
45+
"gopkg.in/yaml.v2"
4346
)
4447

4548
var (
@@ -49,7 +52,7 @@ var (
4952
type Options struct {
5053
*platform.Options
5154

52-
// Config file. Defaults to $HOME/.config/openstack.json.
55+
// Config file. The path to a clouds.yaml file.
5356
ConfigPath string
5457
// Profile name
5558
Profile string
@@ -80,14 +83,41 @@ type API struct {
8083
networkClient *gophercloud.ServiceClient
8184
}
8285

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+
}
84100

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) {
85114
if opts.Profile == "" {
86115
opts.Profile = "openstack"
87116
}
88117

89118
osOpts := &clientconfig.ClientOpts{
90-
Cloud: opts.Profile,
119+
Cloud: opts.Profile,
120+
YAMLOpts: opts,
91121
}
92122

93123
if opts.Region != "" {

0 commit comments

Comments
 (0)