github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/rescueunrescue/requests.go (about)

     1  package rescueunrescue
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions"
     6  )
     7  
     8  // RescueOptsBuilder is an interface that allows extensions to override the
     9  // default structure of a Rescue request.
    10  type RescueOptsBuilder interface {
    11  	ToServerRescueMap() (map[string]interface{}, error)
    12  }
    13  
    14  // RescueOpts represents the configuration options used to control a Rescue
    15  // option.
    16  type RescueOpts struct {
    17  	// AdminPass is the desired administrative password for the instance in
    18  	// RESCUE mode.
    19  	// If it's left blank, the server will generate a password.
    20  	AdminPass string `json:"adminPass,omitempty"`
    21  
    22  	// RescueImageRef contains reference on an image that needs to be used as
    23  	// rescue image.
    24  	// If it's left blank, the server will be rescued with the default image.
    25  	RescueImageRef string `json:"rescue_image_ref,omitempty"`
    26  }
    27  
    28  // ToServerRescueMap formats a RescueOpts as a map that can be used as a JSON
    29  // request body for the Rescue request.
    30  func (opts RescueOpts) ToServerRescueMap() (map[string]interface{}, error) {
    31  	return gophercloud.BuildRequestBody(opts, "rescue")
    32  }
    33  
    34  // Rescue instructs the provider to place the server into RESCUE mode.
    35  func Rescue(client *gophercloud.ServiceClient, id string, opts RescueOptsBuilder) (r RescueResult) {
    36  	b, err := opts.ToServerRescueMap()
    37  	if err != nil {
    38  		r.Err = err
    39  		return
    40  	}
    41  	resp, err := client.Post(extensions.ActionURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
    42  		OkCodes: []int{200},
    43  	})
    44  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    45  	return
    46  }
    47  
    48  // Unrescue instructs the provider to return the server from RESCUE mode.
    49  func Unrescue(client *gophercloud.ServiceClient, id string) (r UnrescueResult) {
    50  	resp, err := client.Post(extensions.ActionURL(client, id), map[string]interface{}{"unrescue": nil}, nil, nil)
    51  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    52  	return
    53  }