provider/openstack: gophercloud migration: Migrate NetworkCreateOpts to types.go

This commit is contained in:
Gavin Williams 2016-10-06 16:03:37 +01:00 committed by Joe Topjian
parent 58c3c4ef8e
commit bfab530410
2 changed files with 18 additions and 38 deletions

View File

@ -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 {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
@ -105,9 +70,11 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{})
}
createOpts := NetworkCreateOpts{
Name: d.Get("name").(string),
TenantID: d.Get("tenant_id").(string),
ValueSpecs: MapValueSpecs(d),
networks.CreateOpts{
Name: d.Get("name").(string),
TenantID: d.Get("tenant_id").(string),
},
MapValueSpecs(d),
}
asuRaw := d.Get("admin_state_up").(string)

View File

@ -3,9 +3,22 @@ package openstack
import (
"github.com/gophercloud/gophercloud"
"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"
)
// 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.
type SubnetCreateOpts struct {
subnets.CreateOpts