github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/evs/v2/cloudvolumes/results.go (about) 1 package cloudvolumes 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/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 // Volume contains all the information associated with a Volume. 27 type Volume struct { 28 // Unique identifier for the volume. 29 ID string `json:"id"` 30 // Human-readable display name for the volume. 31 Name string `json:"name"` 32 // Current status of the volume. 33 Status string `json:"status"` 34 // Size of the volume in GB. 35 Size int `json:"size"` 36 // Human-readable description for the volume. 37 Description string `json:"description"` 38 // The type of volume to create, either SATA or SSD. 39 VolumeType string `json:"volume_type"` 40 // AvailabilityZone is which availability zone the volume is in. 41 AvailabilityZone string `json:"availability_zone"` 42 // Instances onto which the volume is attached. 43 Attachments []Attachment `json:"attachments"` 44 45 // The metadata of the disk image. 46 ImageMetadata map[string]string `json:"volume_image_metadata"` 47 // The ID of the snapshot from which the volume was created 48 SnapshotID string `json:"snapshot_id"` 49 // The ID of another block storage volume from which the current volume was created 50 SourceVolID string `json:"source_volid"` 51 52 // Indicates whether this is a bootable volume. 53 Bootable string `json:"bootable"` 54 // Multiattach denotes if the volume is multi-attach capable. 55 Multiattach bool `json:"multiattach"` 56 // Encrypted denotes if the volume is encrypted. 57 Encrypted bool `json:"encrypted"` 58 // wwn of the volume. 59 WWN string `json:"wwn"` 60 // enterprise project ID bound to the volume 61 EnterpriseProjectID string `json:"enterprise_project_id"` 62 // ReplicationStatus is the status of replication. 63 ReplicationStatus string `json:"replication_status"` 64 // ConsistencyGroupID is the consistency group ID. 65 ConsistencyGroupID string `json:"consistencygroup_id"` 66 // Arbitrary key-value pairs defined by the metadata field table. 67 Metadata map[string]string `json:"metadata"` 68 // Arbitrary key-value pairs defined by the user. 69 Tags map[string]string `json:"tags"` 70 // UserID is the id of the user who created the volume. 71 UserID string `json:"user_id"` 72 // The date when this volume was created. 73 CreatedAt string `json:"created_at"` 74 // The date when this volume was last updated 75 UpdatedAt string `json:"updated_at"` 76 } 77 78 // VolumePage is a pagination.pager that is returned from a call to the List function. 79 type VolumePage struct { 80 pagination.LinkedPageBase 81 } 82 83 // IsEmpty returns true if a ListResult contains no Volumes. 84 func (r VolumePage) IsEmpty() (bool, error) { 85 volumes, err := ExtractVolumes(r) 86 return len(volumes) == 0, err 87 } 88 89 // NextPageURL uses the response's embedded link reference to navigate to the 90 // next page of results. 91 func (r VolumePage) NextPageURL() (string, error) { 92 var s struct { 93 Links []golangsdk.Link `json:"volumes_links"` 94 } 95 err := r.ExtractInto(&s) 96 if err != nil { 97 return "", err 98 } 99 return golangsdk.ExtractNextURL(s.Links) 100 } 101 102 // ExtractVolumes extracts and returns Volumes. It is used while iterating over a cloudvolumes.List call. 103 func ExtractVolumes(r pagination.Page) ([]Volume, error) { 104 var s []Volume 105 err := extractVolumesInto(r, &s) 106 return s, err 107 } 108 109 func extractVolumesInto(r pagination.Page, v interface{}) error { 110 return r.(VolumePage).Result.ExtractIntoSlicePtr(v, "volumes") 111 } 112 113 type commonResult struct { 114 golangsdk.Result 115 } 116 117 // Extract will get the Volume object out of the commonResult object. 118 func (r commonResult) Extract() (*Volume, error) { 119 var s Volume 120 err := r.ExtractInto(&s) 121 return &s, err 122 } 123 124 // ExtractInto converts our response data into a volume struct 125 func (r commonResult) ExtractInto(v interface{}) error { 126 return r.Result.ExtractIntoStructPtr(v, "volume") 127 } 128 129 // GetResult contains the response body from a Get request. 130 type GetResult struct { 131 commonResult 132 } 133 134 // UpdateResult contains the response body from a Update request. 135 type UpdateResult struct { 136 commonResult 137 } 138 139 // DeleteResult contains the response body and error from a Delete request. 140 type DeleteResult struct { 141 golangsdk.ErrResult 142 } 143 144 // ErrorInfo contains the error message returned when an error occurs 145 type ErrorInfo struct { 146 Message string `json:"message"` 147 Code string `json:"code"` 148 } 149 150 // JobResponse contains all the information from Create and ExtendSize response 151 type JobResponse struct { 152 JobID string `json:"job_id"` 153 OrderID string `json:"order_id"` 154 VolumeIDs []string `json:"volume_ids"` 155 Error ErrorInfo `json:"error"` 156 } 157 158 // JobResult contains the response body and error from Create and ExtendSize requests 159 type JobResult struct { 160 golangsdk.Result 161 } 162 163 // Extract will get the JobResponse object out of the JobResult 164 func (r JobResult) Extract() (*JobResponse, error) { 165 job := new(JobResponse) 166 err := r.ExtractInto(job) 167 return job, err 168 }