provider/openstack: gophercloud migration: Migrate RouterCreateOpts to types.go
This commit is contained in:
parent
56cc232956
commit
58c3c4ef8e
|
@ -63,50 +63,6 @@ func resourceNetworkingRouterV2() *schema.Resource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// routerCreateOpts contains all the values needed to create a new router. There are
|
|
||||||
// no required values.
|
|
||||||
type RouterCreateOpts struct {
|
|
||||||
Name string
|
|
||||||
AdminStateUp *bool
|
|
||||||
Distributed *bool
|
|
||||||
TenantID string
|
|
||||||
GatewayInfo *routers.GatewayInfo
|
|
||||||
ValueSpecs map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToRouterCreateMap casts a routerCreateOpts struct to a map.
|
|
||||||
func (opts RouterCreateOpts) ToRouterCreateMap() (map[string]interface{}, error) {
|
|
||||||
r := make(map[string]interface{})
|
|
||||||
|
|
||||||
if gophercloud.MaybeString(opts.Name) != nil {
|
|
||||||
r["name"] = opts.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.AdminStateUp != nil {
|
|
||||||
r["admin_state_up"] = opts.AdminStateUp
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Distributed != nil {
|
|
||||||
r["distributed"] = opts.Distributed
|
|
||||||
}
|
|
||||||
|
|
||||||
if gophercloud.MaybeString(opts.TenantID) != nil {
|
|
||||||
r["tenant_id"] = opts.TenantID
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.GatewayInfo != nil {
|
|
||||||
r["external_gateway_info"] = opts.GatewayInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.ValueSpecs != nil {
|
|
||||||
for k, v := range opts.ValueSpecs {
|
|
||||||
r[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return map[string]interface{}{"router": r}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{}) error {
|
func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{}) error {
|
||||||
config := meta.(*Config)
|
config := meta.(*Config)
|
||||||
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
|
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
|
||||||
|
@ -115,9 +71,11 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
createOpts := RouterCreateOpts{
|
createOpts := RouterCreateOpts{
|
||||||
|
routers.CreateOpts{
|
||||||
Name: d.Get("name").(string),
|
Name: d.Get("name").(string),
|
||||||
TenantID: d.Get("tenant_id").(string),
|
TenantID: d.Get("tenant_id").(string),
|
||||||
ValueSpecs: MapValueSpecs(d),
|
},
|
||||||
|
MapValueSpecs(d),
|
||||||
}
|
}
|
||||||
|
|
||||||
if asuRaw, ok := d.GetOk("admin_state_up"); ok {
|
if asuRaw, ok := d.GetOk("admin_state_up"); ok {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package openstack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gophercloud/gophercloud"
|
"github.com/gophercloud/gophercloud"
|
||||||
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
|
||||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,3 +17,15 @@ type SubnetCreateOpts struct {
|
||||||
func (opts SubnetCreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) {
|
func (opts SubnetCreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) {
|
||||||
return BuildRequest(opts, "subnet")
|
return BuildRequest(opts, "subnet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RouterCreateOpts represents the attributes used when creating a new router.
|
||||||
|
type RouterCreateOpts struct {
|
||||||
|
routers.CreateOpts
|
||||||
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToRouterCreateMap casts a CreateOpts struct to a map.
|
||||||
|
// It overrides routers.ToRouterCreateMap to add the ValueSpecs field.
|
||||||
|
func (opts RouterCreateOpts) ToRouterCreateMap() (map[string]interface{}, error) {
|
||||||
|
return BuildRequest(opts, "router")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue