github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/ecs/v1/block_devices/results.go (about)

     1  package block_devices
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/chnsz/golangsdk"
     7  )
     8  
     9  // VolumeAttachment is the structure of the detail of disk mounting.
    10  type VolumeAttachment struct {
    11  	// Specifies the ECS ID in UUID format.
    12  	ServerId string `json:"serverId"`
    13  	// Specifies the EVS disk ID in UUID format.
    14  	VolumeId string `json:"volumeId"`
    15  	// Specifies the mount ID, which is the same as the EVS disk ID.
    16  	// The value is in UUID format.
    17  	Id string `json:"id"`
    18  	// Specifies the drive letter of the EVS disk, which is the device name of the EVS disk.
    19  	Device string `json:"device"`
    20  	// Specifies the PCI address.
    21  	PciAddress string `json:"pciAddress"`
    22  	// Specifies the EVS disk size in GB.
    23  	Size int `json:"size"`
    24  	// Specifies the EVS disk boot sequence.
    25  	// 0 indicates the system disk.
    26  	// Non-0 indicates a data disk.
    27  	BootIndex int `json:"bootIndex"`
    28  	// Specifies the disk bus type.
    29  	// Options: virtio and scsi
    30  	BusType string `json:"bus"`
    31  }
    32  
    33  func (r *VolumeAttachment) UnmarshalJSON(b []byte) error {
    34  	type tmp VolumeAttachment
    35  	var s struct {
    36  		tmp
    37  		BootIndex interface{} `json:"bootIndex"`
    38  	}
    39  	err := json.Unmarshal(b, &s)
    40  	if err != nil {
    41  		return err
    42  	}
    43  
    44  	*r = VolumeAttachment(s.tmp)
    45  
    46  	if s.BootIndex == nil {
    47  		r.BootIndex = -1
    48  	} else {
    49  		r.BootIndex = int(s.BootIndex.(float64))
    50  	}
    51  
    52  	return err
    53  }
    54  
    55  type GetResult struct {
    56  	golangsdk.Result
    57  }
    58  
    59  func (r GetResult) Extract() (*VolumeAttachment, error) {
    60  	s := &VolumeAttachment{}
    61  	return s, r.ExtractInto(s)
    62  }
    63  
    64  func (r GetResult) ExtractInto(v interface{}) error {
    65  	return r.Result.ExtractIntoStructPtr(v, "volumeAttachment")
    66  }
    67  
    68  type ErrorResponse struct {
    69  	// Response error.
    70  	Error Error `json:"error"`
    71  }
    72  
    73  type Error struct {
    74  	// Error code.
    75  	Code string `json:"code"`
    76  	// Error message.
    77  	Message string `json:"message"`
    78  }