github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/evacuate/requests.go (about)

     1  package evacuate
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  // EvacuateOptsBuilder allows extensions to add additional parameters to the
     8  // the Evacuate request.
     9  type EvacuateOptsBuilder interface {
    10  	ToEvacuateMap() (map[string]interface{}, error)
    11  }
    12  
    13  // EvacuateOpts specifies Evacuate action parameters.
    14  type EvacuateOpts struct {
    15  	// The name of the host to which the server is evacuated
    16  	Host string `json:"host,omitempty"`
    17  
    18  	// Indicates whether server is on shared storage
    19  	OnSharedStorage bool `json:"onSharedStorage"`
    20  
    21  	// An administrative password to access the evacuated server
    22  	AdminPass string `json:"adminPass,omitempty"`
    23  }
    24  
    25  // ToServerGroupCreateMap constructs a request body from CreateOpts.
    26  func (opts EvacuateOpts) ToEvacuateMap() (map[string]interface{}, error) {
    27  	return golangsdk.BuildRequestBody(opts, "evacuate")
    28  }
    29  
    30  // Evacuate will Evacuate a failed instance to another host.
    31  func Evacuate(client *golangsdk.ServiceClient, id string, opts EvacuateOptsBuilder) (r EvacuateResult) {
    32  	b, err := opts.ToEvacuateMap()
    33  	if err != nil {
    34  		r.Err = err
    35  		return
    36  	}
    37  	_, r.Err = client.Post(actionURL(client, id), b, &r.Body, &golangsdk.RequestOpts{
    38  		OkCodes: []int{200},
    39  	})
    40  	return
    41  }