blob: 0c1471609b33fdb118be4c26fa0da2caa1af0e1a [file] [log] [blame]
Jamie Hannaford924c09d2014-11-19 12:05:38 +01001package secgroups
2
3import (
Jamie Hannaforda493e642014-11-19 12:40:30 +01004 "github.com/racker/perigee"
5
Jamie Hannaford924c09d2014-11-19 12:05:38 +01006 "github.com/rackspace/gophercloud"
7 "github.com/rackspace/gophercloud/pagination"
8)
9
Jamie Hannaford19151792014-11-19 12:46:47 +010010func commonList(client *gophercloud.ServiceClient, url string) pagination.Pager {
Jamie Hannaford924c09d2014-11-19 12:05:38 +010011 createPage := func(r pagination.PageResult) pagination.Page {
12 return SecurityGroupPage{pagination.SinglePageBase(r)}
13 }
14
Jamie Hannaford19151792014-11-19 12:46:47 +010015 return pagination.NewPager(client, url, createPage)
16}
17
18func List(client *gophercloud.ServiceClient) pagination.Pager {
19 return commonList(client, rootURL(client))
20}
21
22func ListByServer(client *gophercloud.ServiceClient, serverID string) pagination.Pager {
23 return commonList(client, listByServerURL(client, serverID))
Jamie Hannaford924c09d2014-11-19 12:05:38 +010024}
Jamie Hannaforda493e642014-11-19 12:40:30 +010025
26type CreateOpts struct {
27 // Optional - the name of your security group. If no value provided, null
28 // will be set.
29 Name string `json:"name,omitempty"`
30
31 // Optional - the description of your security group. If no value provided,
32 // null will be set.
33 Description string `json:"description,omitempty"`
34}
35
36func Create(client *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
37 var result CreateResult
38
39 reqBody := struct {
40 CreateOpts `json:"security_group"`
41 }{opts}
42
43 _, result.Err = perigee.Request("POST", rootURL(client), perigee.Options{
44 Results: &result.Body,
45 ReqBody: &reqBody,
46 MoreHeaders: client.AuthenticatedHeaders(),
47 OkCodes: []int{200},
48 })
49
50 return result
51}