diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 6840716..9ab5f0e 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -7,7 +7,7 @@ jobs: fail-fast: false matrix: go-version: - - "1.21" + - "1.22" env: GO111MODULE: "on" diff --git a/go.mod b/go.mod index db3ca1a..49616bc 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,12 @@ module github.com/gophercloud/utils/v2 +go 1.22 + require ( - github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2 + github.com/gophercloud/gophercloud/v2 v2.0.0-rc.1 github.com/hashicorp/go-uuid v1.0.3 github.com/mitchellh/go-homedir v1.1.0 golang.org/x/sys v0.20.0 golang.org/x/text v0.15.0 gopkg.in/yaml.v3 v3.0.1 ) - -go 1.21.6 - -toolchain go1.21.7 diff --git a/go.sum b/go.sum index 9ea5c2f..6e02908 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2 h1:JWv6L7eg3+aIS57n11YlVvtn1pVCKpVlMo24ANj/OVc= -github.com/gophercloud/gophercloud/v2 v2.0.0-beta.2/go.mod h1:Sy5GHwY4iazyaRf94rzL/VxJToVWn8WnIH+1cXqoAks= +github.com/gophercloud/gophercloud/v2 v2.0.0-rc.1 h1:B0J9VVGlNuMF/743KMVFScDB8M2Bd5N1KlsEZykSBlc= +github.com/gophercloud/gophercloud/v2 v2.0.0-rc.1/go.mod h1:cwPW9cbJmfBt1c7o/yzXuNjwonhWA+F9Zw8LNQzd3Zk= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= diff --git a/openstack/blockstorage/v1/snapshots/utils.go b/openstack/blockstorage/v1/snapshots/utils.go deleted file mode 100644 index 5414546..0000000 --- a/openstack/blockstorage/v1/snapshots/utils.go +++ /dev/null @@ -1,44 +0,0 @@ -package snapshots - -import ( - "context" - - "github.com/gophercloud/gophercloud/v2" - "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v1/snapshots" -) - -// IDFromName is a convenience function that returns a snapshot's ID given its name. -func IDFromName(ctx context.Context, client *gophercloud.ServiceClient, name string) (string, error) { - count := 0 - id := "" - - listOpts := snapshots.ListOpts{ - Name: name, - } - - pages, err := snapshots.List(client, listOpts).AllPages(ctx) - if err != nil { - return "", err - } - - all, err := snapshots.ExtractSnapshots(pages) - if err != nil { - return "", err - } - - for _, s := range all { - if s.Name == name { - count++ - id = s.ID - } - } - - switch count { - case 0: - return "", gophercloud.ErrResourceNotFound{Name: name, ResourceType: "snapshot"} - case 1: - return id, nil - default: - return "", gophercloud.ErrMultipleResourcesFound{Name: name, Count: count, ResourceType: "snapshot"} - } -} diff --git a/openstack/blockstorage/v1/volumes/utils.go b/openstack/blockstorage/v1/volumes/utils.go deleted file mode 100644 index 8da29a3..0000000 --- a/openstack/blockstorage/v1/volumes/utils.go +++ /dev/null @@ -1,44 +0,0 @@ -package volumes - -import ( - "context" - - "github.com/gophercloud/gophercloud/v2" - "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v1/volumes" -) - -// IDFromName is a convenience function that returns a volume's ID given its name. -func IDFromName(ctx context.Context, client *gophercloud.ServiceClient, name string) (string, error) { - count := 0 - id := "" - - listOpts := volumes.ListOpts{ - Name: name, - } - - pages, err := volumes.List(client, listOpts).AllPages(ctx) - if err != nil { - return "", err - } - - all, err := volumes.ExtractVolumes(pages) - if err != nil { - return "", err - } - - for _, s := range all { - if s.Name == name { - count++ - id = s.ID - } - } - - switch count { - case 0: - return "", gophercloud.ErrResourceNotFound{Name: name, ResourceType: "volume"} - case 1: - return id, nil - default: - return "", gophercloud.ErrMultipleResourcesFound{Name: name, Count: count, ResourceType: "volume"} - } -} diff --git a/openstack/blockstorage/v3/availabilityzones/utils.go b/openstack/blockstorage/v3/availabilityzones/utils.go index ad824b3..cf84aec 100644 --- a/openstack/blockstorage/v3/availabilityzones/utils.go +++ b/openstack/blockstorage/v3/availabilityzones/utils.go @@ -4,7 +4,7 @@ import ( "context" "github.com/gophercloud/gophercloud/v2" - "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/extensions/availabilityzones" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/availabilityzones" ) // ListAvailableAvailabilityZones is a convenience function that return a slice of available Availability Zones. diff --git a/openstack/blockstorage/extensions/backups/utils.go b/openstack/blockstorage/v3/backups/utils.go similarity index 93% rename from openstack/blockstorage/extensions/backups/utils.go rename to openstack/blockstorage/v3/backups/utils.go index 91156e0..b5f99ce 100644 --- a/openstack/blockstorage/extensions/backups/utils.go +++ b/openstack/blockstorage/v3/backups/utils.go @@ -4,7 +4,7 @@ import ( "context" "github.com/gophercloud/gophercloud/v2" - "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/extensions/backups" + "github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups" ) // IDFromName is a convenience function that returns a backup's ID given its diff --git a/openstack/clientconfig/requests.go b/openstack/clientconfig/requests.go index c8f1808..4b38329 100644 --- a/openstack/clientconfig/requests.go +++ b/openstack/clientconfig/requests.go @@ -890,8 +890,6 @@ func NewServiceClient(ctx context.Context, service string, opts *ClientOpts) (*g return openstack.NewBareMetalV1(pClient, eo) case "baremetal-introspection": return openstack.NewBareMetalIntrospectionV1(pClient, eo) - case "clustering": - return openstack.NewClusteringV1(pClient, eo) case "compute": return openstack.NewComputeV2(pClient, eo) case "container": @@ -919,7 +917,7 @@ func NewServiceClient(ctx context.Context, service string, opts *ClientOpts) (*g return nil, fmt.Errorf("invalid identity API version") } case "image": - return openstack.NewImageServiceV2(pClient, eo) + return openstack.NewImageV2(pClient, eo) case "key-manager": return openstack.NewKeyManagerV1(pClient, eo) case "load-balancer": diff --git a/openstack/compute/v2/availabilityzones/utils.go b/openstack/compute/v2/availabilityzones/utils.go index 2d0d9dd..49fc543 100644 --- a/openstack/compute/v2/availabilityzones/utils.go +++ b/openstack/compute/v2/availabilityzones/utils.go @@ -4,7 +4,7 @@ import ( "context" "github.com/gophercloud/gophercloud/v2" - "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/extensions/availabilityzones" + "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/availabilityzones" ) // ListAvailableAvailabilityZones is a convenience function that return a slice of available Availability Zones. diff --git a/openstack/imageservice/v2/images/utils.go b/openstack/image/v2/images/utils.go similarity index 94% rename from openstack/imageservice/v2/images/utils.go rename to openstack/image/v2/images/utils.go index f73950b..25ae7d1 100644 --- a/openstack/imageservice/v2/images/utils.go +++ b/openstack/image/v2/images/utils.go @@ -4,7 +4,7 @@ import ( "context" "github.com/gophercloud/gophercloud/v2" - "github.com/gophercloud/gophercloud/v2/openstack/imageservice/v2/images" + "github.com/gophercloud/gophercloud/v2/openstack/image/v2/images" ) // IDFromName is a convenience function that returns an image's ID given its diff --git a/openstack/objectstorage/v1/objects/upload.go b/openstack/objectstorage/v1/objects/upload.go index 15ce467..13e9e58 100644 --- a/openstack/objectstorage/v1/objects/upload.go +++ b/openstack/objectstorage/v1/objects/upload.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "net/url" "os" "strings" @@ -151,7 +152,7 @@ func Upload(ctx context.Context, client *gophercloud.ServiceClient, containerNam // Check and see if the object being requested already exists. objectResult := objects.Get(ctx, client, containerName, objectName, nil) if objectResult.Err != nil { - if _, ok := objectResult.Err.(gophercloud.ErrDefault404); ok { + if gophercloud.ResponseCodeIs(objectResult.Err, http.StatusNotFound) { origObject = nil } else { return nil, fmt.Errorf("error retrieving original object %s/%s: %s", containerName, objectName, objectResult.Err) diff --git a/terraform/auth/config.go b/terraform/auth/config.go index d1207b1..579e1ea 100644 --- a/terraform/auth/config.go +++ b/terraform/auth/config.go @@ -173,8 +173,6 @@ func (c *Config) LoadAndValidate(ctx context.Context) error { return err } - client.Context = c.Context - // Set UserAgent client.UserAgent.Prepend(terraformUserAgent(c.TerraformVersion, c.SDKVersion)) @@ -327,7 +325,7 @@ func (c *Config) IdentityV3Client(ctx context.Context, region string) (*gophercl } func (c *Config) ImageV2Client(ctx context.Context, region string) (*gophercloud.ServiceClient, error) { - return c.CommonServiceClientInit(ctx, openstack.NewImageServiceV2, region, "image") + return c.CommonServiceClientInit(ctx, openstack.NewImageV2, region, "image") } func (c *Config) MessagingV2Client(ctx context.Context, region string) (*gophercloud.ServiceClient, error) {