Exercise the endpoint discovery code a little.
diff --git a/openstack/client.go b/openstack/client.go
index b058823..207ba13 100644
--- a/openstack/client.go
+++ b/openstack/client.go
@@ -184,19 +184,19 @@
}
// Discover the service we're interested in.
- computeResults, err := services3.List(v3Client, services3.ListOpts{ServiceType: opts.Type})
+ serviceResults, err := services3.List(v3Client, services3.ListOpts{ServiceType: opts.Type})
if err != nil {
return "", err
}
- serviceResults, err := gophercloud.AllPages(computeResults)
+ allServiceResults, err := gophercloud.AllPages(serviceResults)
if err != nil {
return "", err
}
- allServices := services3.AsServices(serviceResults)
+ allServices := services3.AsServices(allServiceResults)
if opts.Name != "" {
- filtered := make([]services3.Service, 1)
+ filtered := make([]services3.Service, 0, 1)
for _, service := range allServices {
if service.Name == opts.Name {
filtered = append(filtered, service)
@@ -206,7 +206,7 @@
}
if len(allServices) == 0 {
- return "", gophercloud.ErrEndpointNotFound
+ return "", gophercloud.ErrServiceNotFound
}
if len(allServices) > 1 {
return "", fmt.Errorf("Discovered %d matching services: %#v", len(allServices), allServices)
@@ -222,18 +222,16 @@
if err != nil {
return "", err
}
-
allEndpoints, err := gophercloud.AllPages(endpointResults)
if err != nil {
return "", err
}
-
endpoints := endpoints3.AsEndpoints(allEndpoints)
if opts.Name != "" {
- filtered := make([]endpoints3.Endpoint, 1)
+ filtered := make([]endpoints3.Endpoint, 0, 1)
for _, endpoint := range endpoints {
- if endpoint.Region == opts.Region {
+ if opts.Region == "" || endpoint.Region == opts.Region {
filtered = append(filtered, endpoint)
}
}
@@ -271,3 +269,12 @@
Endpoint: v3Endpoint,
}
}
+
+// NewStorageV1 creates a ServiceClient that may be used with the v1 object storage package.
+func NewStorageV1(client *gophercloud.ProviderClient, region string) (*gophercloud.ServiceClient, error) {
+ url, err := client.EndpointLocator(gophercloud.EndpointOpts{Type: "object-store", Name: "swift"})
+ if err != nil {
+ return nil, err
+ }
+ return &gophercloud.ServiceClient{Provider: client, Endpoint: url}, nil
+}