github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cci/v1/persistentvolumeclaims/requests.go (about) 1 package persistentvolumeclaims 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 type CreateOpts struct { 9 // The version of the persistent API, valid value is 'v1'. 10 ApiVersion string `json:"apiVersion" required:"true"` 11 // Kind is a string value representing the REST resource this object represents. 12 // Servers may infer this from the endpoint the client submits requests to. 13 Kind string `json:"kind" required:"true"` 14 // Standard object's metadata. 15 Metadata Metadata `json:"metadata" required:"true"` 16 // The desired characteristics of a volume. 17 Spec Spec `json:"spec" required:"true"` 18 } 19 20 type Metadata struct { 21 // The name of the persistent volume claim, must be unique within a namespace. Cannot be updated. 22 Name string `json:"name" required:"true"` 23 // Namespace defines the space within each name must be unique. 24 // An empty namespace is equivalent to the 'default' namespace, but 'default' is the canonical representation. 25 Namespace string `json:"namespace,omitempty"` 26 // An unstructured key value map stored with a resource that may be set by external tools to store and retrieve 27 // arbitrary metadata. 28 Annotations *Annotations `json:"annotations,omitempty"` 29 } 30 31 type Annotations struct { 32 // The type of the file system. 33 // The valid values are ext4 (EVS disk), obs (OBS bucket) and nfs (SFS or SFS Turbo). 34 FsType string `json:"fsType" required:"true"` 35 // ID of the volume 36 VolumeID string `json:"volumeID" required:"true"` 37 // The Shared path of the SFS and the SFS Turbo. 38 DeviceMountPath string `json:"deviceMountPath,omitempty"` 39 } 40 41 type Spec struct { 42 // Resources represents the minimum resources the volume should have. 43 Resources ResourceRequirement `json:"resources" required:"true"` 44 // Name of the storage class required by the claim. 45 // The following fields are supported: 46 // EVS: sas, ssd and sata 47 // SFS: nfs-rw 48 // SFS Turbo: efs-performance and efs-standard 49 // OBS: obs 50 StorageClassName string `json:"storageClassName" required:"true"` 51 // AccessModes contains the actual access modes the volume backing the PVC has. 52 // ReadWriteOnce: can be mount read/write mode to exactly 1 host. 53 // ReadOnlyMany: can be mount in read-only mode to many hosts. 54 // ReadWriteMany: can be mount in read/write mode to many hosts. 55 AccessModes []string `json:"accessModes,omitempty"` 56 } 57 58 type ResourceRequirement struct { 59 // Minimum amount of compute resources required. 60 // If requests is omitted for a container, it defaults to Limits if that is explicitly specified, 61 // otherwise to an implementation-defined value. 62 Requests *ResourceName `json:"requests,omitempty"` 63 } 64 65 type ResourceName struct { 66 // Volume size, in GB format: 'xGi'. 67 Storage string `json:"storage,omitempty"` 68 } 69 70 // CreateOptsBuilder allows extensions to add additional parameters to the Create request. 71 type CreateOptsBuilder interface { 72 ToPVCCreateMap() (map[string]interface{}, error) 73 } 74 75 // ToPVCCreateMap builds a create request body from CreateOpts. 76 func (opts CreateOpts) ToPVCCreateMap() (map[string]interface{}, error) { 77 return golangsdk.BuildRequestBody(opts, "") 78 } 79 80 // Create accepts a CreateOpts struct and uses the namespace name to import a volume into the namespace. 81 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder, ns string) (r CreateResult) { 82 reqBody, err := opts.ToPVCCreateMap() 83 if err != nil { 84 r.Err = err 85 return 86 } 87 _, r.Err = client.Post(rootURL(client, ns), reqBody, &r.Body, &golangsdk.RequestOpts{ 88 OkCodes: []int{200, 201}, 89 }) 90 return 91 } 92 93 type ListOpts struct { 94 // Type of the storage, valid values are bs, obs, nfs and efs. 95 StorageType string `q:"storage_type"` 96 } 97 98 type ListOptsBuilder interface { 99 ToPVCListQuery() (string, error) 100 } 101 102 func (opts ListOpts) ToPVCListQuery() (string, error) { 103 q, err := golangsdk.BuildQueryString(opts) 104 if err != nil { 105 return "", err 106 } 107 return q.String(), err 108 } 109 110 // List is a method to obtain an array of the persistent volume claims for specifies namespace. 111 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder, ns string) pagination.Pager { 112 url := rootURL(client, ns) 113 if opts != nil { 114 query, err := opts.ToPVCListQuery() 115 if err != nil { 116 return pagination.Pager{Err: err} 117 } 118 url += query 119 } 120 121 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 122 return PersistentVolumeClaimPage{pagination.SinglePageBase(r)} 123 }) 124 } 125 126 // Delete accepts to delete the specifies persistent volume claim form the namespace. 127 func Delete(client *golangsdk.ServiceClient, ns, name string) (r DeleteResult) { 128 _, r.Err = client.DeleteWithBodyResp(resourceURL(client, ns, name), nil, r.Body, &golangsdk.RequestOpts{ 129 OkCodes: []int{200}, 130 }) 131 return 132 }