rackspace/gophercloud — pull request #31 by sam-falvo (2013-07-03 01:34:46+00:00)
Title: Implement Access.FirstEndpointUrlByCriteria

The FirstEndpointUrlByCriteria method is a key enabler for writing API
provider interface constructors. A simple, albeit incomplete, use-case
for Cloud Servers API demonstrates how it's used internally.

See squashed commit history below for more detailed rationale behind the
API design.

Squashed commit of the following:

commit 625c31f754dcdcd2d348cf4cf5499a03ba6b2de1
Author: Samuel A. Falvo II
Date: Tue Jul 2 18:21:36 2013 -0700

Fix service name typo

commit c6abcbe20bfe31a8c9399e78c186dca64d050140
Author: Samuel A. Falvo II
Date: Tue Jul 2 18:15:41 2013 -0700

Added decision logic to FFEBC function.

commit bccf7178464c5071a81d63ef16fd20d7a241146f
Author: Samuel A. Falvo II
Date: Tue Jul 2 17:18:14 2013 -0700

Added ListServers and its dependencies.

In order to list servers, we need access to a cloud server API. This is
the job of the ComputeApi() function.

ComputeApi(), in turn, tries hard not to contrain the user in choosing
an endpoint, while still offering an interface optimized for the common
case of using an existing service provider's endpoints. Otherwise, the
user will end up having to use nested functions and bizarre predicate
sequences like this:

func(ce *CatalogEntry, ee *EntryEndpoint) bool {
if ce != nil {
return ce.Name == "cloudComputeOpenStack"
}
if ee != nil {
return ee.Region == "DFW" && ee.VersionId == "2"
}
return false
}

The current interface just encapsulates this kind of logic into a simple
structure, taking 66% fewer lines, and zero chance for error:

ApiCriteria{
Name: "cloudComputeOpenStack",
Region: "DFW",
VersionId: "2",
}

FindFirstEndpointByConstraint() is invoked (via
AccessProvider.FirstEndpointUrlByConstraint()) to actually look for a
matching endpoint in the provider's service catalog. This interprets
the ApiCriteria structure settings, except for UrlChoice. If it finds a
candidate endpoint, the user may select public or private endpoints via
the ApiCriteria.UrlChoice setting (which the
FirstEndpointUrlByCriteria() function interprets). If nothing is found,
an ErrEndpoint error will be returned to the caller. Of course, this
being a brand new implementation, it just returns the default of
"nothing found" for all queries anyway.

If not specified, a criteria's UrlChoice defaults to PublicURL.

commit 9549f0b30e0736962dad55f3f38f88124e076fb9
Author: Samuel A. Falvo II
Date: Tue Jul 2 17:10:14 2013 -0700

Removed VIM temp swap file

commit 8e00ad5ac3466cbec3c539e8b21bea6d23ab37f7
Author: Samuel A. Falvo II
Date: Tue Jul 2 16:20:22 2013 -0700

Add ApiCriteria to API

commit 6f3b41929a496c6a0734221bf12ef27035b71e39
Author: Samuel A. Falvo II
Date: Tue Jul 2 16:18:49 2013 -0700

Add acceptance test for list servers