/
requests.go
106 lines (84 loc) · 2.8 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package securitygroups
import (
"github.com/dynuc/gophercloud"
"github.com/dynuc/gophercloud/pagination"
)
type CreateOpts struct {
// Specifies the security group name.
Name string `json:"name" required:"true"`
// Specifies the enterprise project ID. This field can be used to
// filter out the VPCs associated with a specified enterprise project.
EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
// Specifies the resource ID of the VPC to which the security
// group belongs.
VpcId string `json:"vpc_id,omitempty"`
// Specifies the default security group rule, which ensures that
//// hosts in the security group can communicate with one another.
//SecurityGroupRules []SecurityGroupRule `json:"security_group_rules"`
}
type CreateOptsBuilder interface {
ToSecuritygroupsCreateMap() (map[string]interface{}, error)
}
func (opts CreateOpts) ToSecuritygroupsCreateMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(&opts, "security_group")
if err != nil {
return nil, err
}
return b, nil
}
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToSecuritygroupsCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(CreateURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}
func Delete(client *gophercloud.ServiceClient, securityGroupId string) (r DeleteResult) {
url := DeleteURL(client, securityGroupId)
_, r.Err = client.Delete(url, nil)
return
}
func Get(client *gophercloud.ServiceClient, securityGroupId string) (r GetResult) {
url := GetURL(client, securityGroupId)
_, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}
type ListOpts struct {
// Specifies the resource ID of pagination query. If the parameter
// is left blank, only resources on the first page are queried.
Marker string `q:"marker"`
// Specifies the number of records returned on each page.
Limit int `q:"limit"`
// Specifies the VPC ID used as the query filter.
VpcId string `q:"vpc_id"`
// enterprise_project_id
// Specifies the enterprise_project_id used as the query filter.
EnterpriseProjectId string `q:"enterprise_project_id"`
}
type ListOptsBuilder interface {
ToListQuery() (string, error)
}
func (opts ListOpts) ToListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := ListURL(client)
if opts != nil {
query, err := opts.ToListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url,
func(r pagination.PageResult) pagination.Page {
return SecurityGroupPage{pagination.LinkedPageBase{PageResult: r}}
})
}