github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dataarts/v1.1/cluster/Stop.go (about)

     1  package cluster
     2  
     3  import (
     4  	"net/http"
     5  
     6  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     9  )
    10  
    11  type StopOpts struct {
    12  	Id   string     `json:"-"`
    13  	Stop StopStruct `json:"stop" required:"true"`
    14  }
    15  
    16  type StopStruct struct {
    17  	StopMode  string `json:"stopMode,omitempty"`
    18  	DelayTime string `json:"delayTime,omitempty"`
    19  }
    20  
    21  func Stop(client *golangsdk.ServiceClient, opts StopOpts) (*JobId, error) {
    22  	b, err := build.RequestBody(opts, "")
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	// POST /v1.1/{project_id}/clusters/{cluster_id}/action
    27  	raw, err := client.Post(client.ServiceURL("clusters", opts.Id, "action"), b, nil, &golangsdk.RequestOpts{
    28  		MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en"},
    29  	})
    30  	return extraJob(err, raw)
    31  }
    32  
    33  type JobId struct {
    34  	JobId []string `json:"jobId"`
    35  }
    36  
    37  func extraJob(err error, raw *http.Response) (*JobId, error) {
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	var res JobId
    43  	err = extract.Into(raw.Body, &res)
    44  	return &res, err
    45  }