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

     1  package cluster
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/common/tags"
     6  )
     7  
     8  const (
     9  	// Instance type. The options are ess, ess-cold, ess-master, and ess-client.
    10  	InstanceTypeEss       = "ess"
    11  	InstanceTypeEssCode   = "ess-cold"
    12  	InstanceTypeEssMaster = "ess-master"
    13  	InstanceTypeEssClient = "ess-client"
    14  
    15  	ClusterStatusInProcess   = "100" //The operation, such as instance creation, is in progress.
    16  	ClusterStatusAvailable   = "200"
    17  	ClusterStatusUnavailable = "303"
    18  )
    19  
    20  // Opts
    21  type CreateOpts struct {
    22  	// Instance. For details about related parameters, see Table 4.
    23  	Instance *InstanceBody `json:"instance" required:"true"`
    24  	// Type of the data search engine. For details about related parameters, see Table 7.
    25  	Datastore *DatastoreBody `json:"datastore,omitempty"`
    26  	// Cluster name. It contains 4 to 32 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.
    27  	// The value must start with a letter.
    28  	Name string `json:"name" required:"true"`
    29  	// Number of clusters. The value range is 1 to 32.
    30  	InstanceNum int `json:"instanceNum" required:"true"`
    31  	// Automatic snapshot creation. This function is enabled by default. For details about related parameters.
    32  	BackupStrategy *BackupStrategyBody `json:"backupStrategy,omitempty"`
    33  	// Whether disks are encrypted. For details about related parameters, see Table 9.
    34  	DiskEncryption *EncryptionBody `json:"diskEncryption,omitempty"`
    35  	// Whether communication encryption is performed on the cluster. Available values include true and false.
    36  	// By default, communication encryption is disabled. When httpsEnable is set to true,
    37  	// authorityEnable must be set to true.
    38  	// Value true indicates that communication encryption is performed on the cluster.
    39  	// Value false indicates that communication encryption is not performed on the cluster.
    40  	// NOTE:
    41  	// This parameter is supported in clusters 6.5.4 or later.
    42  	HttpsEnable bool `json:"httpsEnable,omitempty"`
    43  	// Whether to enable authentication. Available values include true and false. Authentication is disabled by default.
    44  	// When authentication is enabled, httpsEnable must be set to true.
    45  	// Value true indicates that authentication is enabled for the cluster.
    46  	// Value false indicates that authentication is disabled for the cluster.
    47  	// NOTE:
    48  	// This parameter is supported in clusters 6.5.4 or later.
    49  	AuthorityEnable bool `json:"authorityEnable,omitempty"`
    50  	// Password of the cluster user admin in security mode. This parameter is mandatory only when authorityEnable
    51  	// is set to true.
    52  	// NOTE:
    53  	// The administrator password must meet the following requirements:
    54  	// The password can contain 8 to 32 characters.
    55  	// Passwords must contain at least 3 of the following character types: uppercase letters, lowercase letters,
    56  	// numbers, and special characters (~!@#$%^&*()-_=+\\|[{}];:,<.>/?).
    57  	// Weak password verification is required for a security cluster. You are advised to set a strong password.
    58  	AdminPwd string `json:"adminPwd,omitempty"`
    59  	// Enterprise project ID. When creating a cluster, associate the enterprise project ID with the cluster. The value
    60  	// can contain a maximum of 36 characters. It is string 0 or in UUID format with hyphens (-). Value 0 indicates
    61  	// the default enterprise project.
    62  	// NOTE:
    63  	// For details about how to obtain enterprise project IDs and features, see the Enterprise Management Service User
    64  	// Guide.
    65  	EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
    66  	// Tags in a cluster.
    67  	// NOTE:
    68  	// For details about the tag feature, see the Tag Management Service Overview.
    69  	Tags []tags.ResourceTag `json:"tags,omitempty"`
    70  }
    71  
    72  type BackupStrategyBody struct {
    73  	// Time when a snapshot is created every day. Snapshots can only be created on the hour. The time format is the time
    74  	// followed by the time zone, specifically, HH:mm z. In the format, HH:mm refers to the hour time and z
    75  	// refers to the time zone, for example, 00:00 GMT+08:00 and 01:00 GMT+08:00.
    76  	Period string `json:"period" required:"true"`
    77  	// Prefix of the name of the snapshot that is automatically created.
    78  	Prefix string `json:"prefix" required:"true"`
    79  	// Number of days for which automatically created snapshots are reserved.
    80  	// Value range: 1 to 90
    81  	Keepday int `json:"keepday" required:"true"`
    82  	// The name of the OBS bucket used for backup. If the bucket already stores snapshot data, it cannot be changed.
    83  	Bucket string `json:"bucket,omitempty"`
    84  	// Storage path of the snapshot in the OBS bucket.
    85  	BasePath string `json:"basePath,omitempty"`
    86  	// The name of the IAM delegate used to access OBS.
    87  	// illustrate:
    88  	// If the three parameters bucket, basePath, and agency are empty at the same time, the system will automatically
    89  	// create an OBS bucket and IAM agent, otherwise the configured parameter values will be used.
    90  	Agency string `json:"agency,omitempty"`
    91  }
    92  
    93  // DatastoreBody
    94  type DatastoreBody struct {
    95  	// Cluster type. The default value is Elasticsearch. Currently, the value can only be Elasticsearch.
    96  	Type string `json:"type,omitempty"`
    97  	// Cluster version. The value can be 5.5.1, 6.2.3, 6.5.4, 7.1.1, 7.6.2, or 7.9.3. The default value is 5.5.1.
    98  	Version string `json:"version" required:"true"`
    99  }
   100  
   101  // InstanceBody
   102  type InstanceBody struct {
   103  	// Instance flavor name. For example:
   104  	// Value range of flavor ess.spec-2u16g: 40 GB to 1,280 GB
   105  	// Value range of flavor ess.spec-4u32g: 40 GB to 2,560 GB
   106  	// Value range of flavor ess.spec-8u64g: 80 GB to 5,120 GB
   107  	// Value range of flavor ess.spec-16u128g: 160 GB to 10,240 GB
   108  	FlavorRef string `json:"flavorRef" required:"true"`
   109  	// If flavorRef is set to a local disk flavor, you do not need to set this parameter. You can obtain the local disk
   110  	// flavor by calling the API for obtaining the instance flavor list. Currently,
   111  	// the following local disk flavors are supported:
   112  	// ess.spec-i3small
   113  	// ess.spec-i3medium
   114  	// ess.spec-i3.8xlarge.8
   115  	// ess.spec-ds.xlarge.8
   116  	// ess.spec-ds.2xlarge.8
   117  	// ess.spec-ds.4xlarge.8
   118  	// Information about the volume. For details about related parameters, see Table 5.
   119  	Volume InstanceVolumeBody `json:"volume"`
   120  	// Subnet information. For details about related parameters, see Table 6.
   121  	Nics InstanceNicsBody `json:"nics" required:"true"`
   122  	// Availability zone (AZ). A single AZ is created when this parameter is not specified.
   123  	// Separate multiple AZs with commas (,), for example, az1,az2. AZs must be unique and ensure that the number of
   124  	// nodes be at least the number of AZs.
   125  	// If the number of nodes is a multiple of the number of AZs, the nodes are evenly distributed to each AZ. If the
   126  	// number of nodes is not a multiple of the number of AZs, the absolute difference between node quantity in any two
   127  	// AZs is 1 at most.
   128  	AvailabilityZone string `json:"availability_zone"`
   129  }
   130  
   131  // InstanceNicsBody
   132  type InstanceNicsBody struct {
   133  	// Subnet ID. All instances in a cluster must have the same subnets and security groups.
   134  	NetId string `json:"netId" required:"true"`
   135  	// Security group ID. All instances in a cluster must have the same subnets and security groups.
   136  	SecurityGroupId string `json:"securityGroupId" required:"true"`
   137  	// VPC ID, which is used for configuring cluster network.
   138  	VpcId string `json:"vpcId" required:"true"`
   139  }
   140  
   141  // InstanceVolumeBody volume
   142  type InstanceVolumeBody struct {
   143  	// Volume size, which must be a multiple of 4 and 10.  Unit: GB
   144  	Size int `json:"size" required:"true"`
   145  	// COMMON: Common I/O
   146  	// HIGH: High I/O
   147  	// ULTRAHIGH: Ultra-high I/O
   148  	VolumeType string `json:"volume_type" required:"true"`
   149  }
   150  
   151  type EncryptionBody struct {
   152  	// Value 1 indicates encryption is performed, and value 0 indicates encryption is not performed.
   153  	SystemEncrypted string `json:"systemEncrypted" required:"true"`
   154  	// Key ID.
   155  	// The Default Master Keys cannot be used to create grants. Specifically, you cannot use Default Master Keys whose
   156  	// aliases end with /default in KMS to create clusters.
   157  	// After a cluster is created, do not delete the key used by the cluster. Otherwise,
   158  	// the cluster will become unavailable.
   159  	SystemCmkid string `json:"systemCmkid" required:"true"`
   160  }
   161  
   162  type ListClustersDetailsOpts struct {
   163  	// Start value of the query. The default value is 1, indicating that the query starts from the first cluster.
   164  	Start int `q:"start"`
   165  	// Number of clusters to be queried. The default value is 10, indicating that 10 clusters are queried at a time.
   166  	Limit int `q:"limit"`
   167  }
   168  
   169  type RoleExtendReq struct {
   170  	// Detailed description about the cluster scale-out request. For detai
   171  	Grow []RoleExtendGrowReq `json:"grow" required:"true"`
   172  }
   173  
   174  // RoleExtendGrowReq
   175  type RoleExtendGrowReq struct {
   176  	// Storage capacity of the instance to be expanded. The total storage capacity of existing instances
   177  	// and newly added instances in a cluster cannot exceed the maximum instance storage capacity allowed when a
   178  	// cluster is being created. In addition, you can expand the instance storage capacity for a cluster
   179  	// for up to six times.Unit: GB
   180  	Disksize *int `json:"disksize" required:"true"`
   181  	// Number of instances to be scaled out. The total number of existing instances and newly added instances
   182  	// in a cluster cannot exceed 32.
   183  	Nodesize *int `json:"nodesize" required:"true"`
   184  	// Type of the instance to be scaled out. Select at least one from ess, ess-cold, ess-master, and ess-client.
   185  	// You can only add instances rather than increase storage capacity on nodes of the ess-master and ess-client types.
   186  	Type string `json:"type" required:"true"`
   187  }
   188  
   189  var RequestOpts = golangsdk.RequestOpts{
   190  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
   191  }
   192  
   193  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*CreateResponse, error) {
   194  	b, err := golangsdk.BuildRequestBody(opts, "cluster")
   195  	if err != nil {
   196  		return nil, err
   197  	}
   198  
   199  	var r CreateResponse
   200  
   201  	_, err = c.Post(createURL(c), b, &r, &golangsdk.RequestOpts{
   202  		MoreHeaders: RequestOpts.MoreHeaders,
   203  	})
   204  
   205  	if err == nil {
   206  		return &r, nil
   207  	}
   208  	return nil, err
   209  }
   210  
   211  func Get(c *golangsdk.ServiceClient, clusterId string) (*ClusterDetailResponse, error) {
   212  	var rst ClusterDetailResponse
   213  	_, err := c.Get(getURL(c, clusterId), &rst, &golangsdk.RequestOpts{
   214  		MoreHeaders: RequestOpts.MoreHeaders,
   215  	})
   216  
   217  	if err == nil {
   218  		return &rst, nil
   219  	}
   220  	return nil, err
   221  }
   222  
   223  func Delete(c *golangsdk.ServiceClient, clusterId string) *golangsdk.ErrResult {
   224  	var r golangsdk.ErrResult
   225  	_, r.Err = c.Delete(deleteURL(c, clusterId), &golangsdk.RequestOpts{
   226  		MoreHeaders: RequestOpts.MoreHeaders,
   227  	})
   228  	return &r
   229  }
   230  
   231  // ListClustersDetails
   232  func List(c *golangsdk.ServiceClient, opts ListClustersDetailsOpts) (*ClusterListResponse, error) {
   233  	url := listURL(c)
   234  	query, err := golangsdk.BuildQueryString(opts)
   235  	if err != nil {
   236  		return nil, err
   237  	}
   238  	url += query.String()
   239  
   240  	var rst golangsdk.Result
   241  	_, err = c.Get(url, &rst.Body, &golangsdk.RequestOpts{
   242  		MoreHeaders: RequestOpts.MoreHeaders,
   243  	})
   244  	if err == nil {
   245  		var r ClusterListResponse
   246  		rst.ExtractInto(&r)
   247  		return &r, nil
   248  	}
   249  	return nil, err
   250  }
   251  
   252  func ExtendInstanceStorage(c *golangsdk.ServiceClient, clusterId string, opts RoleExtendReq) (*ClusterResponse, error) {
   253  	b, err := golangsdk.BuildRequestBody(opts, "")
   254  	if err != nil {
   255  		return nil, err
   256  	}
   257  
   258  	var rst ClusterResponse
   259  	_, err = c.Post(extendInstanceStorageURL(c, clusterId), b, &rst, &golangsdk.RequestOpts{
   260  		MoreHeaders: RequestOpts.MoreHeaders,
   261  	})
   262  	if err == nil {
   263  		return &rst, nil
   264  	}
   265  	return nil, err
   266  }
   267  
   268  // ListFlavors
   269  func ListFlavors(c *golangsdk.ServiceClient) (*EsFlavorsResp, error) {
   270  	var rst EsFlavorsResp
   271  	_, err := c.Get(listFlavorsURL(c), &rst, &golangsdk.RequestOpts{
   272  		MoreHeaders: RequestOpts.MoreHeaders,
   273  	})
   274  	if err == nil {
   275  		return &rst, nil
   276  	}
   277  	return nil, err
   278  
   279  }
   280  
   281  // RestartCluster
   282  func Restart(c *golangsdk.ServiceClient, clusterId string) (*RestartClusterResponse, error) {
   283  
   284  	var rst RestartClusterResponse
   285  	_, err := c.Post(restartURL(c, clusterId), nil, &rst, &golangsdk.RequestOpts{
   286  		MoreHeaders: RequestOpts.MoreHeaders,
   287  	})
   288  	if err == nil {
   289  		return &rst, nil
   290  	}
   291  	return nil, err
   292  }