blob: ae46b59627f2af5bdfa20cc22618eaaddeae3a8f [file] [log] [blame]
Jamie Hannaford17d2f872014-11-24 12:20:33 +01001package defsecrules
2
3import (
4 "github.com/mitchellh/mapstructure"
5
6 "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups"
7 "github.com/rackspace/gophercloud/pagination"
8)
9
10type DefaultRule secgroups.Rule
11
12// DefaultRulePage is a single page of a DefaultRule collection.
13type DefaultRulePage struct {
14 pagination.SinglePageBase
15}
16
17// IsEmpty determines whether or not a page of default rules contains any results.
18func (page DefaultRulePage) IsEmpty() (bool, error) {
19 users, err := ExtractDefaultRules(page)
20 if err != nil {
21 return false, err
22 }
23 return len(users) == 0, nil
24}
25
26// ExtractDefaultRules returns a slice of DefaultRules contained in a single
27// page of results.
28func ExtractDefaultRules(page pagination.Page) ([]DefaultRule, error) {
29 casted := page.(DefaultRulePage).Body
30 var response struct {
31 Rules []DefaultRule `mapstructure:"security_group_default_rules"`
32 }
33
34 err := mapstructure.Decode(casted, &response)
35
36 return response.Rules, err
37}