blob: 8d9a4e9a76f3d7127606c850a2ebf84cf9ddc817 [file] [log] [blame]
Jamie Hannaford924c09d2014-11-19 12:05:38 +01001package secgroups
2
3import (
4 "github.com/mitchellh/mapstructure"
5
6 "github.com/rackspace/gophercloud/pagination"
7)
8
9type SecurityGroup struct {
10 ID string
11 Name string
12 Description string
13 Rules []Rule
14 TenantID string `mapstructure:"tenant_id"`
15}
16
17type Rule struct {
18 ID string
19 FromPort int `mapstructure:"from_port"`
20 ToPort int `mapstructure:"to_port"`
21 IPProtocol string `mapstructure:"ip_protocol"`
22 IPRange IPRange `mapstructure:"ip_range"`
23}
24
25type IPRange struct {
26 CIDR string
27}
28
29// RolePage is a single page of a user Role collection.
30type SecurityGroupPage struct {
31 pagination.SinglePageBase
32}
33
34// IsEmpty determines whether or not a page of Security Groups contains any results.
35func (page SecurityGroupPage) IsEmpty() (bool, error) {
36 users, err := ExtractSecurityGroups(page)
37 if err != nil {
38 return false, err
39 }
40 return len(users) == 0, nil
41}
42
43// ExtractSecurityGroups returns a slice of SecurityGroups contained in a single page of results.
44func ExtractSecurityGroups(page pagination.Page) ([]SecurityGroup, error) {
45 casted := page.(SecurityGroupPage).Body
46 var response struct {
47 SecurityGroups []SecurityGroup `mapstructure:"security_groups"`
48 }
49
50 err := mapstructure.Decode(casted, &response)
51 return response.SecurityGroups, err
52}