Jamie Hannaford | 6ee2e9a | 2014-09-23 12:03:54 +0200 | [diff] [blame] | 1 | package quotas |
Jamie Hannaford | 546401f | 2014-09-23 15:15:11 +0200 | [diff] [blame^] | 2 | |
| 3 | import ( |
| 4 | "github.com/racker/perigee" |
| 5 | "github.com/rackspace/gophercloud" |
| 6 | ) |
| 7 | |
| 8 | func Get(c *gophercloud.ServiceClient) GetResult { |
| 9 | var res GetResult |
| 10 | _, err := perigee.Request("GET", rootURL(c), perigee.Options{ |
| 11 | Results: &res.resp, |
| 12 | MoreHeaders: c.Provider.AuthenticatedHeaders(), |
| 13 | }) |
| 14 | res.err = err |
| 15 | return res |
| 16 | } |
| 17 | |
| 18 | type UpdateOpts struct { |
| 19 | Subnet *int |
| 20 | Router *int |
| 21 | Network *int |
| 22 | FloatingIP *int |
| 23 | Port *int |
| 24 | HealthMonitor *int |
| 25 | SecGroupRule *int |
| 26 | SecGroup *int |
| 27 | VIP *int |
| 28 | Member *int |
| 29 | Pool *int |
| 30 | } |
| 31 | |
| 32 | func Update(c *gophercloud.ServiceClient, opts UpdateOpts) UpdateResult { |
| 33 | type quota struct { |
| 34 | Subnet *int `json:"subnet,omitempty"` |
| 35 | Router *int `json:"router,omitempty"` |
| 36 | Network *int `json:"network,omitempty"` |
| 37 | FloatingIP *int `json:"floatingip,omitempty"` |
| 38 | Port *int `json:"port,omitempty"` |
| 39 | HealthMonitor *int `json:"health_monitor,omitempty"` |
| 40 | SecGroupRule *int `json:"security_group_rule,omitempty"` |
| 41 | VIP *int `json:"vip,omitempty"` |
| 42 | SecGroup *int `json:"security_group,omitempty"` |
| 43 | Member *int `json:"member,omitempty"` |
| 44 | Pool *int `json:"pool,omitempty"` |
| 45 | } |
| 46 | |
| 47 | type request struct { |
| 48 | Quota quota `json:"quota"` |
| 49 | } |
| 50 | |
| 51 | reqBody := request{Quota: quota{ |
| 52 | Subnet: opts.Subnet, |
| 53 | Router: opts.Router, |
| 54 | Network: opts.Network, |
| 55 | FloatingIP: opts.FloatingIP, |
| 56 | Port: opts.Port, |
| 57 | HealthMonitor: opts.HealthMonitor, |
| 58 | SecGroupRule: opts.SecGroupRule, |
| 59 | VIP: opts.VIP, |
| 60 | SecGroup: opts.SecGroup, |
| 61 | Member: opts.Member, |
| 62 | Pool: opts.Pool, |
| 63 | }} |
| 64 | |
| 65 | var res UpdateResult |
| 66 | _, err := perigee.Request("PUT", rootURL(c), perigee.Options{ |
| 67 | MoreHeaders: c.Provider.AuthenticatedHeaders(), |
| 68 | ReqBody: &reqBody, |
| 69 | Results: &res.resp, |
| 70 | OkCodes: []int{200}, |
| 71 | }) |
| 72 | res.err = err |
| 73 | |
| 74 | return res |
| 75 | } |
| 76 | |
| 77 | func Reset(c *gophercloud.ServiceClient) DeleteResult { |
| 78 | var res DeleteResult |
| 79 | _, err := perigee.Request("DELETE", rootURL(c), perigee.Options{ |
| 80 | MoreHeaders: c.Provider.AuthenticatedHeaders(), |
| 81 | OkCodes: []int{204}, |
| 82 | }) |
| 83 | res.err = err |
| 84 | return res |
| 85 | } |