github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/sfs_turbo/v1/shares/requests.go (about) 1 package shares 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // CreateOptsBuilder allows extensions to add additional parameters to the 9 // Create request. 10 type CreateOptsBuilder interface { 11 ToShareCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains the options for create an SFS Turbo. This object is 15 // passed to shares.Create(). 16 type CreateOpts struct { 17 // Defines the SFS Turbo file system name 18 Name string `json:"name" required:"true"` 19 // Defines the SFS Turbo file system protocol to use, the vaild value is NFS. 20 ShareProto string `json:"share_proto,omitempty"` 21 // ShareType defines the file system type. the vaild values are STANDARD and PERFORMANCE. 22 ShareType string `json:"share_type" required:"true"` 23 // Size in GB, range from 500 to 32768. 24 Size int `json:"size" required:"true"` 25 // The availability zone of the SFS Turbo file system 26 AvailabilityZone string `json:"availability_zone" required:"true"` 27 // The VPC ID 28 VpcID string `json:"vpc_id" required:"true"` 29 // The subnet ID 30 SubnetID string `json:"subnet_id" required:"true"` 31 // The security group ID 32 SecurityGroupID string `json:"security_group_id" required:"true"` 33 // The enterprise project ID 34 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 35 // The backup ID 36 BackupID string `json:"backup_id,omitempty"` 37 // Share description 38 Description string `json:"description,omitempty"` 39 // The metadata information 40 Metadata Metadata `json:"metadata,omitempty"` 41 } 42 43 // Metadata specifies the metadata information 44 type Metadata struct { 45 ExpandType string `json:"expand_type,omitempty"` 46 CryptKeyID string `json:"crypt_key_id,omitempty"` 47 DedicatedFlavor string `json:"dedicated_flavor,omitempty"` 48 MasterDedicatedHostID string `json:"master_dedicated_host_id,omitempty"` 49 SlaveDedicatedHostID string `json:"slave_dedicated_host_id,omitempty"` 50 DedicatedStorageID string `json:"dedicated_storage_id,omitempty"` 51 } 52 53 // ToShareCreateMap assembles a request body based on the contents of a 54 // CreateOpts. 55 func (opts CreateOpts) ToShareCreateMap() (map[string]interface{}, error) { 56 return golangsdk.BuildRequestBody(opts, "share") 57 } 58 59 // Create will create a new SFS Turbo file system based on the values in CreateOpts. To extract 60 // the Share object from the response, call the Extract method on the 61 // CreateResult. 62 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 63 b, err := opts.ToShareCreateMap() 64 if err != nil { 65 r.Err = err 66 return 67 } 68 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 69 OkCodes: []int{200, 202}, 70 }) 71 return 72 } 73 74 // List returns a Pager which allows you to iterate over a collection of 75 // SFS Turbo resources. 76 func List(c *golangsdk.ServiceClient) ([]Turbo, error) { 77 pages, err := pagination.NewPager(c, listURL(c), func(r pagination.PageResult) pagination.Page { 78 return TurboPage{pagination.LinkedPageBase{PageResult: r}} 79 }).AllPages() 80 if err != nil { 81 return nil, err 82 } 83 84 return ExtractTurbos(pages) 85 } 86 87 // Get will get a single SFS Trubo file system with given UUID 88 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 89 _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) 90 91 return 92 } 93 94 // Delete will delete an existing SFS Trubo file system with the given UUID. 95 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 96 _, r.Err = client.Delete(resourceURL(client, id), nil) 97 return 98 } 99 100 // ExpandOptsBuilder allows extensions to add additional parameters to the 101 // Expand request. 102 type ExpandOptsBuilder interface { 103 ToShareExpandMap() (map[string]interface{}, error) 104 } 105 106 // ExpandOpts contains the options for expanding a SFS Turbo. This object is 107 // passed to shares.Expand(). 108 type ExpandOpts struct { 109 // Specifies the extend object. 110 Extend ExtendOpts `json:"extend" required:"true"` 111 } 112 113 type ExtendOpts struct { 114 // Specifies the post-expansion capacity (GB) of the shared file system. 115 NewSize int `json:"new_size" required:"true"` 116 } 117 118 // ToShareExpandMap assembles a request body based on the contents of a 119 // ExpandOpts. 120 func (opts ExpandOpts) ToShareExpandMap() (map[string]interface{}, error) { 121 return golangsdk.BuildRequestBody(opts, "") 122 } 123 124 // Expand will expand a SFS Turbo based on the values in ExpandOpts. 125 func Expand(client *golangsdk.ServiceClient, share_id string, opts ExpandOptsBuilder) (r ExpandResult) { 126 b, err := opts.ToShareExpandMap() 127 if err != nil { 128 r.Err = err 129 return 130 } 131 _, r.Err = client.Post(actionURL(client, share_id), b, nil, &golangsdk.RequestOpts{ 132 OkCodes: []int{202}, 133 }) 134 return 135 }