github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dds/v3/instances/results.go (about) 1 package instances 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 type commonResult struct { 9 golangsdk.Result 10 } 11 12 type CreateResult struct { 13 commonResult 14 } 15 16 type Instance struct { 17 OrderId string `json:"order_id"` 18 Id string `json:"id"` 19 Name string `json:"name"` 20 DataStore DataStore `json:"datastore"` 21 Status string `json:"status"` 22 Region string `json:"region"` 23 AvailabilityZone string `json:"availability_zone"` 24 VpcId string `json:"vpc_id"` 25 SubnetId string `json:"subnet_id"` 26 SecurityGroupId string `json:"security_group_id"` 27 DiskEncryptionId string `json:"disk_encryption_id"` 28 Ssl string `json:"ssl_option"` 29 Mode string `json:"mode"` 30 Flavor []FlavorOpt `json:"flavor"` 31 BackupStrategy BackupStrategyOpt `json:"backup_strategy"` 32 EnterpriseProjectID string `json:"enterprise_project_id"` 33 } 34 35 type FlavorOpt struct { 36 Type string `json:"type" required:"true"` 37 Num string `json:"num" required:"true"` 38 Storage string `json:"storage,omitempty"` 39 Size string `json:"size,omitempty"` 40 SpecCode string `json:"spec_code" required:"true"` 41 } 42 43 type BackupStrategyOpt struct { 44 StartTime string `json:"start_time" required:"true"` 45 KeepDays string `json:"keep_days,omitempty"` 46 } 47 48 func (r CreateResult) Extract() (*Instance, error) { 49 var response Instance 50 err := r.ExtractInto(&response) 51 return &response, err 52 } 53 54 func (r CreateResult) ExtractEnabled() (*EnabledOpts, error) { 55 var response EnabledOpts 56 err := r.ExtractInto(&response) 57 return &response, err 58 } 59 60 type UpdateInstanceResult struct { 61 commonResult 62 } 63 64 type UpdateResp struct { 65 JobId string `json:"job_id"` 66 OrderId string `json:"order_id"` 67 } 68 69 func (r UpdateInstanceResult) Extract() (*UpdateResp, error) { 70 var resp UpdateResp 71 err := r.ExtractInto(&resp) 72 return &resp, err 73 } 74 75 type DeleteInstanceResult struct { 76 commonResult 77 } 78 79 type DeleteInstanceResponse struct { 80 JobId string `json:"job_id"` 81 } 82 83 func (r DeleteInstanceResult) Extract() (*DeleteInstanceResponse, error) { 84 var response DeleteInstanceResponse 85 err := r.ExtractInto(&response) 86 return &response, err 87 } 88 89 type ListInstanceResult struct { 90 commonResult 91 } 92 93 type ListInstanceResponse struct { 94 Instances []InstanceResponse `json:"instances"` 95 TotalCount int `json:"total_count"` 96 } 97 98 type InstanceResponse struct { 99 Id string `json:"id"` 100 Name string `json:"name"` 101 Remark string `json:"remark"` 102 Status string `json:"status"` 103 Port string `json:"port"` 104 Mode string `json:"mode"` 105 Region string `json:"region"` 106 DataStore DataStore `json:"datastore"` 107 Engine string `json:"engine"` 108 Created string `json:"created"` 109 Updated string `json:"updated"` 110 DbUserName string `json:"db_user_name"` 111 Ssl int `json:"ssl"` 112 VpcId string `json:"vpc_id"` 113 SubnetId string `json:"subnet_id"` 114 SecurityGroupId string `json:"security_group_id"` 115 BackupStrategy BackupStrategy `json:"backup_strategy"` 116 MaintenanceWindow string `json:"maintenance_window"` 117 Groups []Group `json:"groups"` 118 DiskEncryptionId string `json:"disk_encryption_id"` 119 TimeZone string `json:"time_zone"` 120 Actions []string `json:"actions"` 121 EnterpriseProjectID string `json:"enterprise_project_id"` 122 } 123 124 type Group struct { 125 Type string `json:"type"` 126 Id string `json:"id"` 127 Name string `json:"name"` 128 Status string `json:"status"` 129 Volume Volume `json:"volume"` 130 Nodes []Nodes `json:"nodes"` 131 } 132 133 type Volume struct { 134 Size string `json:"size"` 135 Used string `json:"used"` 136 } 137 138 type Nodes struct { 139 Id string `json:"id"` 140 Name string `json:"name"` 141 Status string `json:"status"` 142 Role string `json:"role"` 143 PrivateIP string `json:"private_ip"` 144 PublicIP string `json:"public_ip"` 145 SpecCode string `json:"spec_code"` 146 AvailabilityZone string `json:"availability_zone"` 147 } 148 149 type InstancePage struct { 150 pagination.SinglePageBase 151 } 152 153 func (r InstancePage) IsEmpty() (bool, error) { 154 data, err := ExtractInstances(r) 155 if err != nil { 156 return false, err 157 } 158 return len(data.Instances) == 0, err 159 } 160 161 func ExtractInstances(r pagination.Page) (ListInstanceResponse, error) { 162 var s ListInstanceResponse 163 err := (r.(InstancePage)).ExtractInto(&s) 164 return s, err 165 } 166 167 // PortUpdateResp is the structure that represents the detail of the database user. 168 type PortUpdateResp struct { 169 // Job ID. 170 JobId string `json:"job_id"` 171 // Database access port. 172 Port int `json:"port"` 173 } 174 175 type BackupPolicyResp struct { 176 BackupPolicy BackupStrategy `json:"backup_policy"` 177 } 178 179 type AvailabilityZoneResp struct { 180 // Job ID. 181 JobId string `json:"job_id"` 182 } 183 184 type CommonResp struct { 185 // Job ID. 186 JobId string `json:"job_id"` 187 } 188 189 type SlowLogStatusResp struct { 190 // Status. 191 Status string `json:"status"` 192 }