github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/evs/v2/cloudvolumes/results.go (about) 1 package cloudvolumes 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // Attachment contains the disk attachment information 9 type Attachment struct { 10 // Specifies the ID of the attachment information 11 AttachmentID string `json:"attachment_id"` 12 // Specifies the disk ID 13 VolumeID string `json:"volume_id"` 14 // Specifies the ID of the attached resource, equals to volume_id 15 ResourceID string `json:"id"` 16 // Specifies the ID of the server to which the disk is attached 17 ServerID string `json:"server_id"` 18 // Specifies the name of the host accommodating the server to which the disk is attached 19 HostName string `json:"host_name"` 20 // Specifies the device name 21 Device string `json:"device"` 22 // Specifies the time when the disk was attached. Time format: UTC YYYY-MM-DDTHH:MM:SS.XXXXXX 23 AttachedAt string `json:"attached_at"` 24 } 25 26 // VolumeMetadata is an object that represents the metadata about the disk. 27 type VolumeMetadata struct { 28 // Specifies the parameter that describes the encryption CMK ID in metadata. 29 // This parameter is used together with __system__encrypted for encryption. 30 // The length of cmkid is fixed at 36 bytes. 31 SystemCmkID string `json:"__system__cmkid"` 32 // Specifies the parameter that describes the encryption function in metadata. The value can be 0 or 1. 33 // 0: indicates the disk is not encrypted. 34 // 1: indicates the disk is encrypted. 35 // If this parameter does not appear, the disk is not encrypted by default. 36 SystemEncrypted string `json:"__system__encrypted"` 37 // Specifies the clone method. When the disk is created from a snapshot, 38 // the parameter value is 0, indicating the linked cloning method. 39 FullClone string `json:"full_clone"` 40 // Specifies the parameter that describes the disk device type in metadata. The value can be true or false. 41 // If this parameter is set to true, the disk device type is SCSI, that is, Small Computer System 42 // Interface (SCSI), which allows ECS OSs to directly access the underlying storage media and supports SCSI 43 // reservation commands. 44 // If this parameter is set to false, the disk device type is VBD (the default type), 45 // that is, Virtual Block Device (VBD), which supports only simple SCSI read/write commands. 46 // If this parameter does not appear, the disk device type is VBD. 47 HwPassthrough string `json:"hw:passthrough"` 48 // Specifies the parameter that describes the disk billing mode in metadata. 49 // If this parameter is specified, the disk is billed on a yearly/monthly basis. 50 // If this parameter is not specified, the disk is billed on a pay-per-use basis. 51 OrderID string `json:"orderID"` 52 // Specifies the resource type about the disk. 53 ResourceType string `json:"resourceType"` 54 // Specifies the special code about the disk. 55 ResourceSpecCode string `json:"resourceSpecCode"` 56 // Specifies whether disk is read-only. 57 ReadOnly string `json:"readonly"` 58 // Specifies the attached mode about the disk. 59 AttachedMode string `json:"attached_mode"` 60 } 61 62 // IOPSAndThroughput is the struct of IOPS and throughput 63 type IOPSAndThroughput struct { 64 // The frozened mark 65 Frozened bool `json:"frozened"` 66 // The iops or throughput id 67 ID string `json:"id"` 68 // The iops or throughput value 69 TotalVal int `json:"total_val"` 70 // The volume ID 71 VolumeId string `json:"volume_id"` 72 } 73 74 // Link is an object that represents a link to which the disk belongs. 75 type Link struct { 76 // Specifies the corresponding shortcut link. 77 Href string `json:"href"` 78 // Specifies the shortcut link marker name. 79 Rel string `json:"rel"` 80 } 81 82 // Volume contains all the information associated with a Volume. 83 type Volume struct { 84 // Unique identifier for the volume. 85 ID string `json:"id"` 86 // Human-readable display name for the volume. 87 Name string `json:"name"` 88 // Current status of the volume. 89 Status string `json:"status"` 90 // Size of the volume in GB. 91 Size int `json:"size"` 92 // Human-readable description for the volume. 93 Description string `json:"description"` 94 // The type of volume to create, either SATA or SSD. 95 VolumeType string `json:"volume_type"` 96 // The IOPS of the volume. Only exist when volume_type is `ESSD2` or `GPSSD2` 97 IOPS IOPSAndThroughput `json:"iops"` 98 // The throughput of the volume. Only exist when volume_type is `GPSSD2` 99 Throughput IOPSAndThroughput `json:"throughput"` 100 // AvailabilityZone is which availability zone the volume is in. 101 AvailabilityZone string `json:"availability_zone"` 102 // Instances onto which the volume is attached. 103 Attachments []Attachment `json:"attachments"` 104 // Specifies the disk URI. 105 Links []Link `json:"links"` 106 // The metadata of the disk image. 107 ImageMetadata map[string]string `json:"volume_image_metadata"` 108 // The ID of the snapshot from which the volume was created 109 SnapshotID string `json:"snapshot_id"` 110 // The ID of another block storage volume from which the current volume was created 111 SourceVolID string `json:"source_volid"` 112 // Specifies the ID of the tenant to which the disk belongs. The tenant ID is actually the project ID. 113 OsVolTenantAttrTenantID string `json:"os-vol-tenant-attr:tenant_id"` 114 // Specifies the service type. The value can be EVS, DSS or DESS. 115 ServiceType string `json:"service_type"` 116 // Indicates whether this is a bootable volume. 117 Bootable string `json:"bootable"` 118 // Multiattach denotes if the volume is multi-attach capable. 119 Multiattach bool `json:"multiattach"` 120 // Specifies the ID of the DSS storage pool accommodating the disk. 121 DedicatedStorageID string `json:"dedicated_storage_id"` 122 // Specifies the name of the DSS storage pool accommodating the disk. 123 DedicatedStorageName string `json:"dedicated_storage_name"` 124 // Encrypted denotes if the volume is encrypted. 125 Encrypted bool `json:"encrypted"` 126 // wwn of the volume. 127 WWN string `json:"wwn"` 128 // enterprise project ID bound to the volume 129 EnterpriseProjectID string `json:"enterprise_project_id"` 130 // ReplicationStatus is the status of replication. 131 ReplicationStatus string `json:"replication_status"` 132 // ConsistencyGroupID is the consistency group ID. 133 ConsistencyGroupID string `json:"consistencygroup_id"` 134 // Arbitrary key-value pairs defined by the metadata field table. 135 Metadata VolumeMetadata `json:"metadata"` 136 // Arbitrary key-value pairs defined by the user. 137 Tags map[string]string `json:"tags"` 138 // UserID is the id of the user who created the volume. 139 UserID string `json:"user_id"` 140 // The date when this volume was created. 141 CreatedAt string `json:"created_at"` 142 // The date when this volume was last updated 143 UpdatedAt string `json:"updated_at"` 144 } 145 146 // VolumePage is a pagination.pager that is returned from a call to the List function. 147 type VolumePage struct { 148 pagination.OffsetPageBase 149 } 150 151 // IsEmpty returns true if a ListResult contains no Volumes. 152 func (r VolumePage) IsEmpty() (bool, error) { 153 volumes, err := ExtractVolumes(r) 154 return len(volumes) == 0, err 155 } 156 157 // ExtractVolumes extracts and returns Volumes. It is used while iterating over a cloudvolumes.List call. 158 func ExtractVolumes(r pagination.Page) ([]Volume, error) { 159 var s []Volume 160 err := extractVolumesInto(r, &s) 161 return s, err 162 } 163 164 func extractVolumesInto(r pagination.Page, v interface{}) error { 165 return r.(VolumePage).Result.ExtractIntoSlicePtr(v, "volumes") 166 } 167 168 type commonResult struct { 169 golangsdk.Result 170 } 171 172 // Extract will get the Volume object out of the commonResult object. 173 func (r commonResult) Extract() (*Volume, error) { 174 var s Volume 175 err := r.ExtractInto(&s) 176 return &s, err 177 } 178 179 // ExtractInto converts our response data into a volume struct 180 func (r commonResult) ExtractInto(v interface{}) error { 181 return r.Result.ExtractIntoStructPtr(v, "volume") 182 } 183 184 // GetResult contains the response body from a Get request. 185 type GetResult struct { 186 commonResult 187 } 188 189 // UpdateResult contains the response body from a Update request. 190 type UpdateResult struct { 191 commonResult 192 } 193 194 // DeleteResult contains the response body and error from a Delete request. 195 type DeleteResult struct { 196 golangsdk.ErrResult 197 } 198 199 // ErrorInfo contains the error message returned when an error occurs 200 type ErrorInfo struct { 201 Message string `json:"message"` 202 Code string `json:"code"` 203 } 204 205 // JobResponse contains all the information from Create and ExtendSize response 206 type JobResponse struct { 207 JobID string `json:"job_id"` 208 OrderID string `json:"order_id"` 209 VolumeIDs []string `json:"volume_ids"` 210 Error ErrorInfo `json:"error"` 211 } 212 213 // JobResult contains the response body and error from Create and ExtendSize requests 214 type JobResult struct { 215 golangsdk.Result 216 } 217 218 // Extract will get the JobResponse object out of the JobResult 219 func (r JobResult) Extract() (*JobResponse, error) { 220 job := new(JobResponse) 221 err := r.ExtractInto(job) 222 return job, err 223 }