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 | |
Jon Perritt | 723a24b | 2015-02-02 10:06:42 -0700 | [diff] [blame] | 19 | // Update requests an existing server to be updated with the supplied options. |
Jon Perritt | e5940aa | 2015-02-01 22:08:23 -0700 | [diff] [blame] | 20 | func Update(client *gophercloud.ServiceClient, id string, opts os.UpdateOptsBuilder) os.UpdateResult { |
| 21 | return os.Update(client, id, opts) |
| 22 | } |
| 23 | |
Ash Wilson | e596398 | 2014-10-21 10:04:01 -0400 | [diff] [blame] | 24 | // Delete requests that a server previously provisioned be removed from your account. |
Jamie Hannaford | 7bc317d | 2014-10-27 11:41:52 +0100 | [diff] [blame] | 25 | func Delete(client *gophercloud.ServiceClient, id string) os.DeleteResult { |
Ash Wilson | e596398 | 2014-10-21 10:04:01 -0400 | [diff] [blame] | 26 | return os.Delete(client, id) |
| 27 | } |
| 28 | |
| 29 | // Get requests details on a single server, by ID. |
| 30 | func Get(client *gophercloud.ServiceClient, id string) os.GetResult { |
| 31 | return os.Get(client, id) |
| 32 | } |
| 33 | |
| 34 | // ChangeAdminPassword alters the administrator or root password for a specified server. |
| 35 | func ChangeAdminPassword(client *gophercloud.ServiceClient, id, newPassword string) os.ActionResult { |
| 36 | return os.ChangeAdminPassword(client, id, newPassword) |
| 37 | } |
| 38 | |
| 39 | // Reboot requests that a given server reboot. Two methods exist for rebooting a server: |
| 40 | // |
| 41 | // os.HardReboot (aka PowerCycle) restarts the server instance by physically cutting power to the |
| 42 | // machine, or if a VM, terminating it at the hypervisor level. It's done. Caput. Full stop. Then, |
| 43 | // after a brief wait, power is restored or the VM instance restarted. |
| 44 | // |
| 45 | // os.SoftReboot (aka OSReboot) simply tells the OS to restart under its own procedures. E.g., in |
| 46 | // Linux, asking it to enter runlevel 6, or executing "sudo shutdown -r now", or by asking Windows to restart the machine. |
| 47 | func Reboot(client *gophercloud.ServiceClient, id string, how os.RebootMethod) os.ActionResult { |
| 48 | return os.Reboot(client, id, how) |
| 49 | } |
| 50 | |
| 51 | // Rebuild will reprovision the server according to the configuration options provided in the |
| 52 | // RebuildOpts struct. |
| 53 | func Rebuild(client *gophercloud.ServiceClient, id string, opts os.RebuildOptsBuilder) os.RebuildResult { |
| 54 | return os.Rebuild(client, id, opts) |
| 55 | } |
| 56 | |
Jon Perritt | 36747e4 | 2015-04-08 11:17:36 -0600 | [diff] [blame] | 57 | // Resize instructs the provider to change the flavor of the server. |
| 58 | // Note that this implies rebuilding it. |
| 59 | // Unfortunately, one cannot pass rebuild parameters to the resize function. |
| 60 | // When the resize completes, the server will be in RESIZE_VERIFY state. |
| 61 | // While in this state, you can explore the use of the new server's configuration. |
| 62 | // If you like it, call ConfirmResize() to commit the resize permanently. |
| 63 | // Otherwise, call RevertResize() to restore the old configuration. |
| 64 | func Resize(client *gophercloud.ServiceClient, id string, opts os.ResizeOpts) os.ActionResult { |
| 65 | return os.Resize(client, id, opts) |
| 66 | } |
| 67 | |
Jon Perritt | 1f3caa6 | 2015-04-08 11:20:43 -0600 | [diff] [blame] | 68 | // ConfirmResize confirms a previous resize operation on a server. |
| 69 | // See Resize() for more details. |
| 70 | func ConfirmResize(client *gophercloud.ServiceClient, id string) os.ActionResult { |
| 71 | return os.ConfirmResize(client, id) |
| 72 | } |
| 73 | |
Ash Wilson | e596398 | 2014-10-21 10:04:01 -0400 | [diff] [blame] | 74 | // WaitForStatus will continually poll a server until it successfully transitions to a specified |
| 75 | // status. It will do this for at most the number of seconds specified. |
| 76 | func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error { |
| 77 | return os.WaitForStatus(c, id, status, secs) |
| 78 | } |
Ash Wilson | bee34e2 | 2014-10-21 14:04:27 -0400 | [diff] [blame] | 79 | |
| 80 | // ExtractServers interprets the results of a single page from a List() call, producing a slice of Server entities. |
| 81 | func ExtractServers(page pagination.Page) ([]os.Server, error) { |
| 82 | return os.ExtractServers(page) |
| 83 | } |
Jon Perritt | 7ed6855 | 2015-02-20 09:37:42 -0700 | [diff] [blame] | 84 | |
| 85 | // ListAddresses makes a request against the API to list the servers IP addresses. |
| 86 | func ListAddresses(client *gophercloud.ServiceClient, id string) pagination.Pager { |
| 87 | return os.ListAddresses(client, id) |
| 88 | } |
| 89 | |
| 90 | // ExtractAddresses interprets the results of a single page from a ListAddresses() call, producing a map of Address slices. |
| 91 | func ExtractAddresses(page pagination.Page) (map[string][]os.Address, error) { |
| 92 | return os.ExtractAddresses(page) |
| 93 | } |
| 94 | |
| 95 | // ListAddressesByNetwork makes a request against the API to list the servers IP addresses |
| 96 | // for the given network. |
| 97 | func ListAddressesByNetwork(client *gophercloud.ServiceClient, id, network string) pagination.Pager { |
| 98 | return os.ListAddressesByNetwork(client, id, network) |
| 99 | } |
| 100 | |
| 101 | // ExtractNetworkAddresses interprets the results of a single page from a ListAddressesByNetwork() call, producing a map of Address slices. |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 102 | func ExtractNetworkAddresses(page pagination.Page) ([]os.Address, error) { |
Jon Perritt | 7ed6855 | 2015-02-20 09:37:42 -0700 | [diff] [blame] | 103 | return os.ExtractNetworkAddresses(page) |
| 104 | } |
Jon Perritt | 33fd1b3 | 2015-04-08 11:23:37 -0600 | [diff] [blame] | 105 | |
| 106 | // Metadata requests all the metadata for the given server ID. |
| 107 | func Metadata(client *gophercloud.ServiceClient, id string) os.GetMetadataResult { |
| 108 | return os.Metadata(client, id) |
| 109 | } |
| 110 | |
| 111 | // UpdateMetadata updates (or creates) all the metadata specified by opts for the given server ID. |
| 112 | // This operation does not affect already-existing metadata that is not specified |
| 113 | // by opts. |
| 114 | func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts os.UpdateMetadataOptsBuilder) os.UpdateMetadataResult { |
| 115 | return os.UpdateMetadata(client, id, opts) |
| 116 | } |