Copy blockstorage v1 to v2
diff --git a/openstack/client.go b/openstack/client.go
index 951f4ed..b533e83 100644
--- a/openstack/client.go
+++ b/openstack/client.go
@@ -281,6 +281,29 @@
return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil
}
+// NewBlockStorageV2 creates a ServiceClient that may be used to access the v2 block storage service.
+func NewBlockStorageV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
+ eo.ApplyDefaults("volume")
+ url, err := client.EndpointLocator(eo)
+ if err != nil {
+ return nil, err
+ }
+
+ // Force using v2 API
+ if strings.Contains(url, "/v1") {
+ url = strings.Replace(url, "/v1", "/v2", -1)
+ }
+ if !strings.Contains(url, "/v2") {
+ return nil, fmt.Errorf("Block Storage v2 endpoint not found")
+ }
+
+ return &gophercloud.ServiceClient{
+ ProviderClient: client,
+ Endpoint: url,
+ ResourceBase: url,
+ }, nil
+}
+
// NewCDNV1 creates a ServiceClient that may be used to access the OpenStack v1
// CDN service.
func NewCDNV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {