Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a // indirect
github.com/coreos/ignition v0.33.0 // indirect
github.com/go-logr/logr v0.2.1
github.com/gophercloud/gophercloud v0.6.1-0.20191025185032-6ad562af8c1f
github.com/gophercloud/utils v0.0.0-20190124231947-9c3b9f2457ef
github.com/gophercloud/gophercloud v0.14.0
github.com/gophercloud/utils v0.0.0-20201221031838-d93cf4b3fa50
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/openshift/api v0.0.0-20201019163320-c6a5ec25f267
Expand Down
16 changes: 12 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,12 @@ github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1a
github.com/googleapis/gnostic v0.4.1 h1:DLJCy1n/vrD4HPjOvYcT8aYQXpPIzoRZONaYwyycI+I=
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gophercloud/gophercloud v0.6.1-0.20191025185032-6ad562af8c1f h1:oUSh4Z++AIcYE3FClYjEqC+T/esZ2ZDaDeaEeXQ2mkE=
github.com/gophercloud/gophercloud v0.6.1-0.20191025185032-6ad562af8c1f/go.mod h1:GICNByuaEBibcjmjvI7QvYJSZEbGkcYwAR7EZK2WMqM=
github.com/gophercloud/utils v0.0.0-20190124231947-9c3b9f2457ef h1:/5kyAzeE1xcedTX3DxziRVWHJrxD+7NEdXU/4/DOjTs=
github.com/gophercloud/utils v0.0.0-20190124231947-9c3b9f2457ef/go.mod h1:wjDF8z83zTeg5eMLml5EBSlAhbF7G8DobyI1YsMuyzw=
github.com/gophercloud/gophercloud v0.6.1-0.20191122030953-d8ac278c1c9d h1:r5dcOhiqucDq0XNmvsN+HMB7+o3TrjZlLdNYGFRtM3o=
github.com/gophercloud/gophercloud v0.6.1-0.20191122030953-d8ac278c1c9d/go.mod h1:ozGNgr9KYOVATV5jsgHl/ceCDXGuguqOZAzoQ/2vcNM=
github.com/gophercloud/gophercloud v0.14.0 h1:c2Byo+YMxhHlTJ3TPptjQ4dOQ1YknTHDJ/9zClDH+84=
github.com/gophercloud/gophercloud v0.14.0/go.mod h1:VX0Ibx85B60B5XOrZr6kaNwrmPUzcmMpwxvQ1WQIIWM=
github.com/gophercloud/utils v0.0.0-20201221031838-d93cf4b3fa50 h1:gqB4UDxKbkdoZVzjAYDjK04FlM7vZG4Z22MqTKa6Cmo=
github.com/gophercloud/utils v0.0.0-20201221031838-d93cf4b3fa50/go.mod h1:ehWUbLQJPqS0Ep+CxeD559hsm9pthPXadJNKwZkp43w=
github.com/gorilla/mux v0.0.0-20191024121256-f395758b854c/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
Expand All @@ -346,6 +348,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
Expand Down Expand Up @@ -383,6 +386,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
Expand All @@ -409,6 +414,7 @@ github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
Expand Down Expand Up @@ -625,6 +631,7 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
Expand Down Expand Up @@ -748,6 +755,7 @@ golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
72 changes: 18 additions & 54 deletions pkg/cloud/openstack/clients/machineservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
netext "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks"
Expand All @@ -50,6 +49,8 @@ import (
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
"github.com/gophercloud/gophercloud/pagination"
"github.com/gophercloud/utils/openstack/clientconfig"
flavorutils "github.com/gophercloud/utils/openstack/compute/v2/flavors"
imageutils "github.com/gophercloud/utils/openstack/imageservice/v2/images"
configclient "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
"github.com/openshift/machine-api-operator/pkg/util"
Expand Down Expand Up @@ -367,36 +368,6 @@ func GetSecurityGroups(is *InstanceService, sg_param []openstackconfigv1.Securit
return sgIDs, nil
}

// Helper function for getting image ID from name
func getImageID(is *InstanceService, imageName string) (string, error) {
if imageName == "" {
return "", nil
}

opts := images.ListOpts{
Name: imageName,
}

pages, err := images.List(is.imagesClient, opts).AllPages()
if err != nil {
return "", err
}

allImages, err := images.ExtractImages(pages)
if err != nil {
return "", err
}

switch len(allImages) {
case 0:
return "", fmt.Errorf("no image with the name %s could be found", imageName)
case 1:
return allImages[0].ID, nil
default:
return "", fmt.Errorf("too many images with the name, %s, were found", imageName)
}
}

// InstanceCreate creates a compute instance.
// If ServerGroupName is nonempty and no server group exists with that name,
// then InstanceCreate creates a server group with that name.
Expand Down Expand Up @@ -580,21 +551,24 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
is.computeClient.Microversion = "2.52"
}

