provider/openstack: gophercloud migration: Migrate NetworkCreateOpts to types.go
This commit is contained in:
parent
58c3c4ef8e
commit
bfab530410
|
@ -62,41 +62,6 @@ func resourceNetworkingNetworkV2() *schema.Resource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkCreateOpts contains all teh values needed to create a new network.
|
|
||||||
type NetworkCreateOpts struct {
|
|
||||||
AdminStateUp *bool
|
|
||||||
Name string
|
|
||||||
Shared *bool
|
|
||||||
TenantID string
|
|
||||||
ValueSpecs map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToNetworkCreateMpa casts a networkCreateOpts struct to a map.
|
|
||||||
func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
|
|
||||||
n := make(map[string]interface{})
|
|
||||||
|
|
||||||
if opts.AdminStateUp != nil {
|
|
||||||
n["admin_state_up"] = &opts.AdminStateUp
|
|
||||||
}
|
|
||||||
if opts.Name != "" {
|
|
||||||
n["name"] = opts.Name
|
|
||||||
}
|
|
||||||
if opts.Shared != nil {
|
|
||||||
n["shared"] = &opts.Shared
|
|
||||||
}
|
|
||||||
if opts.TenantID != "" {
|
|
||||||
n["tenant_id"] = opts.TenantID
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.ValueSpecs != nil {
|
|
||||||
for k, v := range opts.ValueSpecs {
|
|
||||||
n[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return map[string]interface{}{"network": n}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) error {
|
func resourceNetworkingNetworkV2Create(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))
|
||||||
|
@ -105,9 +70,11 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
createOpts := NetworkCreateOpts{
|
createOpts := NetworkCreateOpts{
|
||||||
Name: d.Get("name").(string),
|
networks.CreateOpts{
|
||||||
TenantID: d.Get("tenant_id").(string),
|
Name: d.Get("name").(string),
|
||||||
ValueSpecs: MapValueSpecs(d),
|
TenantID: d.Get("tenant_id").(string),
|
||||||
|
},
|
||||||
|
MapValueSpecs(d),
|
||||||
}
|
}
|
||||||
|
|
||||||
asuRaw := d.Get("admin_state_up").(string)
|
asuRaw := d.Get("admin_state_up").(string)
|
||||||
|
|
|
@ -3,9 +3,22 @@ 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/extensions/layer3/routers"
|
||||||
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
|
||||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NetworkCreateOpts represents the attributes used when creating a new network.
|
||||||
|
type NetworkCreateOpts struct {
|
||||||
|
networks.CreateOpts
|
||||||
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToNetworkCreateMap casts a CreateOpts struct to a map.
|
||||||
|
// It overrides networks.ToNetworkCreateMap to add the ValueSpecs field.
|
||||||
|
func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
|
||||||
|
return BuildRequest(opts, "network")
|
||||||
|
}
|
||||||
|
|
||||||
// SubnetCreateOpts represents the attributes used when creating a new subnet.
|
// SubnetCreateOpts represents the attributes used when creating a new subnet.
|
||||||
type SubnetCreateOpts struct {
|
type SubnetCreateOpts struct {
|
||||||
subnets.CreateOpts
|
subnets.CreateOpts
|
||||||
|
|
Loading…
Reference in New Issue