interfaces: add ListServersByFilter() method
This method allows us list servers based on certain URI filter
paramters provided by the API endpoint.
diff --git a/servers.go b/servers.go
index 425853b..1f6a7a4 100644
--- a/servers.go
+++ b/servers.go
@@ -5,9 +5,11 @@
import (
"fmt"
+ "net/url"
+ "strings"
+
"github.com/mitchellh/mapstructure"
"github.com/racker/perigee"
- "strings"
)
// genericServersProvider structures provide the implementation for generic OpenStack-compatible
@@ -26,6 +28,23 @@
}
// See the CloudServersProvider interface for details.
+func (gcp *genericServersProvider) ListServersByFilter(filter url.Values) ([]Server, error) {
+ var ss []Server
+
+ err := gcp.context.WithReauth(gcp.access, func() error {
+ url := gcp.endpoint + "/servers/detail?" + filter.Encode()
+ return perigee.Get(url, perigee.Options{
+ CustomClient: gcp.context.httpClient,
+ Results: &struct{ Servers *[]Server }{&ss},
+ MoreHeaders: map[string]string{
+ "X-Auth-Token": gcp.access.AuthToken(),
+ },
+ })
+ })
+ return ss, err
+}
+
+// See the CloudServersProvider interface for details.
func (gcp *genericServersProvider) ListServersLinksOnly() ([]Server, error) {
var ss []Server
@@ -496,7 +515,7 @@
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
- Results: &struct{Security_group_default_rules *[]SGRule}{&sgrs},
+ Results: &struct{ Security_group_default_rules *[]SGRule }{&sgrs},
})
})
return sgrs, err
@@ -511,8 +530,10 @@
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
- Results: &struct{Security_group_default_rule **SGRule}{&sgr},
- ReqBody: struct{Security_group_default_rule SGRule `json:"security_group_default_rule"`}{r},
+ Results: &struct{ Security_group_default_rule **SGRule }{&sgr},
+ ReqBody: struct {
+ Security_group_default_rule SGRule `json:"security_group_default_rule"`
+ }{r},
})
})
return sgr, err
@@ -527,7 +548,7 @@
MoreHeaders: map[string]string{
"X-Auth-Token": gsp.access.AuthToken(),
},
- Results: &struct{Security_group_default_rule **SGRule}{&sgr},
+ Results: &struct{ Security_group_default_rule **SGRule }{&sgr},
})
})
return sgr, err