blob: 61b918df9efcbf9fa593896aac9aeedee591377a [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)
Jon Perritt31b66462016-02-25 22:25:30 -060021 return len(users) == 0, err
Jamie Hannaford17d2f872014-11-24 12:20:33 +010022}
23
24// ExtractDefaultRules returns a slice of DefaultRules contained in a single
25// page of results.
Jon Perritt31b66462016-02-25 22:25:30 -060026func ExtractDefaultRules(r pagination.Page) ([]DefaultRule, error) {
Jon Perritt12395212016-02-24 10:41:17 -060027 var s struct {
28 DefaultRules []DefaultRule `json:"security_group_default_rules"`
Jamie Hannaford17d2f872014-11-24 12:20:33 +010029 }
Jon Perritt31b66462016-02-25 22:25:30 -060030 err := (r.(DefaultRulePage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060031 return s.DefaultRules, err
Jamie Hannaford17d2f872014-11-24 12:20:33 +010032}
Jamie Hannaford43fa4a22014-11-24 12:49:17 +010033
34type commonResult struct {
35 gophercloud.Result
36}
37
38// CreateResult represents the result of a create operation.
39type CreateResult struct {
40 commonResult
41}
42
43// GetResult represents the result of a get operation.
44type GetResult struct {
45 commonResult
46}
47
48// Extract will extract a DefaultRule struct from most responses.
49func (r commonResult) Extract() (*DefaultRule, error) {
Jon Perritt12395212016-02-24 10:41:17 -060050 var s struct {
51 DefaultRule DefaultRule `json:"security_group_default_rule"`
Jamie Hannaford43fa4a22014-11-24 12:49:17 +010052 }
Jon Perritt12395212016-02-24 10:41:17 -060053 err := r.ExtractInto(&s)
54 return &s.DefaultRule, err
Jamie Hannaford43fa4a22014-11-24 12:49:17 +010055}