github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dms/v1/instances/requests.go (about) 1 package instances 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/openstack/common/tags" 6 "github.com/chnsz/golangsdk/pagination" 7 ) 8 9 // CreateOpsBuilder is used for creating instance parameters. 10 // any struct providing the parameters should implement this interface 11 type CreateOpsBuilder interface { 12 ToInstanceCreateMap() (map[string]interface{}, error) 13 } 14 15 // CreateOps is a struct that contains all the parameters. 16 type CreateOps struct { 17 // Indicates the name of an instance. 18 // An instance name starts with a letter, 19 // consists of 4 to 64 characters, and supports 20 // only letters, digits, and hyphens (-). 21 Name string `json:"name" required:"true"` 22 23 // Indicates the description of an instance. 24 // It is a character string containing not more than 1024 characters. 25 Description string `json:"description,omitempty"` 26 27 // Indicates a message engine. 28 // Currently, only RabbitMQ is supported. 29 Engine string `json:"engine" required:"true"` 30 31 // Indicates the version of a message engine. 32 EngineVersion string `json:"engine_version,omitempty"` 33 34 // Indicates the message storage space. 35 StorageSpace int `json:"storage_space" required:"true"` 36 37 // Indicates the password of an instance. 38 // An instance password must meet the following complexity requirements: 39 // Must be 6 to 32 characters long. 40 // Must contain at least two of the following character types: 41 // Lowercase letters 42 // Uppercase letters 43 // Digits 44 // Special characters (`~!@#$%^&*()-_=+\|[{}]:'",<.>/?) 45 Password string `json:"password,omitempty"` 46 47 // Indicates a username. 48 // A username consists of 1 to 64 characters 49 // and supports only letters, digits, and hyphens (-). 50 AccessUser string `json:"access_user,omitempty"` 51 52 KafkaManagerUser string `json:"kafka_manager_user,omitempty"` 53 KafkaManagerPassword string `json:"kafka_manager_password,omitempty"` 54 55 // Indicates the ID of a VPC. 56 VPCID string `json:"vpc_id" required:"true"` 57 58 // Indicates the ID of a security group. 59 SecurityGroupID string `json:"security_group_id" required:"true"` 60 61 // Indicates the ID of a subnet. 62 SubnetID string `json:"subnet_id" required:"true"` 63 64 // Indicates the ID of an AZ. 65 // The parameter value can be left blank or an empty array. 66 AvailableZones []string `json:"available_zones,omitempty"` 67 68 // Indicates a product ID. 69 ProductID string `json:"product_id" required:"true"` 70 71 // Indicates the time at which a maintenance time window starts. 72 // Format: HH:mm:ss 73 MaintainBegin string `json:"maintain_begin,omitempty"` 74 75 // Indicates the time at which a maintenance time window ends. 76 // Format: HH:mm:ss 77 MaintainEnd string `json:"maintain_end,omitempty"` 78 79 //This parameter is mandatory when a Kafka instance is created. 80 //Indicates the maximum number of topics in a Kafka instance. 81 PartitionNum int `json:"partition_num,omitempty"` 82 83 //Indicates whether to enable SSL-encrypted access. 84 SslEnable bool `json:"ssl_enable"` 85 86 //This parameter is mandatory if the engine is kafka. 87 //Indicates the baseline bandwidth of a Kafka instance, that is, 88 //the maximum amount of data transferred per unit time. Unit: byte/s. 89 Specification string `json:"specification,omitempty"` 90 91 //Indicates the storage I/O specification. For details on how to select a disk type 92 StorageSpecCode string `json:"storage_spec_code,omitempty"` 93 94 // Indicates whether to enable automatic topic creation. 95 EnableAutoTopic bool `json:"enable_auto_topic,omitempty"` 96 97 // Indicates whether to enable public access for an instance. 98 EnablePublicip bool `json:"enable_publicip,omitempty"` 99 100 // Indicates the public network bandwidth. Unit: Mbit/s 101 PublicBandwidth int `json:"public_bandwidth,omitempty"` 102 103 // ndicates the ID of the elastic IP address (EIP) bound to an instance. 104 PublicipId string `json:"publicip_id,omitempty"` 105 106 // Indicates the action to be taken when the memory usage reaches the disk capacity threshold. 107 RetentionPolicy string `json:"retention_policy,omitempty"` 108 109 // Indicates the tags of the instance 110 Tags []tags.ResourceTag `json:"tags,omitempty"` 111 } 112 113 // ToInstanceCreateMap is used for type convert 114 func (ops CreateOps) ToInstanceCreateMap() (map[string]interface{}, error) { 115 return golangsdk.BuildRequestBody(ops, "") 116 } 117 118 // Create an instance with given parameters. 119 func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) { 120 b, err := ops.ToInstanceCreateMap() 121 if err != nil { 122 r.Err = err 123 return 124 } 125 126 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 127 OkCodes: []int{200}, 128 }) 129 130 return 131 } 132 133 // Delete an instance by id 134 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 135 _, r.Err = client.Delete(deleteURL(client, id), &golangsdk.RequestOpts{ 136 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 137 }) 138 return 139 } 140 141 // UpdateOptsBuilder is an interface which can build the map paramter of update function 142 type UpdateOptsBuilder interface { 143 ToInstanceUpdateMap() (map[string]interface{}, error) 144 } 145 146 // UpdateOpts is a struct which represents the parameters of update function 147 type UpdateOpts struct { 148 // Indicates the name of an instance. 149 // An instance name starts with a letter, 150 // consists of 4 to 64 characters, 151 // and supports only letters, digits, and hyphens (-). 152 Name string `json:"name,omitempty"` 153 154 // Indicates the description of an instance. 155 // It is a character string containing not more than 1024 characters. 156 Description *string `json:"description,omitempty"` 157 158 // Indicates the time at which a maintenance time window starts. 159 // Format: HH:mm:ss 160 MaintainBegin string `json:"maintain_begin,omitempty"` 161 162 // Indicates the time at which a maintenance time window ends. 163 // Format: HH:mm:ss 164 MaintainEnd string `json:"maintain_end,omitempty"` 165 166 // Indicates the ID of a security group. 167 SecurityGroupID string `json:"security_group_id,omitempty"` 168 169 // Indicates the action to be taken when the memory usage reaches the disk capacity threshold. 170 RetentionPolicy string `json:"retention_policy,omitempty"` 171 } 172 173 // ToInstanceUpdateMap is used for type convert 174 func (opts UpdateOpts) ToInstanceUpdateMap() (map[string]interface{}, error) { 175 return golangsdk.BuildRequestBody(opts, "") 176 } 177 178 // Update is a method which can be able to update the instance 179 // via accessing to the service with Put method and parameters 180 func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 181 body, err := opts.ToInstanceUpdateMap() 182 if err != nil { 183 r.Err = err 184 return 185 } 186 187 _, r.Err = client.Put(updateURL(client, id), body, nil, &golangsdk.RequestOpts{ 188 OkCodes: []int{204}, 189 }) 190 return 191 } 192 193 // Get a instance with detailed information by id 194 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 195 _, r.Err = client.Get(getURL(client, id), &r.Body, nil) 196 return 197 } 198 199 type ListDmsInstanceOpts struct { 200 Id string `q:"id"` 201 Name string `q:"name"` 202 Engine string `q:"engine"` 203 Status string `q:"status"` 204 IncludeFailure string `q:"includeFailure"` 205 ExactMatchName string `q:"exactMatchName"` 206 EnterpriseProjectID int `q:"enterprise_project_id"` 207 } 208 209 type ListDmsBuilder interface { 210 ToDmsListDetailQuery() (string, error) 211 } 212 213 func (opts ListDmsInstanceOpts) ToDmsListDetailQuery() (string, error) { 214 q, err := golangsdk.BuildQueryString(opts) 215 if err != nil { 216 return "", err 217 } 218 return q.String(), err 219 } 220 221 func List(client *golangsdk.ServiceClient, opts ListDmsBuilder) pagination.Pager { 222 url := listURL(client) 223 if opts != nil { 224 query, err := opts.ToDmsListDetailQuery() 225 226 if err != nil { 227 return pagination.Pager{Err: err} 228 } 229 url += query 230 } 231 232 pageDmsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 233 return DmsPage{pagination.SinglePageBase(r)} 234 }) 235 236 dmsheader := map[string]string{"Content-Type": "application/json"} 237 pageDmsList.Headers = dmsheader 238 return pageDmsList 239 }