github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ecs/v1/powers/requests.go (about) 1 package powers 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/openstack/ecs/v1/cloudservers" 6 ) 7 8 // PowerOpts allows batch update of the ECS instances power state through the API. 9 // Parameter 'Type' supports two methods of 'SOFT' and 'HARD' to shut down and reboot the machine's power. 10 type PowerOpts struct { 11 Servers []ServerInfo `json:"servers" required:"true"` 12 Type string `json:"type,omitempty"` 13 } 14 15 type ServerInfo struct { 16 ID string `json:"id" required:"true"` 17 } 18 19 // PowerOptsBuilder allows extensions to add additional parameters to the PowerAction(power on/off and reboot) request. 20 type PowerOptsBuilder interface { 21 ToPowerActionMap(option string) (map[string]interface{}, error) 22 } 23 24 // ToPowerActionMap assembles a request body based on the contents of a PowerOpts and the power option parameter. 25 func (opts PowerOpts) ToPowerActionMap(option string) (map[string]interface{}, error) { 26 return golangsdk.BuildRequestBody(opts, option) 27 } 28 29 // PowerAction uses a option parameter to control the power state of the ECS instance. 30 // The option only supports 'os-start' (power on), 'os-stop' (power off) and 'reboot'. 31 func PowerAction(client *golangsdk.ServiceClient, opts PowerOptsBuilder, option string) (r cloudservers.JobResult) { 32 reqBody, err := opts.ToPowerActionMap(option) 33 if err != nil { 34 r.Err = err 35 return 36 } 37 _, r.Err = client.Post(actionURL(client), reqBody, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) 38 return 39 }