github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/evs/v3/volumes/results.go (about)

     1  package volumes
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/opentelekomcloud/gophertelekomcloud"
     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 ID of the snapshot from which the volume was created
    60  	SnapshotID string `json:"snapshot_id"`
    61  	// The ID of another block storage volume from which the current volume was created
    62  	SourceVolID string `json:"source_volid"`
    63  	// The ID of the back that can be used to create an EVS disk
    64  	BackupID string `json:"backup_id"`
    65  	// Arbitrary key-value pairs defined by the metadata field table.
    66  	Metadata map[string]string `json:"metadata"`
    67  	// Arbitrary key-value pairs defined by the user.
    68  	Tags map[string]string `json:"tags"`
    69  	// UserID is the id of the user who created the volume.
    70  	UserID string `json:"user_id"`
    71  	// Indicates whether this is a bootable volume.
    72  	Bootable string `json:"bootable"`
    73  	// Encrypted denotes if the volume is encrypted.
    74  	Encrypted bool `json:"encrypted"`
    75  	// ReplicationStatus is the status of replication.
    76  	ReplicationStatus string `json:"replication_status"`
    77  	// ConsistencyGroupID is the consistency group ID.
    78  	ConsistencyGroupID string `json:"consistencygroup_id"`
    79  	// Multiattach denotes if the volume is multi-attach capable.
    80  	Multiattach bool `json:"multiattach"`
    81  	// wwn of the volume.
    82  	WWN string `json:"wwn"`
    83  	// enterprise project ID bound to the volume
    84  	EnterpriseProjectID string `json:"enterprise_project_id"`
    85  }
    86  
    87  func (r *Volume) UnmarshalJSON(b []byte) error {
    88  	type tmp Volume
    89  	var s struct {
    90  		tmp
    91  		CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"`
    92  		UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"`
    93  	}
    94  	err := json.Unmarshal(b, &s)
    95  	if err != nil {
    96  		return err
    97  	}
    98  	*r = Volume(s.tmp)
    99  
   100  	r.CreatedAt = time.Time(s.CreatedAt)
   101  	r.UpdatedAt = time.Time(s.UpdatedAt)
   102  
   103  	return err
   104  }
   105  
   106  type commonResult struct {
   107  	golangsdk.Result
   108  }
   109  
   110  // Extract will get the Volume object out of the commonResult object.
   111  func (r commonResult) Extract() (*Volume, error) {
   112  	var s Volume
   113  	err := r.ExtractInto(&s)
   114  	return &s, err
   115  }
   116  
   117  // ExtractInto converts our response data into a volume struct
   118  func (r commonResult) ExtractInto(v interface{}) error {
   119  	return r.Result.ExtractIntoStructPtr(v, "volume")
   120  }
   121  
   122  // GetResult contains the response body and error from a Get request.
   123  type GetResult struct {
   124  	commonResult
   125  }