Skip to content

Commit

Permalink
Upgrade gophercloud to v1.11.0
Browse files Browse the repository at this point in the history
Update upup/pkg/fi/cloudup/openstacktasks/instance.go

Co-authored-by: Peter Rifel <[email protected]>
  • Loading branch information
Ole Markus With and rifelpet committed Aug 23, 2020
1 parent 40662d0 commit 8c70787
Show file tree
Hide file tree
Showing 70 changed files with 2,374 additions and 1,154 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ replace k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.18.6

replace k8s.io/code-generator => k8s.io/code-generator v0.18.6

replace github.com/gophercloud/gophercloud => github.com/gophercloud/gophercloud v0.9.0
replace github.com/gophercloud/gophercloud => github.com/gophercloud/gophercloud v0.11.0

require (
cloud.google.com/go v0.38.0
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/uuid v1.1.1
github.com/gophercloud/gophercloud v0.7.1-0.20200116011225-46fdd1830e9a
github.com/gophercloud/gophercloud v0.11.0
github.com/gorilla/mux v1.7.3
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsC
github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk=
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
github.com/gophercloud/gophercloud v0.9.0 h1:eJHQQFguQRv2FatH2d2VXH2ueTe2XzjgjwFjFS7SGcs=
github.com/gophercloud/gophercloud v0.9.0/go.mod h1:gmC5oQqMDOMO1t1gq5DquX/yAU808e/4mzjjDA76+Ss=
github.com/gophercloud/gophercloud v0.11.0 h1:pYMP9UZBdQa3lsfIZ1tZor4EbtxiuB6BHhocenkiH/E=
github.com/gophercloud/gophercloud v0.11.0/go.mod h1:gmC5oQqMDOMO1t1gq5DquX/yAU808e/4mzjjDA76+Ss=
github.com/gophercloud/utils v0.0.0-20191020172814-bd86af96d544/go.mod h1:SZ9FTKibIotDtCrxAU/evccoyu1yhKST6hgBvwTB5Eg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
Expand Down
4 changes: 4 additions & 0 deletions upup/pkg/fi/cloudup/openstack/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"
"time"

"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"

"github.com/gophercloud/gophercloud"
os "github.com/gophercloud/gophercloud/openstack"
cinder "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
Expand Down Expand Up @@ -291,6 +293,8 @@ type OpenstackCloud interface {

GetImage(name string) (i *images.Image, err error)

GetFlavor(name string) (f *flavors.Flavor, err error)

AssociateFloatingIPToInstance(serverID string, opts floatingips.AssociateOpts) (err error)

ListServerFloatingIPs(id string) ([]*string, error)
Expand Down
28 changes: 28 additions & 0 deletions upup/pkg/fi/cloudup/openstack/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"time"

"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"

"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/mitchellh/mapstructure"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -189,3 +191,29 @@ func listInstances(c OpenstackCloud, opt servers.ListOptsBuilder) ([]servers.Ser
return instances, wait.ErrWaitTimeout
}
}

func (c *openstackCloud) GetFlavor(name string) (*flavors.Flavor, error) {
return getFlavor(c, name)
}

func getFlavor(c OpenstackCloud, name string) (*flavors.Flavor, error) {
opts := flavors.ListOpts{}
pager := flavors.ListDetail(c.ComputeClient(), opts)
page, err := pager.AllPages()
if err != nil {
return nil, fmt.Errorf("failed to list flavors: %v", err)
}

fs, err := flavors.ExtractFlavors(page)
if err != nil {
return nil, fmt.Errorf("failed to extract flavors: %v", err)
}
for _, f := range fs {
if f.Name == name {
return &f, nil
}
}

return nil, fmt.Errorf("could not find flavor with name %v", name)

}
6 changes: 6 additions & 0 deletions upup/pkg/fi/cloudup/openstack/mock_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package openstack
import (
"fmt"

"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"

"github.com/gophercloud/gophercloud"
cinder "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
az "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones"
Expand Down Expand Up @@ -331,6 +333,10 @@ func (c *MockCloud) GetImage(name string) (*images.Image, error) {
return getImage(c, name)
}

func (c *MockCloud) GetFlavor(name string) (*flavors.Flavor, error) {
return getFlavor(c, name)
}

func (c *MockCloud) GetInstance(id string) (*servers.Server, error) {
return getInstance(c, id)
}
Expand Down
1 change: 0 additions & 1 deletion upup/pkg/fi/cloudup/openstacktasks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ go_library(
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/imageservice/v2/images:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools:go_default_library",
Expand Down
16 changes: 10 additions & 6 deletions upup/pkg/fi/cloudup/openstacktasks/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"fmt"
"strconv"

"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"

"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
Expand Down Expand Up @@ -181,15 +179,21 @@ func (_ *Instance) RenderOpenstack(t *openstack.OpenstackAPITarget, a, e, change
cloud := t.Cloud.(openstack.OpenstackCloud)

imageName := fi.StringValue(e.Image)
imageRef, err := images.IDFromName(cloud.ImageClient(), imageName)
image, err := cloud.GetImage(imageName)
if err != nil {
return fmt.Errorf("failed to find image %v: %v", imageName, err)
}

flavorName := fi.StringValue(e.Flavor)
flavor, err := cloud.GetFlavor(flavorName)
if err != nil {
return fmt.Errorf("failed to find flavor %v: %v", flavorName, err)
}

opt := servers.CreateOpts{
Name: fi.StringValue(e.Name),
ImageRef: imageRef,
FlavorName: fi.StringValue(e.Flavor),
Name: fi.StringValue(e.Name),
ImageRef: image.ID,
FlavorRef: flavor.ID,
Networks: []servers.Network{
{
Port: fi.StringValue(e.Port.ID),
Expand Down
98 changes: 97 additions & 1 deletion vendor/github.com/gophercloud/gophercloud/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8c70787

Please sign in to comment.