github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cce/v1/persistentvolumeclaims/requests.go (about) 1 package persistentvolumeclaims 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // CreateOpts allows to create a persistent volume claims using given parameters. 9 type CreateOpts struct { 10 // The version of the persistent API, valid value is 'v1'. 11 ApiVersion string `json:"apiVersion" required:"true"` 12 // Kind is a string value representing the REST resource this object represents. 13 // Servers may infer this from the endpoint the c submits requests to. 14 Kind string `json:"kind" required:"true"` 15 // Standard object's metadata. 16 Metadata Metadata `json:"metadata" required:"true"` 17 // The desired characteristics of a volume. 18 Spec Spec `json:"spec" required:"true"` 19 } 20 21 // Metadata is an object which will be build up standard object metadata. 22 type Metadata struct { 23 // The name of the persistent volume claim. 24 Name string `json:"name,omitempty"` 25 // The namespace of the persistent volume claim. 26 Namespace string `json:"namespace,omitempty"` 27 // The labels of the persistent volume claim. 28 Labels map[string]string `json:"labels,omitempty"` 29 // The annotations of the persistent volume claim. 30 Annotations map[string]string `json:"annotations,omitempty"` 31 } 32 33 // Spec defines the detailed description of the cluster object. 34 type Spec struct { 35 // Access mode of the volume. Only the first value in all selected options is valid. 36 // ReadWriteOnce: The volume can be mounted as read-write by a single node. 37 // NOTE: 38 // This function is supported only when the cluster version is v1.13.10 and the storage-driver version is 1.0.19. 39 // ReadOnlyMany (default): The volume can be mounted as read-only by many nodes. 40 // ReadWriteMany: The volume can be mounted as read-write by many nodes. 41 AccessModes []string `json:"accessModes" required:"true"` 42 // Storage class name of the PVC. 43 StorageClassName string `json:"storageClassName,omitempty"` 44 // Resources represents the minimum resources the volume should have. 45 Resources ResourceRequest `json:"resources" required:"true"` 46 // Name of the PV bound to the PVC. 47 VolumeName string `json:"volumeName,omitempty"` 48 } 49 50 // ResourceRequest is an object struct that represents the detailed of the volume. 51 type ResourceRequest struct { 52 // Minimum amount of compute resources required. 53 // If requests is omitted for a container, it defaults to Limits if that is explicitly specified, 54 // otherwise to an implementation-defined value. 55 Requests CapacityReq `json:"requests" required:"true"` 56 } 57 58 // CapacityReq is an object struct that represents the volume capacity. 59 type CapacityReq struct { 60 // Volume size, in GB format: 'xGi'. 61 Storage string `json:"storage" required:"true"` 62 } 63 64 // CreateOptsBuilder allows extensions to add additional parameters to the Create request. 65 type CreateOptsBuilder interface { 66 ToPvcCreateMap() (map[string]interface{}, error) 67 } 68 69 // ToPvcCreateMap builds a create request body from CreateOpts. 70 func (opts CreateOpts) ToPvcCreateMap() (map[string]interface{}, error) { 71 return golangsdk.BuildRequestBody(opts, "") 72 } 73 74 // Create accepts a CreateOpts struct and uses the namespace name to import a volume into the namespace. 75 func Create(c *golangsdk.ServiceClient, clusterId, ns string, opts CreateOptsBuilder) (r CreateResult) { 76 reqBody, err := opts.ToPvcCreateMap() 77 if err != nil { 78 r.Err = err 79 return 80 } 81 _, r.Err = c.Post(createURL(c, clusterId, ns), reqBody, &r.Body, nil) 82 return 83 } 84 85 // List is a method to obtain an array of the persistent volume claims for specifies namespace. 86 func List(c *golangsdk.ServiceClient, clusterId, ns string) pagination.Pager { 87 return pagination.NewPager(c, listURL(c, clusterId, ns), func(r pagination.PageResult) pagination.Page { 88 return PersistentVolumeClaimPage{pagination.SinglePageBase(r)} 89 }) 90 } 91 92 // Delete accepts to delete the specifies persistent volume claim form the namespace. 93 func Delete(c *golangsdk.ServiceClient, clusterId, ns, name string) (r DeleteResult) { 94 _, r.Err = c.DeleteWithBodyResp(deleteURL(c, clusterId, ns, name), nil, r.Body, nil) 95 return 96 }