blob: 00d0bb53c21c3cea04da88619eb6173e83dbf380 [file] [log] [blame]
Jamie Hannaford17d2f872014-11-24 12:20:33 +01001package defsecrules
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups"
6 "github.com/gophercloud/gophercloud/pagination"
Jamie Hannaford17d2f872014-11-24 12:20:33 +01007)
8
Jamie Hannaford558572f2014-11-24 14:31:57 +01009// DefaultRule represents a default rule - which is identical to a
10// normal security rule.
Jamie Hannaford17d2f872014-11-24 12:20:33 +010011type DefaultRule secgroups.Rule
12
13// DefaultRulePage is a single page of a DefaultRule collection.
14type DefaultRulePage struct {
15 pagination.SinglePageBase
16}
17
18// IsEmpty determines whether or not a page of default rules contains any results.
19func (page DefaultRulePage) IsEmpty() (bool, error) {
20 users, err := ExtractDefaultRules(page)
21 if err != nil {
22 return false, err
23 }
24 return len(users) == 0, nil
25}
26
27// ExtractDefaultRules returns a slice of DefaultRules contained in a single
28// page of results.
29func ExtractDefaultRules(page pagination.Page) ([]DefaultRule, error) {
Jon Perritt12395212016-02-24 10:41:17 -060030 r := page.(DefaultRulePage)
31 var s struct {
32 DefaultRules []DefaultRule `json:"security_group_default_rules"`
Jamie Hannaford17d2f872014-11-24 12:20:33 +010033 }
Jon Perritt12395212016-02-24 10:41:17 -060034 err := r.ExtractInto(&s)
35 return s.DefaultRules, err
Jamie Hannaford17d2f872014-11-24 12:20:33 +010036}
Jamie Hannaford43fa4a22014-11-24 12:49:17 +010037
38type commonResult struct {
39 gophercloud.Result
40}
41
42// CreateResult represents the result of a create operation.
43type CreateResult struct {
44 commonResult
45}
46
47// GetResult represents the result of a get operation.
48type GetResult struct {
49 commonResult
50}
51
52// Extract will extract a DefaultRule struct from most responses.
53func (r commonResult) Extract() (*DefaultRule, error) {
Jon Perritt12395212016-02-24 10:41:17 -060054 var s struct {
55 DefaultRule DefaultRule `json:"security_group_default_rule"`
Jamie Hannaford43fa4a22014-11-24 12:49:17 +010056 }
Jon Perritt12395212016-02-24 10:41:17 -060057 err := r.ExtractInto(&s)
58 return &s.DefaultRule, err
Jamie Hannaford43fa4a22014-11-24 12:49:17 +010059}