Mikko Valkonen | 20de780 | 2016-10-24 22:25:01 +0300 | [diff] [blame] | 1 | package shares |
| 2 | |
| 3 | import ( |
| 4 | "github.com/gophercloud/gophercloud" |
| 5 | ) |
| 6 | |
| 7 | // CreateOptsBuilder allows extensions to add additional parameters to the |
| 8 | // Create request. |
| 9 | type CreateOptsBuilder interface { |
| 10 | ToShareCreateMap() (map[string]interface{}, error) |
| 11 | } |
| 12 | |
| 13 | // CreateOpts contains the options for create a Share. This object is |
| 14 | // passed to shares.Create(). For more information about these parameters, |
| 15 | // please refer to the Share object, or the shared file systems API v2 |
| 16 | // documentation |
| 17 | type CreateOpts struct { |
| 18 | // Defines the share protocol to use |
| 19 | ShareProto string `json:"share_proto" required:"true"` |
| 20 | // Size in GB |
| 21 | Size int `json:"size" required:"true"` |
| 22 | // Defines the share name |
| 23 | Name string `json:"name,omitempty"` |
| 24 | // Share description |
| 25 | Description string `json:"description,omitempty"` |
| 26 | // DisplayName is equivalent to Name. The API supports using both |
| 27 | // This is an inherited attribute from the block storage API |
| 28 | DisplayName string `json:"display_name,omitempty"` |
| 29 | // DisplayDescription is equivalent to Description. The API supports using bot |
| 30 | // This is an inherited attribute from the block storage API |
| 31 | DisplayDescription string `json:"display_description,omitempty"` |
| 32 | // ShareType defines the sharetype. If omitted, a default share type is used |
| 33 | ShareType string `json:"share_type,omitempty"` |
| 34 | // VolumeType is deprecated but supported. Either ShareType or VolumeType can be used |
| 35 | VolumeType string `json:"volume_type,omitempty"` |
| 36 | // The UUID from which to create a share |
| 37 | SnapshotID string `json:"snapshot_id,omitempty"` |
| 38 | // Determines whether or not the share is public |
| 39 | IsPublic *bool `json:"is_public,omitempty"` |
| 40 | // Key value pairs of user defined metadata |
| 41 | Metadata map[string]string `json:"metadata,omitempty"` |
| 42 | // The UUID of the share network to which the share belongs to |
| 43 | ShareNetworkID string `json:"share_network_id,omitempty"` |
| 44 | // The UUID of the consistency group to which the share belongs to |
| 45 | ConsistencyGroupID string `json:"consistency_group_id,omitempty"` |
| 46 | // The availability zone of the share |
| 47 | AvailabilityZone string `json:"availability_zone,omitempty"` |
| 48 | } |
| 49 | |
| 50 | // ToShareCreateMap assembles a request body based on the contents of a |
| 51 | // CreateOpts. |
| 52 | func (opts CreateOpts) ToShareCreateMap() (map[string]interface{}, error) { |
| 53 | return gophercloud.BuildRequestBody(opts, "share") |
| 54 | } |
| 55 | |
| 56 | // Create will create a new Share based on the values in CreateOpts. To extract |
| 57 | // the Share object from the response, call the Extract method on the |
| 58 | // CreateResult. |
| 59 | func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { |
| 60 | b, err := opts.ToShareCreateMap() |
| 61 | if err != nil { |
| 62 | r.Err = err |
| 63 | return |
| 64 | } |
| 65 | _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ |
| 66 | OkCodes: []int{200, 201}, |
| 67 | }) |
| 68 | return |
| 69 | } |
Mikko Valkonen | 4c108b5 | 2016-10-24 23:11:25 +0300 | [diff] [blame] | 70 | |
| 71 | // Delete will delete an existing Share with the given UUID. |
| 72 | func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { |
| 73 | _, r.Err = client.Delete(deleteURL(client, id), nil) |
| 74 | return |
| 75 | } |
Mikko Valkonen | d887d2a | 2016-10-25 21:00:09 +0300 | [diff] [blame] | 76 | |
| 77 | // Get will get a single share with given UUID |
| 78 | func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { |
| 79 | _, r.Err = client.Get(getURL(client, id), &r.Body, nil) |
| 80 | return |
| 81 | } |