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