Mikko Valkonen | 20de780 | 2016-10-24 22:25:01 +0300 | [diff] [blame] | 1 | package shares |
| 2 | |
| 3 | import ( |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 4 | "encoding/json" |
| 5 | "time" |
| 6 | |
Mikko Valkonen | 20de780 | 2016-10-24 22:25:01 +0300 | [diff] [blame] | 7 | "github.com/gophercloud/gophercloud" |
| 8 | ) |
| 9 | |
| 10 | // Share contains all information associated with an OpenStack Share |
| 11 | type Share struct { |
| 12 | // The availability zone of the share |
| 13 | AvailabilityZone string `json:"availability_zone"` |
| 14 | // A description of the share |
| 15 | Description string `json:"description,omitempty"` |
| 16 | // DisplayDescription is inherited from BlockStorage API. |
| 17 | // Both Description and DisplayDescription can be used |
| 18 | DisplayDescription string `json:"display_description,omitempty"` |
| 19 | // DisplayName is inherited from BlockStorage API |
| 20 | // Both DisplayName and Name can be used |
| 21 | DisplayName string `json:"display_name,omitempty"` |
| 22 | // Indicates whether a share has replicas or not. |
| 23 | HasReplicas bool `json:"has_replicas"` |
| 24 | // The host name of the share |
| 25 | Host string `json:"host"` |
| 26 | // The UUID of the share |
| 27 | ID string `json:"id"` |
| 28 | // Indicates the visibility of the share |
| 29 | IsPublic bool `json:"is_public,omitempty"` |
| 30 | // Share links for pagination |
| 31 | Links []map[string]string `json:"links"` |
| 32 | // Key, value -pairs of custom metadata |
| 33 | Metadata map[string]string `json:"metadata,omitempty"` |
| 34 | // The name of the share |
| 35 | Name string `json:"name,omitempty"` |
| 36 | // The UUID of the project to which this share belongs to |
| 37 | ProjectID string `json:"project_id"` |
| 38 | // The share replication type |
| 39 | ReplicationType string `json:"replication_type,omitempty"` |
| 40 | // The UUID of the share network |
| 41 | ShareNetworkID string `json:"share_network_id"` |
| 42 | // The shared file system protocol |
| 43 | ShareProto string `json:"share_proto"` |
| 44 | // The UUID of the share server |
| 45 | ShareServerID string `json:"share_server_id"` |
| 46 | // The UUID of the share type. |
| 47 | ShareType string `json:"share_type"` |
| 48 | // The name of the share type. |
| 49 | ShareTypeName string `json:"share_type_name"` |
| 50 | // Size of the share in GB |
| 51 | Size int `json:"size"` |
| 52 | // UUID of the snapshot from which to create the share |
| 53 | SnapshotID string `json:"snapshot_id"` |
| 54 | // The share status |
| 55 | Status string `json:"status"` |
| 56 | // The task state, used for share migration |
| 57 | TaskState string `json:"task_state"` |
| 58 | // The type of the volume |
| 59 | VolumeType string `json:"volume_type,omitempty"` |
| 60 | // The UUID of the consistency group this share belongs to |
| 61 | ConsistencyGroupID string `json:"consistency_group_id"` |
| 62 | // Used for filtering backends which either support or do not support share snapshots |
| 63 | SnapshotSupport bool `json:"snapshot_support"` |
| 64 | SourceCgsnapshotMemberID string `json:"source_cgsnapshot_member_id"` |
| 65 | // Timestamp when the share was created |
jrperritt | 98d0162 | 2017-01-12 14:24:42 -0600 | [diff] [blame] | 66 | CreatedAt time.Time `json:"-"` |
| 67 | } |
| 68 | |
| 69 | func (r *Share) UnmarshalJSON(b []byte) error { |
| 70 | type tmp Share |
| 71 | var s struct { |
| 72 | tmp |
| 73 | CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"` |
| 74 | } |
| 75 | err := json.Unmarshal(b, &s) |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | *r = Share(s.tmp) |
| 80 | |
| 81 | r.CreatedAt = time.Time(s.CreatedAt) |
| 82 | |
| 83 | return nil |
Mikko Valkonen | 20de780 | 2016-10-24 22:25:01 +0300 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | type commonResult struct { |
| 87 | gophercloud.Result |
| 88 | } |
| 89 | |
| 90 | // Extract will get the Share object from the commonResult |
| 91 | func (r commonResult) Extract() (*Share, error) { |
| 92 | var s struct { |
| 93 | Share *Share `json:"share"` |
| 94 | } |
| 95 | err := r.ExtractInto(&s) |
| 96 | return s.Share, err |
| 97 | } |
| 98 | |
| 99 | // CreateResult contains the result.. |
| 100 | type CreateResult struct { |
| 101 | commonResult |
| 102 | } |
Mikko Valkonen | 4c108b5 | 2016-10-24 23:11:25 +0300 | [diff] [blame] | 103 | |
| 104 | // DeleteResult contains the delete results |
| 105 | type DeleteResult struct { |
| 106 | gophercloud.ErrResult |
| 107 | } |
Mikko Valkonen | d887d2a | 2016-10-25 21:00:09 +0300 | [diff] [blame] | 108 | |
| 109 | // GetResult contains the get result |
| 110 | type GetResult struct { |
| 111 | commonResult |
| 112 | } |