// Get image ID
imageID, err := getImageID(is, config.Image)
imageID, err := imageutils.IDFromName(is.imagesClient, config.Image)
if err != nil {
return nil, fmt.Errorf("Create new server err: %v", err)
}

flavorID, err := flavorutils.IDFromName(is.computeClient, config.Flavor)
if err != nil {
return nil, fmt.Errorf("Create new server err: %v", err)
}

var serverCreateOpts servers.CreateOptsBuilder = servers.CreateOpts{
Name: name,
ImageRef: imageID,
FlavorName: config.Flavor,
FlavorRef: flavorID,
AvailabilityZone: config.AvailabilityZone,
Networks: ports_list,
UserData: []byte(userData),
SecurityGroups: securityGroups,
ServiceClient: is.computeClient,
Tags: serverTags,
Metadata: config.ServerMetadata,
ConfigDrive: config.ConfigDrive,
Expand All @@ -609,12 +583,11 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
// change serverCreateOpts to exclude imageRef from them
serverCreateOpts = servers.CreateOpts{
Name: name,
FlavorName: config.Flavor,
FlavorRef: flavorID,
AvailabilityZone: config.AvailabilityZone,
Networks: ports_list,
UserData: []byte(userData),
SecurityGroups: securityGroups,
ServiceClient: is.computeClient,
Tags: serverTags,
Metadata: config.ServerMetadata,
ConfigDrive: config.ConfigDrive,
Expand All @@ -624,7 +597,7 @@ func (is *InstanceService) InstanceCreate(clusterName string, name string, clust
// if source type is "image" then we have to create a volume from the image first
klog.Infof("Creating a bootable volume from image %v.", config.RootVolume.SourceUUID)

imageID, err := getImageID(is, config.RootVolume.SourceUUID)
imageID, err := imageutils.IDFromName(is.imagesClient, config.RootVolume.SourceUUID)
if err != nil {
return nil, fmt.Errorf("Create new server err: %v", err)
}
Expand Down Expand Up @@ -896,24 +869,16 @@ func (is *InstanceService) GetInstanceList(opts *InstanceListOpts) ([]*Instance,
return instanceList, nil
}

// DoesFlavorExist return an error if flavor with given name doesn't exist, and nil otherwise
// DoesFlavorExist returns nil if exactly one flavor exists with the given name.
func (is *InstanceService) DoesFlavorExist(flavorName string) error {
_, err := flavors.IDFromName(is.computeClient, flavorName)
if err != nil {
return err
}

return nil
_, err := flavorutils.IDFromName(is.computeClient, flavorName)
return err
}

// DoesImageExist return an error if image with the given name doesn't exist, and nil otherwise
// DoesImageExist returns nil if exactly one image exists with the given name.
func (is *InstanceService) DoesImageExist(imageName string) error {
_, err := getImageID(is, imageName)
if err != nil {
return err
}

return nil
_, err := imageutils.IDFromName(is.imagesClient, imageName)
return err
}

// DoesAvailabilityZoneExist return an error if AZ with the given name doesn't exist, and nil otherwise
Expand Down Expand Up @@ -1011,8 +976,7 @@ func (is *InstanceService) GetFlavorInfo(flavorID string) (flavor *flavors.Flavo
}

func (is *InstanceService) GetFlavorID(flavorName string) (string, error) {
flavorID, err := flavors.IDFromName(is.computeClient, flavorName)
return flavorID, err
return flavorutils.IDFromName(is.computeClient, flavorName)
}

func serverToInstance(server *servers.Server) *Instance {
Expand Down
4 changes: 2 additions & 2 deletions vendor/github.com/gophercloud/gophercloud/.travis.yml

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

48 changes: 35 additions & 13 deletions vendor/github.com/gophercloud/gophercloud/.zuul.yaml

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

Loading