github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/volumeactions/results.go (about)

     1  package volumeactions
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  )
     9  
    10  // AttachResult contains the response body and error from an Attach request.
    11  type AttachResult struct {
    12  	golangsdk.ErrResult
    13  }
    14  
    15  // BeginDetachingResult contains the response body and error from a BeginDetach
    16  // request.
    17  type BeginDetachingResult struct {
    18  	golangsdk.ErrResult
    19  }
    20  
    21  // DetachResult contains the response body and error from a Detach request.
    22  type DetachResult struct {
    23  	golangsdk.ErrResult
    24  }
    25  
    26  // UploadImageResult contains the response body and error from an UploadImage
    27  // request.
    28  type UploadImageResult struct {
    29  	golangsdk.Result
    30  }
    31  
    32  // ReserveResult contains the response body and error from a Reserve request.
    33  type ReserveResult struct {
    34  	golangsdk.ErrResult
    35  }
    36  
    37  // UnreserveResult contains the response body and error from an Unreserve
    38  // request.
    39  type UnreserveResult struct {
    40  	golangsdk.ErrResult
    41  }
    42  
    43  // TerminateConnectionResult contains the response body and error from a
    44  // TerminateConnection request.
    45  type TerminateConnectionResult struct {
    46  	golangsdk.ErrResult
    47  }
    48  
    49  // InitializeConnectionResult contains the response body and error from an
    50  // InitializeConnection request.
    51  type InitializeConnectionResult struct {
    52  	golangsdk.Result
    53  }
    54  
    55  // ExtendSizeResult contains the response body and error from an ExtendSize request.
    56  type ExtendSizeResult struct {
    57  	golangsdk.ErrResult
    58  }
    59  
    60  // Extract will get the connection information out of the
    61  // InitializeConnectionResult object.
    62  //
    63  // This will be a generic map[string]interface{} and the results will be
    64  // dependent on the type of connection made.
    65  func (r InitializeConnectionResult) Extract() (map[string]interface{}, error) {
    66  	var s struct {
    67  		ConnectionInfo map[string]interface{} `json:"connection_info"`
    68  	}
    69  	err := r.ExtractInto(&s)
    70  	return s.ConnectionInfo, err
    71  }
    72  
    73  // ImageVolumeType contains volume type information obtained from UploadImage
    74  // action.
    75  type ImageVolumeType struct {
    76  	// The ID of a volume type.
    77  	ID string `json:"id"`
    78  
    79  	// Human-readable display name for the volume type.
    80  	Name string `json:"name"`
    81  
    82  	// Human-readable description for the volume type.
    83  	Description string `json:"display_description"`
    84  
    85  	// Flag for public access.
    86  	IsPublic bool `json:"is_public"`
    87  
    88  	// Extra specifications for volume type.
    89  	ExtraSpecs map[string]interface{} `json:"extra_specs"`
    90  
    91  	// ID of quality of service specs.
    92  	QosSpecsID string `json:"qos_specs_id"`
    93  
    94  	// Flag for deletion status of volume type.
    95  	Deleted bool `json:"deleted"`
    96  
    97  	// The date when volume type was deleted.
    98  	DeletedAt time.Time `json:"-"`
    99  
   100  	// The date when volume type was created.
   101  	CreatedAt time.Time `json:"-"`
   102  
   103  	// The date when this volume was last updated.
   104  	UpdatedAt time.Time `json:"-"`
   105  }
   106  
   107  func (r *ImageVolumeType) UnmarshalJSON(b []byte) error {
   108  	type tmp ImageVolumeType
   109  	var s struct {
   110  		tmp
   111  		CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"`
   112  		UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"`
   113  		DeletedAt golangsdk.JSONRFC3339MilliNoZ `json:"deleted_at"`
   114  	}
   115  	err := json.Unmarshal(b, &s)
   116  	if err != nil {
   117  		return err
   118  	}
   119  	*r = ImageVolumeType(s.tmp)
   120  
   121  	r.CreatedAt = time.Time(s.CreatedAt)
   122  	r.UpdatedAt = time.Time(s.UpdatedAt)
   123  	r.DeletedAt = time.Time(s.DeletedAt)
   124  
   125  	return err
   126  }
   127  
   128  // VolumeImage contains information about volume uploaded to an image service.
   129  type VolumeImage struct {
   130  	// The ID of a volume an image is created from.
   131  	VolumeID string `json:"id"`
   132  
   133  	// Container format, may be bare, ofv, ova, etc.
   134  	ContainerFormat string `json:"container_format"`
   135  
   136  	// Disk format, may be raw, qcow2, vhd, vdi, vmdk, etc.
   137  	DiskFormat string `json:"disk_format"`
   138  
   139  	// Human-readable description for the volume.
   140  	Description string `json:"display_description"`
   141  
   142  	// The ID of the created image.
   143  	ImageID string `json:"image_id"`
   144  
   145  	// Human-readable display name for the image.
   146  	ImageName string `json:"image_name"`
   147  
   148  	// Size of the volume in GB.
   149  	Size int `json:"size"`
   150  
   151  	// Current status of the volume.
   152  	Status string `json:"status"`
   153  
   154  	// The date when this volume was last updated.
   155  	UpdatedAt time.Time `json:"-"`
   156  
   157  	// Volume type object of used volume.
   158  	VolumeType ImageVolumeType `json:"volume_type"`
   159  }
   160  
   161  func (r *VolumeImage) UnmarshalJSON(b []byte) error {
   162  	type tmp VolumeImage
   163  	var s struct {
   164  		tmp
   165  		UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"`
   166  	}
   167  	err := json.Unmarshal(b, &s)
   168  	if err != nil {
   169  		return err
   170  	}
   171  	*r = VolumeImage(s.tmp)
   172  
   173  	r.UpdatedAt = time.Time(s.UpdatedAt)
   174  
   175  	return err
   176  }
   177  
   178  // Extract will get an object with info about the uploaded image out of the
   179  // UploadImageResult object.
   180  func (r UploadImageResult) Extract() (VolumeImage, error) {
   181  	var s struct {
   182  		VolumeImage VolumeImage `json:"os-volume_upload_image"`
   183  	}
   184  	err := r.ExtractInto(&s)
   185  	return s.VolumeImage, err
   186  }
   187  
   188  // ForceDeleteResult contains the response body and error from a ForceDelete request.
   189  type ForceDeleteResult struct {
   190  	golangsdk.ErrResult
   191  }