From 5824036ca66f3c51a30810d78c5e23b62aafdafc Mon Sep 17 00:00:00 2001 From: Kirill Shirinkin Date: Mon, 11 Apr 2016 10:23:01 +0200 Subject: [PATCH] provider/openstack: Add value_specs for routers --- ...resource_openstack_networking_router_v2.go | 64 ++++++++++++++++++- .../r/networking_router_v2.html.markdown | 3 + 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_networking_router_v2.go b/builtin/providers/openstack/resource_openstack_networking_router_v2.go index 7b5f3b8c25a8..d4f80828cc3a 100644 --- a/builtin/providers/openstack/resource_openstack_networking_router_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_router_v2.go @@ -54,10 +54,59 @@ func resourceNetworkingRouterV2() *schema.Resource { ForceNew: true, Computed: true, }, + "value_specs": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + ForceNew: true, + }, }, } } +// 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 { config := meta.(*Config) networkingClient, err := config.networkingV2Client(d.Get("region").(string)) @@ -65,9 +114,10 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error creating OpenStack networking client: %s", err) } - createOpts := routers.CreateOpts{ - Name: d.Get("name").(string), - TenantID: d.Get("tenant_id").(string), + createOpts := RouterCreateOpts{ + Name: d.Get("name").(string), + TenantID: d.Get("tenant_id").(string), + ValueSpecs: routerValueSpecs(d), } if asuRaw, ok := d.GetOk("admin_state_up"); ok { @@ -239,3 +289,11 @@ func waitForRouterDelete(networkingClient *gophercloud.ServiceClient, routerId s return r, "ACTIVE", nil } } + +func routerValueSpecs(d *schema.ResourceData) map[string]string { + m := make(map[string]string) + for key, val := range d.Get("value_specs").(map[string]interface{}) { + m[key] = val.(string) + } + return m +} diff --git a/website/source/docs/providers/openstack/r/networking_router_v2.html.markdown b/website/source/docs/providers/openstack/r/networking_router_v2.html.markdown index 04a261a38cf2..5540adb62c40 100644 --- a/website/source/docs/providers/openstack/r/networking_router_v2.html.markdown +++ b/website/source/docs/providers/openstack/r/networking_router_v2.html.markdown @@ -48,6 +48,8 @@ The following arguments are supported: * `tenant_id` - (Optional) The owner of the floating IP. Required if admin wants to create a router for another tenant. Changing this creates a new router. +* `value_specs` - (Optional) Map of additional driver-specific options. + ## Attributes Reference The following attributes are exported: @@ -57,3 +59,4 @@ The following attributes are exported: * `admin_state_up` - See Argument Reference above. * `external_gateway` - See Argument Reference above. * `tenant_id` - See Argument Reference above. +* `value_specs` - See Argument Reference above.