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

     1  package persistentvolumeclaims
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  // PersistentVolumeClaim is a struct that represents the result of Create, Get and List methods.
     9  type PersistentVolumeClaim struct {
    10  	// The version of the persistent API.
    11  	ApiVersion string `json:"apiVersion"`
    12  	// The REST resource of object represents.
    13  	Kind string `json:"kind"`
    14  	// Standard object's metadata.
    15  	Metadata MetaResp `json:"metadata"`
    16  	// The desired characteristics of a volume.
    17  	Spec SpecResp `json:"spec"`
    18  	// PVC status.
    19  	Status Status `json:"status"`
    20  }
    21  
    22  // MetaResp is an object struct that represents the persistent volume claim metadata.
    23  type MetaResp struct {
    24  	// The name of the Persistent Volume Claim.
    25  	Name string `json:"name"`
    26  	// The namespace where the Persistent Volume Claim is located.
    27  	Namespace string `json:"namespace"`
    28  	// An unstructured key value map stored with a resource that may be set by external tools to store and retrieve
    29  	// arbitrary metadata.
    30  	Annotations map[string]string `json:"annotations"`
    31  	// ID of the Persistent Volume Claim in UUID format.
    32  	UID string `json:"uid"`
    33  	// String that identifies the server's internal version of this object that can be used by clients to determine
    34  	// when objects have changed.
    35  	ResourceVersion string `json:"resourceVersion"`
    36  	// A timestamp representing the server time when this object was created.
    37  	CreationTimestamp string `json:"creationTimestamp"`
    38  	// SelfLink is a URL representing this object.
    39  	SelfLink string `json:"selfLink"`
    40  	// Map of string keys and values that can be used to organize and categorize (scope and select) objects.
    41  	Labels map[string]string `json:"labels"`
    42  	// Each finalizer string of array is an identifier for the responsible component that will remove the entry form
    43  	// the list.
    44  	Finalizers []string `json:"finalizers"`
    45  	// Enable identify whether the resource is available.
    46  	Enable bool `json:"enable"`
    47  }
    48  
    49  // SpecResp is an object struct that represents the detailed description.
    50  type SpecResp struct {
    51  	// The name of the volume.
    52  	VolumeName string `json:"volumeName"`
    53  	// AccessModes contains the actual access modes the volume backing the PVC has.
    54  	AccessModes []string `json:"accessModes"`
    55  	// Resources represents the minimum resources the volume should have.
    56  	Resources ResourceRequirement `json:"resources"`
    57  	// Name of the storage class required by the claim.
    58  	StorageClassName string `json:"storageClassName"`
    59  	// Mode of the volume.
    60  	VolumeMode string `json:"volumeMode"`
    61  }
    62  
    63  // ResourceRequirement is an object struct that represents the detailed of the volume.
    64  type ResourceRequirement struct {
    65  	// Minimum amount of compute resources required.
    66  	// If requests is omitted for a container, it defaults to Limits if that is explicitly specified,
    67  	// otherwise to an implementation-defined value.
    68  	Requests Capacity `json:"requests"`
    69  }
    70  
    71  // Capacity is an object struct that represents the volume capacity.
    72  type Capacity struct {
    73  	// Volume size, in GB format: 'xGi'.
    74  	Storage string `json:"storage"`
    75  }
    76  
    77  // Status is an object struct that represents the volume capacity.
    78  type Status struct {
    79  	// AccessModes contains the actual access modes the volume backing the PVC has.
    80  	Capacity Capacity `json:"capacity"`
    81  	// AccessModes contains the actual access modes the volume backing the PVC has.
    82  	AccessModes []string `json:"accessModes"`
    83  	// Phase represents the current phase of persistentVolumeClaim.
    84  	//   pending: used for PersistentVolumeClaims that are not yet bound.
    85  	//   Bound: used for PersistentVolumeClaims that are bound.
    86  	//   Lost: used for PersistentVolumeClaims that lost their underlying.
    87  	Phase string `json:"phase"`
    88  }
    89  
    90  type commonResult struct {
    91  	golangsdk.Result
    92  }
    93  
    94  // CreateResult represents a result of the Create method.
    95  type CreateResult struct {
    96  	commonResult
    97  }
    98  
    99  func (r commonResult) Extract() (*PersistentVolumeClaim, error) {
   100  	var s PersistentVolumeClaim
   101  	err := r.ExtractInto(&s)
   102  	return &s, err
   103  }
   104  
   105  // PersistentVolumeClaimPage represents the result of a List method.
   106  type PersistentVolumeClaimPage struct {
   107  	pagination.SinglePageBase
   108  }
   109  
   110  // ExtractPersistentVolumeClaims is a method to interpret the PersistentVolumeClaimPage as a PVC list.
   111  func ExtractPersistentVolumeClaims(r pagination.Page) ([]PersistentVolumeClaim, error) {
   112  	var s []PersistentVolumeClaim
   113  	err := r.(PersistentVolumeClaimPage).Result.ExtractIntoSlicePtr(&s, "items")
   114  	return s, err
   115  }
   116  
   117  // DeleteResult represents a result of the Create method.
   118  type DeleteResult struct {
   119  	commonResult
   120  }
   121  
   122  // Extract is a method which to extract the response to a PVC object.
   123  func (r DeleteResult) Extract() ([]PersistentVolumeClaim, error) {
   124  	var s []PersistentVolumeClaim
   125  	err := r.ExtractInto(&s)
   126  	return s, err
   127  }