Ash Wilson | 92457e9 | 2014-10-20 15:18:23 -0400 | [diff] [blame] | 1 | package servers |
Ash Wilson | e596398 | 2014-10-21 10:04:01 -0400 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | os "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
| 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | ) |
| 8 | |
| 9 | // List makes a request against the API to list servers accessible to you. |
| 10 | func List(client *gophercloud.ServiceClient, opts os.ListOptsBuilder) pagination.Pager { |
| 11 | return os.List(client, opts) |
| 12 | } |
| 13 | |
| 14 | // Create requests a server to be provisioned to the user in the current tenant. |
| 15 | func Create(client *gophercloud.ServiceClient, opts os.CreateOptsBuilder) os.CreateResult { |
| 16 | return os.Create(client, opts) |
| 17 | } |
| 18 | |
| 19 | // Delete requests that a server previously provisioned be removed from your account. |
| 20 | func Delete(client *gophercloud.ServiceClient, id string) error { |
| 21 | return os.Delete(client, id) |
| 22 | } |
| 23 | |
| 24 | // Get requests details on a single server, by ID. |
| 25 | func Get(client *gophercloud.ServiceClient, id string) os.GetResult { |
| 26 | return os.Get(client, id) |
| 27 | } |
| 28 | |
| 29 | // ChangeAdminPassword alters the administrator or root password for a specified server. |
| 30 | func ChangeAdminPassword(client *gophercloud.ServiceClient, id, newPassword string) os.ActionResult { |
| 31 | return os.ChangeAdminPassword(client, id, newPassword) |
| 32 | } |
| 33 | |
| 34 | // Reboot requests that a given server reboot. Two methods exist for rebooting a server: |
| 35 | // |
| 36 | // os.HardReboot (aka PowerCycle) restarts the server instance by physically cutting power to the |
| 37 | // machine, or if a VM, terminating it at the hypervisor level. It's done. Caput. Full stop. Then, |
| 38 | // after a brief wait, power is restored or the VM instance restarted. |
| 39 | // |
| 40 | // os.SoftReboot (aka OSReboot) simply tells the OS to restart under its own procedures. E.g., in |
| 41 | // Linux, asking it to enter runlevel 6, or executing "sudo shutdown -r now", or by asking Windows to restart the machine. |
| 42 | func Reboot(client *gophercloud.ServiceClient, id string, how os.RebootMethod) os.ActionResult { |
| 43 | return os.Reboot(client, id, how) |
| 44 | } |
| 45 | |
| 46 | // Rebuild will reprovision the server according to the configuration options provided in the |
| 47 | // RebuildOpts struct. |
| 48 | func Rebuild(client *gophercloud.ServiceClient, id string, opts os.RebuildOptsBuilder) os.RebuildResult { |
| 49 | return os.Rebuild(client, id, opts) |
| 50 | } |
| 51 | |
| 52 | // Resize instructs the provider to change the flavor of the server. Note that this implies |
| 53 | // rebuilding it. Unfortunately, one cannot pass rebuild parameters to the resize function. When the |
| 54 | // resize completes, the server will be in RESIZE_VERIFY state. While in this state, you can explore |
| 55 | // the use of the new server's configuration. If you like it, call ConfirmResize() to commit the |
| 56 | // resize permanently. Otherwise, call RevertResize() to restore the old configuration. |
| 57 | // |
| 58 | // Note that only Rackspace servers with standard flavors can be resized. |
| 59 | func Resize(client *gophercloud.ServiceClient, id, flavorRef string) os.ActionResult { |
| 60 | return os.Resize(client, id, flavorRef) |
| 61 | } |
| 62 | |
| 63 | // ConfirmResize confirms a previous resize operation on a server. See Resize() for more details. |
| 64 | func ConfirmResize(client *gophercloud.ServiceClient, id string) os.ActionResult { |
| 65 | return os.ConfirmResize(client, id) |
| 66 | } |
| 67 | |
| 68 | // RevertResize cancels a previous resize operation on a server. See Resize() for more details. |
| 69 | func RevertResize(client *gophercloud.ServiceClient, id string) os.ActionResult { |
| 70 | return os.RevertResize(client, id) |
| 71 | } |
| 72 | |
| 73 | // WaitForStatus will continually poll a server until it successfully transitions to a specified |
| 74 | // status. It will do this for at most the number of seconds specified. |
| 75 | func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error { |
| 76 | return os.WaitForStatus(c, id, status, secs) |
| 77 | } |