Merge pull request #4898 from Fodoj/add-router-type
provider/openstack Add value_specs for routers
This commit is contained in:
commit
779b36106f
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue