blob: 7810d156a0fbb58b9ad6a520bb8992ce5818b032 [file] [log] [blame]
Ash Wilson92457e92014-10-20 15:18:23 -04001package servers
Ash Wilsone5963982014-10-21 10:04:01 -04002
3import (
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.
10func 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.
15func Create(client *gophercloud.ServiceClient, opts os.CreateOptsBuilder) os.CreateResult {
16 return os.Create(client, opts)
17}
18
Jon Perritt723a24b2015-02-02 10:06:42 -070019// Update requests an existing server to be updated with the supplied options.
Jon Perritte5940aa2015-02-01 22:08:23 -070020func Update(client *gophercloud.ServiceClient, id string, opts os.UpdateOptsBuilder) os.UpdateResult {
21 return os.Update(client, id, opts)
22}
23
Ash Wilsone5963982014-10-21 10:04:01 -040024// Delete requests that a server previously provisioned be removed from your account.
Jamie Hannaford7bc317d2014-10-27 11:41:52 +010025func Delete(client *gophercloud.ServiceClient, id string) os.DeleteResult {
Ash Wilsone5963982014-10-21 10:04:01 -040026 return os.Delete(client, id)
27}
28
29// Get requests details on a single server, by ID.
30func 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.
35func 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.
47func 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.
53func Rebuild(client *gophercloud.ServiceClient, id string, opts os.RebuildOptsBuilder) os.RebuildResult {
54 return os.Rebuild(client, id, opts)
55}
56
Jon Perritt36747e42015-04-08 11:17:36 -060057// 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.
Jon Perrittf8b77ca2015-04-08 11:43:39 -060064func Resize(client *gophercloud.ServiceClient, id string, opts os.ResizeOptsBuilder) os.ActionResult {
Jon Perritt36747e42015-04-08 11:17:36 -060065 return os.Resize(client, id, opts)
66}
67
Jon Perritt1f3caa62015-04-08 11:20:43 -060068// ConfirmResize confirms a previous resize operation on a server.
69// See Resize() for more details.
70func ConfirmResize(client *gophercloud.ServiceClient, id string) os.ActionResult {
71 return os.ConfirmResize(client, id)
72}
73
Ash Wilsone5963982014-10-21 10:04:01 -040074// 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.
76func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error {
77 return os.WaitForStatus(c, id, status, secs)
78}
Ash Wilsonbee34e22014-10-21 14:04:27 -040079
80// ExtractServers interprets the results of a single page from a List() call, producing a slice of Server entities.
81func ExtractServers(page pagination.Page) ([]os.Server, error) {
82 return os.ExtractServers(page)
83}
Jon Perritt7ed68552015-02-20 09:37:42 -070084
85// ListAddresses makes a request against the API to list the servers IP addresses.
86func 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.
91func 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.
97func 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 Perrittb51ba9c2015-02-23 10:56:35 -0700102func ExtractNetworkAddresses(page pagination.Page) ([]os.Address, error) {
Jon Perritt7ed68552015-02-20 09:37:42 -0700103 return os.ExtractNetworkAddresses(page)
104}
Jon Perritt33fd1b32015-04-08 11:23:37 -0600105
106// Metadata requests all the metadata for the given server ID.
107func 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.
114func UpdateMetadata(client *gophercloud.ServiceClient, id string, opts os.UpdateMetadataOptsBuilder) os.UpdateMetadataResult {
115 return os.UpdateMetadata(client, id, opts)
116}