Skip to content

Commit b5eb5d6

Browse files
dustymabeopenshift-merge-robot
authored andcommitted
mantle: use clientconfig from github.com/gophercloud/utils for openstack auth
We can use the clientconfig package to read/parse a clouds.yaml file with the information needed to connect to the corresponding OpenStack cloud.
1 parent a52b03f commit b5eb5d6

File tree

35 files changed

+19150
-108
lines changed

35 files changed

+19150
-108
lines changed

mantle/auth/openstack.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

mantle/cmd/kola/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ func init() {
117117
sv(&kola.GCEOptions.JSONKeyFile, "gce-json-key", "", "use a service account's JSON key for authentication")
118118

119119
// openstack-specific options
120-
sv(&kola.OpenStackOptions.ConfigPath, "openstack-config-file", "", "OpenStack config file (default \"~/"+auth.OpenStackConfigPath+"\")")
121-
sv(&kola.OpenStackOptions.Profile, "openstack-profile", "", "OpenStack profile (default \"default\")")
120+
sv(&kola.OpenStackOptions.ConfigPath, "openstack-config-file", "", "Path to a clouds.yaml formatted OpenStack config file. The underlying library defaults to ./clouds.yaml")
121+
sv(&kola.OpenStackOptions.Profile, "openstack-profile", "", "OpenStack profile within clouds.yaml (default \"openstack\")")
122122
sv(&kola.OpenStackOptions.Region, "openstack-region", "", "OpenStack region")
123123
sv(&kola.OpenStackOptions.Image, "openstack-image", "", "OpenStack image ref")
124124
sv(&kola.OpenStackOptions.Flavor, "openstack-flavor", "1", "OpenStack flavor ref")

mantle/cmd/ore/openstack/openstack.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/coreos/pkg/capnslog"
2121
"github.com/spf13/cobra"
2222

23-
"github.com/coreos/mantle/auth"
2423
"github.com/coreos/mantle/cli"
2524
"github.com/coreos/mantle/platform/api/openstack"
2625
)
@@ -38,8 +37,8 @@ var (
3837
)
3938

4039
func init() {
41-
OpenStack.PersistentFlags().StringVar(&options.ConfigPath, "config-file", "", "config file (default \"~/"+auth.OpenStackConfigPath+"\")")
42-
OpenStack.PersistentFlags().StringVar(&options.Profile, "profile", "", "profile (default \"default\")")
40+
OpenStack.PersistentFlags().StringVar(&options.ConfigPath, "config-file", "", "Path to a clouds.yaml formatted OpenStack config file. The underlying library defaults to ./clouds.yaml")
41+
OpenStack.PersistentFlags().StringVar(&options.Profile, "profile", "", "OpenStack profile within clouds.yaml (default \"openstack\")")
4342
cli.WrapPreRun(OpenStack, preflightCheck)
4443
}
4544

mantle/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
682682
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
683683
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
684684
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
685+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
685686
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
686687
gopkg.in/yaml.v3 v3.0.0-20190502103701-55513cacd4ae/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
687688
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

mantle/platform/api/openstack/api.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import (
3434
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
3535
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
3636
"github.com/gophercloud/gophercloud/pagination"
37+
"github.com/gophercloud/utils/openstack/clientconfig"
3738
utilsSecurityGroups "github.com/gophercloud/utils/openstack/networking/v2/extensions/security/groups"
3839

39-
"github.com/coreos/mantle/auth"
4040
"github.com/coreos/mantle/platform"
4141
"github.com/coreos/mantle/util"
4242
)
@@ -80,60 +80,40 @@ type API struct {
8080
}
8181

8282
func New(opts *Options) (*API, error) {
83-
profiles, err := auth.ReadOpenStackConfig(opts.ConfigPath)
84-
if err != nil {
85-
return nil, fmt.Errorf("couldn't read OpenStack config: %v", err)
86-
}
8783

8884
if opts.Profile == "" {
89-
opts.Profile = "default"
90-
}
91-
profile, ok := profiles[opts.Profile]
92-
if !ok {
93-
return nil, fmt.Errorf("no such profile %q", opts.Profile)
85+
opts.Profile = "openstack"
9486
}
9587

96-
if opts.Domain == "" {
97-
opts.Domain = profile.Domain
88+
osOpts := &clientconfig.ClientOpts{
89+
Cloud: opts.Profile,
9890
}
9991

100-
osOpts := gophercloud.AuthOptions{
101-
IdentityEndpoint: profile.AuthURL,
102-
TenantID: profile.TenantID,
103-
TenantName: profile.TenantName,
104-
Username: profile.Username,
105-
Password: profile.Password,
106-
DomainID: opts.Domain,
92+
if opts.Region != "" {
93+
osOpts.RegionName = opts.Region
10794
}
10895

109-
provider, err := openstack.AuthenticatedClient(osOpts)
96+
provider, err := clientconfig.AuthenticatedClient(osOpts)
11097
if err != nil {
11198
return nil, fmt.Errorf("failed creating provider: %v", err)
11299
}
113100

114-
if opts.Region == "" {
115-
opts.Region = profile.Region
116-
}
117-
118101
computeClient, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
119-
Name: "nova",
120-
Region: opts.Region,
102+
Name: "nova",
121103
})
122104
if err != nil {
123105
return nil, fmt.Errorf("failed to create compute client: %v", err)
124106
}
125107

126108
imageClient, err := openstack.NewImageServiceV2(provider, gophercloud.EndpointOpts{
127-
Name: "glance",
128-
Region: opts.Region,
109+
Name: "glance",
129110
})
130111
if err != nil {
131112
return nil, fmt.Errorf("failed to create image client: %v", err)
132113
}
133114

134115
networkClient, err := openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
135-
Name: "neutron",
136-
Region: opts.Region,
116+
Name: "neutron",
137117
})
138118

139119
a := &API{
@@ -167,10 +147,6 @@ func New(opts *Options) (*API, error) {
167147
a.opts.Network = tmp
168148
}
169149

170-
if a.opts.FloatingIPPool == "" {
171-
a.opts.FloatingIPPool = profile.FloatingIPPool
172-
}
173-
174150
return a, nil
175151
}
176152

mantle/vendor/github.com/gophercloud/utils/env/env.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mantle/vendor/github.com/gophercloud/utils/env/env_windows.go

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mantle/vendor/github.com/gophercloud/utils/gnocchi/client.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mantle/vendor/github.com/gophercloud/utils/gnocchi/results.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)