github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/evs/v3/volumes/results.go (about) 1 package volumes 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 ) 9 10 type Attachment struct { 11 AttachedAt time.Time `json:"-"` 12 AttachmentID string `json:"attachment_id"` 13 Device string `json:"device"` 14 HostName string `json:"host_name"` 15 ID string `json:"id"` 16 ServerID string `json:"server_id"` 17 VolumeID string `json:"volume_id"` 18 } 19 20 func (r *Attachment) UnmarshalJSON(b []byte) error { 21 type tmp Attachment 22 var s struct { 23 tmp 24 AttachedAt golangsdk.JSONRFC3339MilliNoZ `json:"attached_at"` 25 } 26 err := json.Unmarshal(b, &s) 27 if err != nil { 28 return err 29 } 30 *r = Attachment(s.tmp) 31 32 r.AttachedAt = time.Time(s.AttachedAt) 33 34 return err 35 } 36 37 // Volume contains all the information associated with a Volume. 38 type Volume struct { 39 // Unique identifier for the volume. 40 ID string `json:"id"` 41 // Current status of the volume. 42 Status string `json:"status"` 43 // Size of the volume in GB. 44 Size int `json:"size"` 45 // AvailabilityZone is which availability zone the volume is in. 46 AvailabilityZone string `json:"availability_zone"` 47 // The date when this volume was created. 48 CreatedAt time.Time `json:"-"` 49 // The date when this volume was last updated 50 UpdatedAt time.Time `json:"-"` 51 // Instances onto which the volume is attached. 52 Attachments []Attachment `json:"attachments"` 53 // Human-readable display name for the volume. 54 Name string `json:"name"` 55 // Human-readable description for the volume. 56 Description string `json:"description"` 57 // The type of volume to create, either SATA or SSD. 58 VolumeType string `json:"volume_type"` 59 // The image ID of volume to create. 60 VolumeImageMetadata map[string]string `json:"volume_image_metadata"` 61 // The ID of the snapshot from which the volume was created 62 SnapshotID string `json:"snapshot_id"` 63 // The ID of another block storage volume from which the current volume was created 64 SourceVolID string `json:"source_volid"` 65 // The ID of the back that can be used to create an EVS disk 66 BackupID string `json:"backup_id"` 67 // Arbitrary key-value pairs defined by the metadata field table. 68 Metadata map[string]string `json:"metadata"` 69 // Arbitrary key-value pairs defined by the user. 70 Tags map[string]string `json:"tags"` 71 // UserID is the id of the user who created the volume. 72 UserID string `json:"user_id"` 73 // Indicates whether this is a bootable volume. 74 Bootable string `json:"bootable"` 75 // Encrypted denotes if the volume is encrypted. 76 Encrypted bool `json:"encrypted"` 77 // ReplicationStatus is the status of replication. 78 ReplicationStatus string `json:"replication_status"` 79 // ConsistencyGroupID is the consistency group ID. 80 ConsistencyGroupID string `json:"consistencygroup_id"` 81 // Multiattach denotes if the volume is multi-attach capable. 82 Multiattach bool `json:"multiattach"` 83 // wwn of the volume. 84 WWN string `json:"wwn"` 85 // enterprise project ID bound to the volume 86 EnterpriseProjectID string `json:"enterprise_project_id"` 87 } 88 89 func (r *Volume) UnmarshalJSON(b []byte) error { 90 type tmp Volume 91 var s struct { 92 tmp 93 CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"` 94 UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"` 95 } 96 err := json.Unmarshal(b, &s) 97 if err != nil { 98 return err 99 } 100 *r = Volume(s.tmp) 101 102 r.CreatedAt = time.Time(s.CreatedAt) 103 r.UpdatedAt = time.Time(s.UpdatedAt) 104 105 return err 106 } 107 108 type commonResult struct { 109 golangsdk.Result 110 } 111 112 // Extract will get the Volume object out of the commonResult object. 113 func (r commonResult) Extract() (*Volume, error) { 114 var s Volume 115 err := r.ExtractInto(&s) 116 return &s, err 117 } 118 119 // ExtractInto converts our response data into a volume struct 120 func (r commonResult) ExtractInto(v interface{}) error { 121 return r.Result.ExtractIntoStructPtr(v, "volume") 122 } 123 124 // GetResult contains the response body and error from a Get request. 125 type GetResult struct { 126 commonResult 127 }