Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/openstack Add value_specs for routers #4898

Merged
merged 1 commit into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,70 @@ 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))
if err != nil {
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 {
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.