github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/sfs_turbo/v1/shares/requests.go (about) 1 package shares 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/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 valid value is NFS. 20 ShareProto string `json:"share_proto,omitempty"` 21 // ShareType defines the file system type. the valid 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 CryptKeyID string `json:"crypt_key_id,omitempty"` 46 ExpandType string `json:"expand_type,omitempty"` 47 } 48 49 // ToShareCreateMap assembles a request body based on the contents of a 50 // CreateOpts. 51 func (opts CreateOpts) ToShareCreateMap() (map[string]interface{}, error) { 52 return golangsdk.BuildRequestBody(opts, "share") 53 } 54 55 // Create will create a new SFS Turbo file system based on the values in CreateOpts. To extract 56 // the Share object from the response, call the Extract method on the 57 // CreateResult. 58 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 59 b, err := opts.ToShareCreateMap() 60 if err != nil { 61 r.Err = err 62 return 63 } 64 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 65 OkCodes: []int{200, 202}, 66 }) 67 return 68 } 69 70 type ListOptsBuilder interface { 71 ToShareListQuery() (string, error) 72 } 73 74 type ListOpts struct { 75 Limit string `q:"limit"` 76 Offset string `q:"offset"` 77 } 78 79 func (opts ListOpts) ToShareListQuery() (string, error) { 80 q, err := golangsdk.BuildQueryString(opts) 81 if err != nil { 82 return "", err 83 } 84 return q.String(), err 85 } 86 87 // List returns a Pager which allows you to iterate over a collection of 88 // SFS Turbo resources. 89 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 90 url := listURL(client) 91 if opts != nil { 92 query, err := opts.ToShareListQuery() 93 if err != nil { 94 return pagination.Pager{Err: err} 95 } 96 url += query 97 } 98 99 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 100 return TurboPage{pagination.LinkedPageBase{PageResult: r}} 101 }) 102 } 103 104 // Get will get a single SFS Turbo file system with given UUID 105 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 106 _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) 107 return 108 } 109 110 // Delete will delete an existing SFS Turbo file system with the given UUID. 111 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 112 _, r.Err = client.Delete(resourceURL(client, id), nil) 113 return 114 } 115 116 // ExpandOptsBuilder allows extensions to add additional parameters to the 117 // Expand request. 118 type ExpandOptsBuilder interface { 119 ToShareExpandMap() (map[string]interface{}, error) 120 } 121 122 // ExpandOpts contains the options for expanding a SFS Turbo. This object is 123 // passed to shares.Expand(). 124 type ExpandOpts struct { 125 // Specifies the extend object. 126 Extend ExtendOpts `json:"extend" required:"true"` 127 } 128 129 type ExtendOpts struct { 130 // Specifies the post-expansion capacity (GB) of the shared file system. 131 NewSize int `json:"new_size" required:"true"` 132 } 133 134 // ToShareExpandMap assembles a request body based on the contents of a 135 // ExpandOpts. 136 func (opts ExpandOpts) ToShareExpandMap() (map[string]interface{}, error) { 137 return golangsdk.BuildRequestBody(opts, "") 138 } 139 140 // Expand will expand a SFS Turbo based on the values in ExpandOpts. 141 func Expand(client *golangsdk.ServiceClient, shareID string, opts ExpandOptsBuilder) (r ExpandResult) { 142 b, err := opts.ToShareExpandMap() 143 if err != nil { 144 r.Err = err 145 return 146 } 147 _, r.Err = client.Post(actionURL(client, shareID), b, nil, &golangsdk.RequestOpts{ 148 OkCodes: []int{202}, 149 }) 150 return 151 } 152 153 // ChangeSGOptsBuilder allows extensions to change the security group 154 // bound to a SFS Turbo file system 155 type ChangeSGOptsBuilder interface { 156 ToShareSGMap() (map[string]interface{}, error) 157 } 158 159 // ChangeSGOpts contains the options for changing security group to a SFS Turbo 160 type ChangeSGOpts struct { 161 // Specifies the change_security_group object. 162 ChangeSecurityGroup SecurityGroupOpts `json:"change_security_group" required:"true"` 163 } 164 165 type SecurityGroupOpts struct { 166 // Specifies the ID of the security group to be modified. 167 SecurityGroupID string `json:"security_group_id" required:"true"` 168 } 169 170 // ToShareExpandMap assembles a request body based on the contents of a 171 // ChangeSGOpts. 172 func (opts ChangeSGOpts) ToShareSGMap() (map[string]interface{}, error) { 173 return golangsdk.BuildRequestBody(opts, "") 174 } 175 176 // ChangeSG will change security group to a SFS Turbo based on the values in ChangeSGOpts. 177 func ChangeSG(client *golangsdk.ServiceClient, shareID string, opts ChangeSGOptsBuilder) (r ExpandResult) { 178 b, err := opts.ToShareSGMap() 179 if err != nil { 180 r.Err = err 181 return 182 } 183 _, r.Err = client.Post(actionURL(client, shareID), b, nil, &golangsdk.RequestOpts{ 184 OkCodes: []int{202}, 185 }) 186 return 187 }