Vendor: add Gophercloud networking v2 external
Add package that allow to work with OpenStack networks with external attribute via the Networking V2 service API.
This commit is contained in:
parent
f0f1967c9f
commit
68afd3d8da
53
vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/doc.go
generated
vendored
Normal file
53
vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Package external provides information and interaction with the external
|
||||
extension for the OpenStack Networking service.
|
||||
|
||||
Example to List Networks with External Information
|
||||
|
||||
iTrue := true
|
||||
networkListOpts := networks.ListOpts{}
|
||||
listOpts := external.ListOptsExt{
|
||||
ListOptsBuilder: networkListOpts,
|
||||
External: &iTrue,
|
||||
}
|
||||
|
||||
type NetworkWithExternalExt struct {
|
||||
networks.Network
|
||||
external.NetworkExternalExt
|
||||
}
|
||||
|
||||
var allNetworks []NetworkWithExternalExt
|
||||
|
||||
allPages, err := networks.List(networkClient, listOpts).AllPages()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = networks.ExtractNetworksInto(allPages, &allNetworks)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, network := range allNetworks {
|
||||
fmt.Println("%+v\n", network)
|
||||
}
|
||||
|
||||
Example to Create a Network with External Information
|
||||
|
||||
iTrue := true
|
||||
networkCreateOpts := networks.CreateOpts{
|
||||
Name: "private",
|
||||
AdminStateUp: &iTrue,
|
||||
}
|
||||
|
||||
createOpts := external.CreateOptsExt{
|
||||
networkCreateOpts,
|
||||
&iTrue,
|
||||
}
|
||||
|
||||
network, err := networks.Create(networkClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
*/
|
||||
package external
|
84
vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/requests.go
generated
vendored
Normal file
84
vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/requests.go
generated
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
package external
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
|
||||
)
|
||||
|
||||
// ListOptsExt adds the external network options to the base ListOpts.
|
||||
type ListOptsExt struct {
|
||||
networks.ListOptsBuilder
|
||||
External *bool `q:"router:external"`
|
||||
}
|
||||
|
||||
// ToNetworkListQuery adds the router:external option to the base network
|
||||
// list options.
|
||||
func (opts ListOptsExt) ToNetworkListQuery() (string, error) {
|
||||
q, err := gophercloud.BuildQueryString(opts.ListOptsBuilder)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
params := q.Query()
|
||||
if opts.External != nil {
|
||||
v := strconv.FormatBool(*opts.External)
|
||||
params.Add("router:external", v)
|
||||
}
|
||||
|
||||
q = &url.URL{RawQuery: params.Encode()}
|
||||
return q.String(), err
|
||||
}
|
||||
|
||||
// CreateOptsExt is the structure used when creating new external network
|
||||
// resources. It embeds networks.CreateOpts and so inherits all of its required
|
||||
// and optional fields, with the addition of the External field.
|
||||
type CreateOptsExt struct {
|
||||
networks.CreateOptsBuilder
|
||||
External *bool `json:"router:external,omitempty"`
|
||||
}
|
||||
|
||||
// ToNetworkCreateMap adds the router:external options to the base network
|
||||
// creation options.
|
||||
func (opts CreateOptsExt) ToNetworkCreateMap() (map[string]interface{}, error) {
|
||||
base, err := opts.CreateOptsBuilder.ToNetworkCreateMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if opts.External == nil {
|
||||
return base, nil
|
||||
}
|
||||
|
||||
networkMap := base["network"].(map[string]interface{})
|
||||
networkMap["router:external"] = opts.External
|
||||
|
||||
return base, nil
|
||||
}
|
||||
|
||||
// UpdateOptsExt is the structure used when updating existing external network
|
||||
// resources. It embeds networks.UpdateOpts and so inherits all of its required
|
||||
// and optional fields, with the addition of the External field.
|
||||
type UpdateOptsExt struct {
|
||||
networks.UpdateOptsBuilder
|
||||
External *bool `json:"router:external,omitempty"`
|
||||
}
|
||||
|
||||
// ToNetworkUpdateMap casts an UpdateOpts struct to a map.
|
||||
func (opts UpdateOptsExt) ToNetworkUpdateMap() (map[string]interface{}, error) {
|
||||
base, err := opts.UpdateOptsBuilder.ToNetworkUpdateMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if opts.External == nil {
|
||||
return base, nil
|
||||
}
|
||||
|
||||
networkMap := base["network"].(map[string]interface{})
|
||||
networkMap["router:external"] = opts.External
|
||||
|
||||
return base, nil
|
||||
}
|
8
vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/results.go
generated
vendored
Normal file
8
vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external/results.go
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
package external
|
||||
|
||||
// NetworkExternalExt represents a decorated form of a Network with based on the
|
||||
// "external-net" extension.
|
||||
type NetworkExternalExt struct {
|
||||
// Specifies whether the network is an external network or not.
|
||||
External bool `json:"router:external"`
|
||||
}
|
|
@ -839,6 +839,12 @@
|
|||
"revision": "7112fcd50da4ea27e8d4d499b30f04eea143bec2",
|
||||
"revisionTime": "2018-05-31T02:06:30Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "x6lD4wQOZc1rtm6kMaUBMwLxAlA=",
|
||||
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external",
|
||||
"revision": "00dcc07f1071d5f96520fac7a2b9a30eabccf879",
|
||||
"revisionTime": "2018-06-10T02:06:14Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "K4VAatvB/jywsU+g/mU7bnSaVaI=",
|
||||
"path": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips",
|
||||
|
|
Loading…
Reference in New Issue