Jamie Hannaford | 924c09d | 2014-11-19 12:05:38 +0100 | [diff] [blame] | 1 | package secgroups |
| 2 | |
| 3 | import ( |
Jamie Hannaford | a493e64 | 2014-11-19 12:40:30 +0100 | [diff] [blame^] | 4 | "github.com/racker/perigee" |
| 5 | |
Jamie Hannaford | 924c09d | 2014-11-19 12:05:38 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud" |
| 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | ) |
| 9 | |
| 10 | func List(client *gophercloud.ServiceClient) pagination.Pager { |
| 11 | createPage := func(r pagination.PageResult) pagination.Page { |
| 12 | return SecurityGroupPage{pagination.SinglePageBase(r)} |
| 13 | } |
| 14 | |
| 15 | return pagination.NewPager(client, rootURL(client), createPage) |
| 16 | } |
Jamie Hannaford | a493e64 | 2014-11-19 12:40:30 +0100 | [diff] [blame^] | 17 | |
| 18 | type CreateOpts struct { |
| 19 | // Optional - the name of your security group. If no value provided, null |
| 20 | // will be set. |
| 21 | Name string `json:"name,omitempty"` |
| 22 | |
| 23 | // Optional - the description of your security group. If no value provided, |
| 24 | // null will be set. |
| 25 | Description string `json:"description,omitempty"` |
| 26 | } |
| 27 | |
| 28 | func Create(client *gophercloud.ServiceClient, opts CreateOpts) CreateResult { |
| 29 | var result CreateResult |
| 30 | |
| 31 | reqBody := struct { |
| 32 | CreateOpts `json:"security_group"` |
| 33 | }{opts} |
| 34 | |
| 35 | _, result.Err = perigee.Request("POST", rootURL(client), perigee.Options{ |
| 36 | Results: &result.Body, |
| 37 | ReqBody: &reqBody, |
| 38 | MoreHeaders: client.AuthenticatedHeaders(), |
| 39 | OkCodes: []int{200}, |
| 40 | }) |
| 41 | |
| 42 | return result |
| 43 | } |