1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
package sharenetworks
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToShareNetworkCreateMap() (map[string]interface{}, error)
}
// CreateOpts contains options for creating a ShareNetwork. This object is
// passed to the sharenetworks.Create function. For more information about
// these parameters, see the ShareNetwork object.
type CreateOpts struct {
// The UUID of the Neutron network to set up for share servers
NeutronNetID string `json:"neutron_net_id,omitempty"`
// The UUID of the Neutron subnet to set up for share servers
NeutronSubnetID string `json:"neutron_subnet_id,omitempty"`
// The UUID of the nova network to set up for share servers
NovaNetID string `json:"nova_net_id,omitempty"`
// The share network name
Name string `json:"name"`
// The share network description
Description string `json:"description"`
}
// ToShareNetworkCreateMap assembles a request body based on the contents of a
// CreateOpts.
func (opts CreateOpts) ToShareNetworkCreateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "share_network")
}
// Create will create a new ShareNetwork based on the values in CreateOpts. To
// extract the ShareNetwork object from the response, call the Extract method
// on the CreateResult.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToShareNetworkCreateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200, 202},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Delete will delete the existing ShareNetwork with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
resp, err := client.Delete(deleteURL(client, id), nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// ListOptsBuilder allows extensions to add additional parameters to the List
// request.
type ListOptsBuilder interface {
ToShareNetworkListQuery() (string, error)
}
// ListOpts holds options for listing ShareNetworks. It is passed to the
// sharenetworks.List function.
type ListOpts struct {
// admin-only option. Set it to true to see all tenant share networks.
AllTenants bool `q:"all_tenants"`
// The UUID of the project where the share network was created
ProjectID string `q:"project_id"`
// The neutron network ID
NeutronNetID string `q:"neutron_net_id"`
// The neutron subnet ID
NeutronSubnetID string `q:"neutron_subnet_id"`
// The nova network ID
NovaNetID string `q:"nova_net_id"`
// The network type. A valid value is VLAN, VXLAN, GRE or flat
NetworkType string `q:"network_type"`
// The Share Network name
Name string `q:"name"`
// The Share Network description
Description string `q:"description"`
// The Share Network IP version
IPVersion gophercloud.IPVersion `q:"ip_version"`
// The Share Network segmentation ID
SegmentationID int `q:"segmentation_id"`
// List all share networks created after the given date
CreatedSince string `q:"created_since"`
// List all share networks created before the given date
CreatedBefore string `q:"created_before"`
// Limit specifies the page size.
Limit int `q:"limit"`
// Limit specifies the page number.
Offset int `q:"offset"`
}
// ToShareNetworkListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToShareNetworkListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// ListDetail returns ShareNetworks optionally limited by the conditions provided in ListOpts.
func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := listDetailURL(client)
if opts != nil {
query, err := opts.ToShareNetworkListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
p := ShareNetworkPage{pagination.MarkerPageBase{PageResult: r}}
p.MarkerPageBase.Owner = p
return p
})
}
// Get retrieves the ShareNetwork with the provided ID. To extract the ShareNetwork
// object from the response, call the Extract method on the GetResult.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
resp, err := client.Get(getURL(client, id), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToShareNetworkUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts contain options for updating an existing ShareNetwork. This object is passed
// to the sharenetworks.Update function. For more information about the parameters, see
// the ShareNetwork object.
type UpdateOpts struct {
// The share network name
Name *string `json:"name,omitempty"`
// The share network description
Description *string `json:"description,omitempty"`
// The UUID of the Neutron network to set up for share servers
NeutronNetID string `json:"neutron_net_id,omitempty"`
// The UUID of the Neutron subnet to set up for share servers
NeutronSubnetID string `json:"neutron_subnet_id,omitempty"`
// The UUID of the nova network to set up for share servers
NovaNetID string `json:"nova_net_id,omitempty"`
}
// ToShareNetworkUpdateMap assembles a request body based on the contents of an
// UpdateOpts.
func (opts UpdateOpts) ToShareNetworkUpdateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "share_network")
}
// Update will update the ShareNetwork with provided information. To extract the updated
// ShareNetwork from the response, call the Extract method on the UpdateResult.
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToShareNetworkUpdateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Put(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// AddSecurityServiceOptsBuilder allows extensions to add additional parameters to the
// AddSecurityService request.
type AddSecurityServiceOptsBuilder interface {
ToShareNetworkAddSecurityServiceMap() (map[string]interface{}, error)
}
// AddSecurityServiceOpts contain options for adding a security service to an
// existing ShareNetwork. This object is passed to the sharenetworks.AddSecurityService
// function. For more information about the parameters, see the ShareNetwork object.
type AddSecurityServiceOpts struct {
SecurityServiceID string `json:"security_service_id"`
}
// ToShareNetworkAddSecurityServiceMap assembles a request body based on the contents of an
// AddSecurityServiceOpts.
func (opts AddSecurityServiceOpts) ToShareNetworkAddSecurityServiceMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "add_security_service")
}
// AddSecurityService will add the security service to a ShareNetwork. To extract the updated
// ShareNetwork from the response, call the Extract method on the UpdateResult.
func AddSecurityService(client *gophercloud.ServiceClient, id string, opts AddSecurityServiceOptsBuilder) (r UpdateResult) {
b, err := opts.ToShareNetworkAddSecurityServiceMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(addSecurityServiceURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// RemoveSecurityServiceOptsBuilder allows extensions to add additional parameters to the
// RemoveSecurityService request.
type RemoveSecurityServiceOptsBuilder interface {
ToShareNetworkRemoveSecurityServiceMap() (map[string]interface{}, error)
}
// RemoveSecurityServiceOpts contain options for removing a security service from an
// existing ShareNetwork. This object is passed to the sharenetworks.RemoveSecurityService
// function. For more information about the parameters, see the ShareNetwork object.
type RemoveSecurityServiceOpts struct {
SecurityServiceID string `json:"security_service_id"`
}
// ToShareNetworkRemoveSecurityServiceMap assembles a request body based on the contents of an
// RemoveSecurityServiceOpts.
func (opts RemoveSecurityServiceOpts) ToShareNetworkRemoveSecurityServiceMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "remove_security_service")
}
// RemoveSecurityService will remove the security service from a ShareNetwork. To extract the updated
// ShareNetwork from the response, call the Extract method on the UpdateResult.
func RemoveSecurityService(client *gophercloud.ServiceClient, id string, opts RemoveSecurityServiceOptsBuilder) (r UpdateResult) {
b, err := opts.ToShareNetworkRemoveSecurityServiceMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(removeSecurityServiceURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
|