Skip to content

Commit b31b044

Browse files
committed
provider/openstack: Add value_specs option to openstack_networking_port_v2.
Refactored to use common types.go Add supporting documentation
1 parent eb8a9ef commit b31b044

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

builtin/providers/openstack/resource_openstack_networking_port_v2.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func resourceNetworkingPortV2() *schema.Resource {
115115
},
116116
},
117117
},
118+
"value_specs": &schema.Schema{
119+
Type: schema.TypeMap,
120+
Optional: true,
121+
ForceNew: true,
122+
},
118123
},
119124
}
120125
}
@@ -126,17 +131,20 @@ func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) er
126131
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
127132
}
128133

129-
createOpts := ports.CreateOpts{
130-
Name: d.Get("name").(string),
131-
AdminStateUp: resourcePortAdminStateUpV2(d),
132-
NetworkID: d.Get("network_id").(string),
133-
MACAddress: d.Get("mac_address").(string),
134-
TenantID: d.Get("tenant_id").(string),
135-
DeviceOwner: d.Get("device_owner").(string),
136-
SecurityGroups: resourcePortSecurityGroupsV2(d),
137-
DeviceID: d.Get("device_id").(string),
138-
FixedIPs: resourcePortFixedIpsV2(d),
139-
AllowedAddressPairs: resourceAllowedAddressPairsV2(d),
134+
createOpts := PortCreateOpts{
135+
ports.CreateOpts{
136+
Name: d.Get("name").(string),
137+
AdminStateUp: resourcePortAdminStateUpV2(d),
138+
NetworkID: d.Get("network_id").(string),
139+
MACAddress: d.Get("mac_address").(string),
140+
TenantID: d.Get("tenant_id").(string),
141+
DeviceOwner: d.Get("device_owner").(string),
142+
SecurityGroups: resourcePortSecurityGroupsV2(d),
143+
DeviceID: d.Get("device_id").(string),
144+
FixedIPs: resourcePortFixedIpsV2(d),
145+
AllowedAddressPairs: resourceAllowedAddressPairsV2(d),
146+
},
147+
MapValueSpecs(d),
140148
}
141149

142150
log.Printf("[DEBUG] Create Options: %#v", createOpts)

builtin/providers/openstack/types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package openstack
33
import (
44
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
55
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
6+
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
67
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
78
)
89

@@ -18,6 +19,18 @@ func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, erro
1819
return BuildRequest(opts, "network")
1920
}
2021

22+
// PortCreateOpts represents the attributes used when creating a new port.
23+
type PortCreateOpts struct {
24+
ports.CreateOpts
25+
ValueSpecs map[string]string `json:"value_specs,omitempty"`
26+
}
27+
28+
// ToPortCreateMap casts a CreateOpts struct to a map.
29+
// It overrides ports.ToPortCreateMap to add the ValueSpecs field.
30+
func (opts PortCreateOpts) ToPortCreateMap() (map[string]interface{}, error) {
31+
return BuildRequest(opts, "port")
32+
}
33+
2134
// RouterCreateOpts represents the attributes used when creating a new router.
2235
type RouterCreateOpts struct {
2336
routers.CreateOpts

website/source/docs/providers/openstack/r/networking_port_v2.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ The following arguments are supported:
6767
addresses that can be active on this port. The structure is described
6868
below.
6969

70+
* `value_specs` - (Optional) Map of additional options.
71+
7072
The `fixed_ip` block supports:
7173

7274
* `subnet_id` - (Required) Subnet in which to allocate IP address for

0 commit comments

Comments
 (0)