github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/css/v1/clusters/Create.go (about) 1 package clusters 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 6 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 7 ) 8 9 type CreateOpts struct { 10 // Instance - instance specification 11 Instance *InstanceSpec `json:"instance" required:"true"` 12 // Datastore - type of the data search engine 13 Datastore *Datastore `json:"datastore,omitempty"` 14 // Name - cluster name. 15 // It contains 4 to 32 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. 16 // The value must start with a letter. 17 Name string `json:"name" required:"true"` 18 // InstanceNum - number of clusters. The value range is 1 to 32. 19 InstanceNum int `json:"instanceNum" required:"true"` 20 // BackupStrategy - configuration of automatic snapshot creation. 21 // This function is enabled by default. 22 BackupStrategy *BackupStrategy `json:"backupStrategy,omitempty"` 23 // DiskEncryption - disk encryption configuration 24 DiskEncryption *DiskEncryption `json:"diskEncryption" required:"true"` 25 // HttpsEnabled - whether communication is not encrypted on the cluster. 26 HttpsEnabled string `json:"httpsEnable,omitempty"` 27 // AuthorityEnabled - whether to enable authentication. 28 // Available values include `true` and `false`. Authentication is disabled by default. 29 // When authentication is enabled, `HttpsEnabled` must be set to `true`. 30 AuthorityEnabled bool `json:"authorityEnable,omitempty"` 31 // AdminPassword - password of the cluster user `admin` in security mode. 32 // This parameter is mandatory only when `AuthorityEnabled` is set to `true`. 33 AdminPassword string `json:"adminPwd,omitempty"` 34 // Tags - tags of a cluster. 35 Tags []tags.ResourceTag `json:"tags,omitempty"` 36 } 37 38 type InstanceSpec struct { 39 // Flavor - instance flavor name. 40 Flavor string `json:"flavorRef" required:"true"` 41 // Volume - information about the volume. 42 Volume *Volume `json:"volume" required:"true"` 43 // Nics - subnet information. 44 Nics *Nics `json:"nics" required:"true"` 45 AvailabilityZone string `json:"availability_zone,omitempty"` 46 } 47 48 type Volume struct { 49 // Type of the volume. 50 // One of: 51 // - `COMMON`: Common I/O 52 // - `HIGH`: High I/O 53 // - `ULTRAHIGH`: Ultra-high I/O 54 Type string `json:"volume_type" required:"true"` 55 // Size of the volume, which must be a multiple of 4 and 10. 56 // Unit: GB. 57 Size int `json:"size" required:"true"` 58 } 59 60 type Nics struct { 61 // VpcID - VPC ID which is used for configuring cluster network. 62 VpcID string `json:"vpcId" required:"true"` 63 // SubnetID - Subnet ID. 64 // All instances in a cluster must have the same subnet. 65 SubnetID string `json:"netId" required:"true"` 66 // SecurityGroupID - Security group ID. 67 // All instances in a cluster must have the same security grou. 68 SecurityGroupID string `json:"securityGroupId" required:"true"` 69 } 70 71 type BackupStrategy struct { 72 // Period - time when a snapshot is created every day. 73 // Snapshots can only be created on the hour. 74 // The time format is the time followed by the time zone, specifically, `HH:mm z`. 75 // In the format, `HH:mm` refers to the hour time and `z` refers to the time zone, for example, 76 // `00:00 GMT+08:00` and `01:00 GMT+08:00`. 77 Period string `json:"period" required:"true"` 78 // Prefix - prefix of the name of the snapshot that is automatically created. 79 Prefix string `json:"prefix" required:"true"` 80 // KeepDay - number of days for which automatically created snapshots are reserved. 81 // Value range: `1` to `90` 82 KeepDay int `json:"keepday" required:"true"` 83 } 84 85 type DiskEncryption struct { 86 // SystemEncrypted - value `1` indicates encryption is performed, and value `0` indicates encryption is not performed. 87 // Boolean sucks. 88 Encrypted string `json:"systemEncrypted" required:"true"` 89 // Key ID. 90 // - The Default Master Keys cannot be used to create grants. 91 // Specifically, you cannot use Default Master Keys whose aliases end with `/default` in KMS to create clusters. 92 // - After a cluster is created, do not delete the key used by the cluster. Otherwise, the cluster will become unavailable. 93 CmkID string `json:"systemCmkid"` 94 } 95 96 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*CreatedCluster, error) { 97 b, err := golangsdk.BuildRequestBody(opts, "cluster") 98 if err != nil { 99 return nil, err 100 } 101 102 raw, err := client.Post(client.ServiceURL("clusters"), b, nil, &golangsdk.RequestOpts{ 103 OkCodes: []int{200}, 104 }) 105 if err != nil { 106 return nil, err 107 } 108 109 var res CreatedCluster 110 err = extract.IntoStructPtr(raw.Body, &res, "cluster") 111 return &res, err 112 } 113 114 type CreatedCluster struct { 115 ID string `json:"id"` 116 Name string `json:"name"` 117 }