Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 1 | package servers |
| 2 | |
| 3 | import ( |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 4 | "fmt" |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 5 | |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 6 | "github.com/racker/perigee" |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud" |
| 8 | "github.com/rackspace/gophercloud/pagination" |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 9 | ) |
| 10 | |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 11 | // List makes a request against the API to list servers accessible to you. |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 12 | func List(client *gophercloud.ServiceClient) pagination.Pager { |
| 13 | createPage := func(r pagination.LastHTTPResponse) pagination.Page { |
Ash Wilson | 397c78b | 2014-09-25 15:19:14 -0400 | [diff] [blame] | 14 | return ServerPage{pagination.LinkedPageBase{LastHTTPResponse: r}} |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 15 | } |
| 16 | |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 17 | return pagination.NewPager(client, detailURL(client), createPage) |
Samuel A. Falvo II | c007c27 | 2014-02-10 20:49:26 -0800 | [diff] [blame] | 18 | } |
| 19 | |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 20 | // Create requests a server to be provisioned to the user in the current tenant. |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 21 | func Create(client *gophercloud.ServiceClient, opts map[string]interface{}) CreateResult { |
| 22 | var result CreateResult |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 23 | _, result.Err = perigee.Request("POST", listURL(client), perigee.Options{ |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 24 | Results: &result.Resp, |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 25 | ReqBody: map[string]interface{}{ |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 26 | "server": opts, |
| 27 | }, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 28 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 29 | OkCodes: []int{202}, |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 30 | }) |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 31 | return result |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // Delete requests that a server previously provisioned be removed from your account. |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 35 | func Delete(client *gophercloud.ServiceClient, id string) error { |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 36 | _, err := perigee.Request("DELETE", serverURL(client, id), perigee.Options{ |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 37 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 38 | OkCodes: []int{204}, |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 39 | }) |
| 40 | return err |
| 41 | } |
| 42 | |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame] | 43 | // Get requests details on a single server, by ID. |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 44 | func Get(client *gophercloud.ServiceClient, id string) GetResult { |
| 45 | var result GetResult |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 46 | _, result.Err = perigee.Request("GET", serverURL(client, id), perigee.Options{ |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 47 | Results: &result.Resp, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 48 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 49 | }) |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 50 | return result |
Samuel A. Falvo II | ce00073 | 2014-02-13 18:53:53 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 53 | // Update requests that various attributes of the indicated server be changed. |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 54 | func Update(client *gophercloud.ServiceClient, id string, opts map[string]interface{}) UpdateResult { |
| 55 | var result UpdateResult |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 56 | _, result.Err = perigee.Request("PUT", serverURL(client, id), perigee.Options{ |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 57 | Results: &result.Resp, |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 58 | ReqBody: map[string]interface{}{ |
| 59 | "server": opts, |
| 60 | }, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 61 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 62 | }) |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 63 | return result |
Samuel A. Falvo II | 22d3b77 | 2014-02-13 19:27:05 -0800 | [diff] [blame] | 64 | } |
Samuel A. Falvo II | ca5f9a3 | 2014-03-11 17:52:58 -0700 | [diff] [blame] | 65 | |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 66 | // ChangeAdminPassword alters the administrator or root password for a specified server. |
| 67 | func ChangeAdminPassword(client *gophercloud.ServiceClient, id, newPassword string) error { |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 68 | var req struct { |
| 69 | ChangePassword struct { |
| 70 | AdminPass string `json:"adminPass"` |
| 71 | } `json:"changePassword"` |
| 72 | } |
| 73 | |
| 74 | req.ChangePassword.AdminPass = newPassword |
| 75 | |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 76 | _, err := perigee.Request("POST", actionURL(client, id), perigee.Options{ |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 77 | ReqBody: req, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 78 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 79 | OkCodes: []int{202}, |
Samuel A. Falvo II | ca5f9a3 | 2014-03-11 17:52:58 -0700 | [diff] [blame] | 80 | }) |
| 81 | return err |
| 82 | } |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 83 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 84 | // ErrArgument errors occur when an argument supplied to a package function |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 85 | // fails to fall within acceptable values. For example, the Reboot() function |
| 86 | // expects the "how" parameter to be one of HardReboot or SoftReboot. These |
| 87 | // constants are (currently) strings, leading someone to wonder if they can pass |
| 88 | // other string values instead, perhaps in an effort to break the API of their |
| 89 | // provider. Reboot() returns this error in this situation. |
| 90 | // |
| 91 | // Function identifies which function was called/which function is generating |
| 92 | // the error. |
| 93 | // Argument identifies which formal argument was responsible for producing the |
| 94 | // error. |
| 95 | // Value provides the value as it was passed into the function. |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 96 | type ErrArgument struct { |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 97 | Function, Argument string |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 98 | Value interface{} |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // Error yields a useful diagnostic for debugging purposes. |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 102 | func (e *ErrArgument) Error() string { |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 103 | return fmt.Sprintf("Bad argument in call to %s, formal parameter %s, value %#v", e.Function, e.Argument, e.Value) |
| 104 | } |
| 105 | |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 106 | func (e *ErrArgument) String() string { |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 107 | return e.Error() |
| 108 | } |
| 109 | |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 110 | // RebootMethod describes the mechanisms by which a server reboot can be requested. |
| 111 | type RebootMethod string |
| 112 | |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 113 | // These constants determine how a server should be rebooted. |
| 114 | // See the Reboot() function for further details. |
| 115 | const ( |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 116 | SoftReboot RebootMethod = "SOFT" |
| 117 | HardReboot RebootMethod = "HARD" |
| 118 | OSReboot = SoftReboot |
| 119 | PowerCycle = HardReboot |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 120 | ) |
| 121 | |
| 122 | // Reboot requests that a given server reboot. |
| 123 | // Two methods exist for rebooting a server: |
| 124 | // |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 125 | // HardReboot (aka PowerCycle) restarts the server instance by physically cutting power to the machine, or if a VM, |
| 126 | // terminating it at the hypervisor level. |
| 127 | // It's done. Caput. Full stop. |
| 128 | // Then, after a brief while, power is restored or the VM instance restarted. |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 129 | // |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 130 | // SoftReboot (aka OSReboot) simply tells the OS to restart under its own procedures. |
| 131 | // E.g., in Linux, asking it to enter runlevel 6, or executing "sudo shutdown -r now", or by asking Windows to restart the machine. |
| 132 | func Reboot(client *gophercloud.ServiceClient, id string, how RebootMethod) error { |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 133 | if (how != SoftReboot) && (how != HardReboot) { |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 134 | return &ErrArgument{ |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 135 | Function: "Reboot", |
| 136 | Argument: "how", |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 137 | Value: how, |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 140 | |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 141 | _, err := perigee.Request("POST", actionURL(client, id), perigee.Options{ |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 142 | ReqBody: struct { |
| 143 | C map[string]string `json:"reboot"` |
| 144 | }{ |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 145 | map[string]string{"type": string(how)}, |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 146 | }, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 147 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 148 | OkCodes: []int{202}, |
Samuel A. Falvo II | 41c9f61 | 2014-03-11 19:00:10 -0700 | [diff] [blame] | 149 | }) |
| 150 | return err |
| 151 | } |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 152 | |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 153 | // Rebuild requests that the Openstack provider reprovision the server. |
| 154 | // The rebuild will need to know the server's name and new image reference or ID. |
| 155 | // In addition, and unlike building a server with Create(), you must provide an administrator password. |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 156 | // |
| 157 | // Additional options may be specified with the additional map. |
| 158 | // This function treats a nil map the same as an empty map. |
| 159 | // |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 160 | // Rebuild returns a server result as though you had called GetDetail() on the server's ID. |
| 161 | // The information, however, refers to the new server, not the old. |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 162 | func Rebuild(client *gophercloud.ServiceClient, id, name, password, imageRef string, additional map[string]interface{}) RebuildResult { |
| 163 | var result RebuildResult |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 164 | |
| 165 | if id == "" { |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 166 | result.Err = &ErrArgument{ |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 167 | Function: "Rebuild", |
| 168 | Argument: "id", |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 169 | Value: "", |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 170 | } |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 171 | return result |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | if name == "" { |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 175 | result.Err = &ErrArgument{ |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 176 | Function: "Rebuild", |
| 177 | Argument: "name", |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 178 | Value: "", |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 179 | } |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 180 | return result |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | if password == "" { |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 184 | result.Err = &ErrArgument{ |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 185 | Function: "Rebuild", |
| 186 | Argument: "password", |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 187 | Value: "", |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 188 | } |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 189 | return result |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | if imageRef == "" { |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 193 | result.Err = &ErrArgument{ |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 194 | Function: "Rebuild", |
| 195 | Argument: "imageRef", |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 196 | Value: "", |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 197 | } |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 198 | return result |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | if additional == nil { |
| 202 | additional = make(map[string]interface{}, 0) |
| 203 | } |
| 204 | |
| 205 | additional["name"] = name |
| 206 | additional["imageRef"] = imageRef |
| 207 | additional["adminPass"] = password |
| 208 | |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 209 | _, result.Err = perigee.Request("POST", actionURL(client, id), perigee.Options{ |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 210 | ReqBody: struct { |
| 211 | R map[string]interface{} `json:"rebuild"` |
| 212 | }{ |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 213 | additional, |
| 214 | }, |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 215 | Results: &result.Resp, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 216 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 217 | OkCodes: []int{202}, |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 218 | }) |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 219 | return result |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // Resize instructs the provider to change the flavor of the server. |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 223 | // Note that this implies rebuilding it. |
| 224 | // Unfortunately, one cannot pass rebuild parameters to the resize function. |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 225 | // When the resize completes, the server will be in RESIZE_VERIFY state. |
| 226 | // While in this state, you can explore the use of the new server's configuration. |
| 227 | // If you like it, call ConfirmResize() to commit the resize permanently. |
| 228 | // Otherwise, call RevertResize() to restore the old configuration. |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 229 | func Resize(client *gophercloud.ServiceClient, id, flavorRef string) error { |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 230 | _, err := perigee.Request("POST", actionURL(client, id), perigee.Options{ |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 231 | ReqBody: struct { |
| 232 | R map[string]interface{} `json:"resize"` |
| 233 | }{ |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 234 | map[string]interface{}{"flavorRef": flavorRef}, |
| 235 | }, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 236 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 237 | OkCodes: []int{202}, |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 238 | }) |
| 239 | return err |
| 240 | } |
| 241 | |
| 242 | // ConfirmResize confirms a previous resize operation on a server. |
| 243 | // See Resize() for more details. |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 244 | func ConfirmResize(client *gophercloud.ServiceClient, id string) error { |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 245 | _, err := perigee.Request("POST", actionURL(client, id), perigee.Options{ |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 246 | ReqBody: map[string]interface{}{"confirmResize": nil}, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 247 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 248 | OkCodes: []int{204}, |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 249 | }) |
| 250 | return err |
| 251 | } |
| 252 | |
| 253 | // RevertResize cancels a previous resize operation on a server. |
| 254 | // See Resize() for more details. |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 255 | func RevertResize(client *gophercloud.ServiceClient, id string) error { |
Ash Wilson | 31f6bde | 2014-09-25 14:52:12 -0400 | [diff] [blame] | 256 | _, err := perigee.Request("POST", actionURL(client, id), perigee.Options{ |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 257 | ReqBody: map[string]interface{}{"revertResize": nil}, |
Ash Wilson | 01626a3 | 2014-09-17 10:38:07 -0400 | [diff] [blame] | 258 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Jon Perritt | 3055864 | 2014-04-14 17:07:12 -0500 | [diff] [blame] | 259 | OkCodes: []int{202}, |
Samuel A. Falvo II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 260 | }) |
| 261 | return err |
| 262 | } |