blob: 0c7c5d31c1e667cf9c100408b5f9f342ef6fb9f3 [file] [log] [blame]
ehdou10f1f852016-10-14 20:58:23 +03001package sharenetworks
2
ehdou07943332016-10-24 21:21:58 +03003import (
4 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
6)
ehdou10f1f852016-10-14 20:58:23 +03007
8// CreateOptsBuilder allows extensions to add additional parameters to the
9// Create request.
10type CreateOptsBuilder interface {
11 ToShareNetworkCreateMap() (map[string]interface{}, error)
12}
13
14// CreateOpts contains options for creating a ShareNetwork. This object is
15// passed to the sharenetworks.Create function. For more information about
16// these parameters, see the ShareNetwork object.
17type CreateOpts struct {
18 // The UUID of the Neutron network to set up for share servers
19 NeutronNetID string `json:"neutron_net_id,omitempty"`
20 // The UUID of the Neutron subnet to set up for share servers
21 NeutronSubnetID string `json:"neutron_subnet_id,omitempty"`
22 // The UUID of the nova network to set up for share servers
23 NovaNetID string `json:"nova_net_id,omitempty"`
24 // The share network name
25 Name string `json:"name"`
26 // The share network description
27 Description string `json:"description"`
28}
29
30// ToShareNetworkCreateMap assembles a request body based on the contents of a
31// CreateOpts.
32func (opts CreateOpts) ToShareNetworkCreateMap() (map[string]interface{}, error) {
33 return gophercloud.BuildRequestBody(opts, "share_network")
34}
35
36// Create will create a new ShareNetwork based on the values in CreateOpts. To
37// extract the ShareNetwork object from the response, call the Extract method
38// on the CreateResult.
39func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
40 b, err := opts.ToShareNetworkCreateMap()
41 if err != nil {
42 r.Err = err
43 return
44 }
45 _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
46 OkCodes: []int{200, 202},
47 })
48 return
49}
ehdou53687252016-10-14 22:10:13 +030050
51// Delete will delete the existing ShareNetwork with the provided ID.
52func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
53 _, r.Err = client.Delete(deleteURL(client, id), nil)
54 return
55}
ehdou07943332016-10-24 21:21:58 +030056
57// ListOptsBuilder allows extensions to add additional parameters to the List
58// request.
59type ListOptsBuilder interface {
60 ToShareNetworkListQuery() (string, error)
61}
62
63// ListOpts holds options for listing ShareNetworks. It is passed to the
64// sharenetworks.List function.
65type ListOpts struct {
66 // admin-only option. Set it to true to see all tenant share networks.
67 AllTenants bool `q:"all_tenants"`
68 // The UUID of the project where the share network was created
69 ProjectID string `q:"project_id"`
70 // The neutron network ID
71 NeutronNetID string `q:"neutron_net_id"`
72 // The neutron subnet ID
73 NeutronSubnetID string `q:"neutron_subnet_id"`
74 // The nova network ID
75 NovaNetID string `q:"nova_net_id"`
76 // The network type. A valid value is VLAN, VXLAN, GRE or flat
77 NetworkType string `q:"network_type"`
78 // The Share Network name
79 Name string `q:"name"`
80 // The Share Network description
81 Description string `q:"description"`
82 // The Share Network IP version
83 IPVersion gophercloud.IPVersion `q:"ip_version"`
84 // The Share Network segmentation ID
85 SegmentationID int `q:"segmentation_id"`
86 // List all share networks created after the given date
87 CreatedSince string `q:"created_since"`
88 // List all share networks created before the given date
89 CreatedBefore string `q:"created_before"`
90 // Limit specifies the page size.
91 Limit int `q:"limit"`
92 // Limit specifies the page number.
93 Offset int `q:"offset"`
94}
95
96// ToShareNetworkListQuery formats a ListOpts into a query string.
97func (opts ListOpts) ToShareNetworkListQuery() (string, error) {
98 q, err := gophercloud.BuildQueryString(opts)
99 return q.String(), err
100}
101
102// ListDetail returns ShareNetworks optionally limited by the conditions provided in ListOpts.
103func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
104 url := listDetailURL(client)
105 if opts != nil {
106 query, err := opts.ToShareNetworkListQuery()
107 if err != nil {
108 return pagination.Pager{Err: err}
109 }
110 url += query
111 }
112
113 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
114 p := ShareNetworkPage{pagination.MarkerPageBase{PageResult: r}}
115 p.MarkerPageBase.Owner = p
116 return p
117 })
118}