github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dcs/v1/instance/RestartOrFlushInstances.go (about)

     1  package instance
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type ChangeInstanceStatusOpts struct {
    10  	// List of DCS instance IDs.
    11  	Instances []string `json:"instances,omitempty"`
    12  	// Action performed on DCS instances. Options: restart, and flush.
    13  	// NOTE
    14  	// Only DCS Redis 4.0 and 5.0 instances can be flushed.
    15  	Action string `json:"action,omitempty"`
    16  }
    17  
    18  func RestartOrFlushInstances(client *golangsdk.ServiceClient, opts ChangeInstanceStatusOpts) ([]BatchOpsResult, error) {
    19  	b, err := build.RequestBody(opts, "")
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  
    24  	raw, err := client.Put(client.ServiceURL("instances", "status"), b, nil, &golangsdk.RequestOpts{
    25  		OkCodes: []int{204},
    26  	})
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	var res []BatchOpsResult
    32  	err = extract.IntoSlicePtr(raw.Body, &res, "results")
    33  	return res, err
    34  }
    35  
    36  type BatchOpsResult struct {
    37  	// Instance modification result. Options: success or failed
    38  	Result string `json:"result,omitempty"`
    39  	// DCS instance ID.
    40  	Instance string `json:"instance,omitempty"`
    41  }