github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cdm/v1/clusters/requests.go (about)

     1  package clusters
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/common/tags"
     6  )
     7  
     8  type ClusterCreateOpts struct {
     9  	Cluster ClusterRequest `json:"cluster" required:"true"`
    10  	// Whether to enable message notification. If this function is enabled, a maximum of five mobile numbers or email
    11  	// addresses can be set. When a table/file migration job fails or an EIP exception occurs,
    12  	// you will receive a notification by SMS message or email.
    13  	AutoRemind *bool `json:"auto_remind,omitempty"`
    14  	// Mobile number for receiving notifications
    15  	PhoneNum string `json:"phone_num,omitempty"`
    16  	// Email address for receiving notifications
    17  	Email string `json:"email,omitempty"`
    18  }
    19  
    20  type ClusterRequest struct {
    21  	// Time for scheduled startup of a CDM cluster. The CDM cluster starts at this time every day.
    22  	ScheduleBootTime string `json:"scheduleBootTime,omitempty"`
    23  	// Whether to enable the scheduled startup/shutdown function.
    24  	// The scheduled startup/shutdown and auto shutdown functions cannot be enabled at the same time.
    25  	IsScheduleBootOff *bool `json:"isScheduleBootOff,omitempty"`
    26  	// Node list.
    27  	Instances []InstanceReq `json:"instances,omitempty"`
    28  	// Cluster information. For details, see the description of the datastore parameter.
    29  	Datastore *Datastore `json:"datastore,omitempty"`
    30  	// Time for scheduled shutdown of a CDM cluster. The system shuts down directly at this time every day without waiting for unfinished jobs to complete.
    31  	ScheduleOffTime string `json:"scheduleOffTime,omitempty"`
    32  	// VPC ID, which is used for configuring a network for the cluster
    33  	VpcId string `json:"vpcId,omitempty"`
    34  	// Cluster name
    35  	Name string `json:"name,omitempty"`
    36  	// Enterprise project information. For details, see the description of the sys_tags parameter.
    37  	SysTags []tags.ResourceTag `json:"sys_tags,omitempty"`
    38  	// Whether to enable auto shutdown. The auto shutdown and scheduled startup/shutdown functions cannot be enabled at the same time. When auto shutdown is enabled, if no job is running in the cluster and no scheduled job is created, a cluster will be automatically shut down 15 minutes after it starts running to reduce costs.
    39  	IsAutoOff *bool `json:"isAutoOff,omitempty"`
    40  }
    41  
    42  type InstanceReq struct {
    43  	AvailabilityZone string `json:"availability_zone" required:"true"`
    44  	// NIC list. A maximum of two NICs are supported. For details, see the description of the nics parameter.
    45  	Nics      []Nics `json:"nics" required:"true"`
    46  	FlavorRef string `json:"flavorRef" required:"true"`
    47  	// Node type. Currently, only cdm is available.
    48  	Type string `json:"type" required:"true"`
    49  }
    50  
    51  type Nics struct {
    52  	SecurityGroupId string `json:"securityGroupId" required:"true"`
    53  	// Subnet ID
    54  	NetId string `json:"net-id" required:"true"`
    55  }
    56  
    57  type Datastore struct {
    58  	// Type. Generally, the value is cdm.
    59  	Type string `json:"type,omitempty"`
    60  	// Cluster version
    61  	Version string `json:"version,omitempty"`
    62  }
    63  
    64  type ClusterDeleteOpts struct {
    65  	// Number of backup log files. Retain the default value 0.
    66  	KeepLastManualBackup int `q:"keep_last_manual_backup"`
    67  }
    68  
    69  type RestartReq struct {
    70  	Restart RestartConfig `json:"restart" required:"true"`
    71  }
    72  
    73  type RestartConfig struct {
    74  	// Restart delay, in seconds
    75  	RestartDelayTime *int `json:"restartDelayTime,omitempty"`
    76  	// Restart mode. The options are as follows:
    77  	// IMMEDIATELY: immediate restart
    78  	// GRACEFULL: graceful restart
    79  	// FORCELY: forcible restart
    80  	// SOFTLY: normal restart
    81  	// The default value is IMMEDIATELY.
    82  	RestartMode string `json:"restartMode,omitempty"`
    83  	// Restart level. The options are as follows:
    84  	// SERVICE: service restart
    85  	// VM: VM restart
    86  	// The default value is SERVICE.
    87  	RestartLevel string `json:"restartLevel,omitempty"`
    88  	Type         string `json:"type,omitempty"`
    89  	// Reserved field. When restartLevel is set to SERVICE,
    90  	// this parameter is mandatory and an empty string should be entered.
    91  	Instance string `json:"instance,omitempty"`
    92  	// Reserved field. When restartLevel is set to SERVICE,
    93  	// this parameter is mandatory and an empty string should be entered.
    94  	Group string `json:"group,omitempty"`
    95  }
    96  
    97  type StartOpts struct {
    98  	Start map[string]string `json:"start" required:"true"`
    99  }
   100  
   101  type StopOpts struct {
   102  	Stop StopConfig `json:"stop" required:"true"`
   103  }
   104  
   105  type StopConfig struct {
   106  	// Stop type. The options are as follows:
   107  	// IMMEDIATELY: immediate stop
   108  	// GRACEFULLY: graceful stop
   109  	// Enumeration values:
   110  	// IMMEDIATELY
   111  	// GRACEFULLY
   112  	StopMode string `json:"stopMode"`
   113  	// Stop delay, in seconds. This parameter is valid only when stopMode is set to GRACEFULLY.
   114  	// If the value of this parameter is set to -1, the system waits for all jobs to complete and stops accepting
   115  	// new jobs. If the value of this parameter is greater than 0, the system stops the cluster after
   116  	// the specified time and stops accepting new jobs.
   117  	DelayTime *int `json:"delayTime"`
   118  }
   119  
   120  var RequestOpts = golangsdk.RequestOpts{
   121  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
   122  }
   123  
   124  func Create(c *golangsdk.ServiceClient, opts ClusterCreateOpts) (*ClusterCreateResult, error) {
   125  	b, err := golangsdk.BuildRequestBody(opts, "")
   126  	if err != nil {
   127  		return nil, err
   128  	}
   129  
   130  	var r ClusterCreateResult
   131  	_, err = c.Post(createURL(c), b, &r, &golangsdk.RequestOpts{
   132  		MoreHeaders: RequestOpts.MoreHeaders,
   133  	})
   134  	return &r, err
   135  }
   136  
   137  func Delete(c *golangsdk.ServiceClient, clusterId string, opts ClusterDeleteOpts) *golangsdk.ErrResult {
   138  	var r golangsdk.ErrResult
   139  
   140  	url := deleteURL(c, clusterId)
   141  	b, err := golangsdk.BuildRequestBody(opts, "")
   142  	if err != nil {
   143  		r.Err = err
   144  		return &r
   145  	}
   146  
   147  	_, r.Err = c.DeleteWithBody(url, b, &golangsdk.RequestOpts{
   148  		MoreHeaders: RequestOpts.MoreHeaders,
   149  	})
   150  	return &r
   151  }
   152  
   153  func List(c *golangsdk.ServiceClient) (*ClustersRepsonse, error) {
   154  	var rst ClustersRepsonse
   155  	_, err := c.Get(listURL(c), &rst, &golangsdk.RequestOpts{
   156  		MoreHeaders: RequestOpts.MoreHeaders,
   157  	})
   158  	return &rst, err
   159  }
   160  
   161  func Restart(c *golangsdk.ServiceClient, clusterId string, opts RestartReq) (*Job, error) {
   162  	b, err := golangsdk.BuildRequestBody(opts, "")
   163  	if err != nil {
   164  		return nil, err
   165  	}
   166  
   167  	var rst Job
   168  	_, err = c.Post(restartURL(c, clusterId), b, &rst, &golangsdk.RequestOpts{
   169  		MoreHeaders: RequestOpts.MoreHeaders,
   170  	})
   171  	return &rst, err
   172  }
   173  
   174  func Get(c *golangsdk.ServiceClient, clusterId string) (*Cluster, error) {
   175  	var rst Cluster
   176  	_, err := c.Get(getURL(c, clusterId), &rst, &golangsdk.RequestOpts{
   177  		MoreHeaders: RequestOpts.MoreHeaders,
   178  	})
   179  	return &rst, err
   180  }
   181  
   182  func Start(c *golangsdk.ServiceClient, clusterId string, opts StartOpts) (*ActionResponse, error) {
   183  	b, err := golangsdk.BuildRequestBody(opts, "")
   184  	if err != nil {
   185  		return nil, err
   186  	}
   187  
   188  	var rst ActionResponse
   189  	_, err = c.Post(actionURL(c, clusterId), b, &rst, &golangsdk.RequestOpts{
   190  		MoreHeaders: RequestOpts.MoreHeaders,
   191  	})
   192  	return &rst, err
   193  }
   194  
   195  func Stop(c *golangsdk.ServiceClient, clusterId string, opts StopConfig) (*ActionResponse, error) {
   196  	b, err := golangsdk.BuildRequestBody(opts, "")
   197  	if err != nil {
   198  		return nil, err
   199  	}
   200  
   201  	var rst ActionResponse
   202  	_, err = c.Post(actionURL(c, clusterId), b, &rst, &golangsdk.RequestOpts{
   203  		MoreHeaders: RequestOpts.MoreHeaders,
   204  	})
   205  	return &rst, err
   206  }