Merge pull request #8257 from FedericoCeratto/allowed_address_pairs

provider/openstack: Add allowed_address_pairs
This commit is contained in:
Joe Topjian 2016-08-22 20:06:33 -06:00 committed by GitHub
commit 9e4fc09365
1 changed files with 61 additions and 9 deletions

View File

@ -96,6 +96,25 @@ func resourceNetworkingPortV2() *schema.Resource {
},
},
},
"allowed_address_pairs": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: false,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_address": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"mac_address": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},
},
},
}
}
@ -117,6 +136,7 @@ func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) er
SecurityGroups: resourcePortSecurityGroupsV2(d),
DeviceID: d.Get("device_id").(string),
FixedIPs: resourcePortFixedIpsV2(d),
AllowedAddressPairs: resourceAllowedAddressPairsV2(d),
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
@ -176,6 +196,16 @@ func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) erro
}
d.Set("fixed_ip", ips)
// Convert AllowedAddressPairs to list of map
var pairs []map[string]interface{}
for _, pairObject := range p.AllowedAddressPairs {
pair := make(map[string]interface{})
pair["ip_address"] = pairObject.IPAddress
pair["mac_address"] = pairObject.MACAddress
pairs = append(pairs, pair)
}
d.Set("allowed_address_pairs", pairs)
return nil
}
@ -212,6 +242,10 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er
updateOpts.FixedIPs = resourcePortFixedIpsV2(d)
}
if d.HasChange("allowed_address_pairs") {
updateOpts.AllowedAddressPairs = resourceAllowedAddressPairsV2(d)
}
log.Printf("[DEBUG] Updating Port %s with options: %+v", d.Id(), updateOpts)
_, err = ports.Update(networkingClient, d.Id(), updateOpts).Extract()
@ -272,7 +306,25 @@ func resourcePortFixedIpsV2(d *schema.ResourceData) interface{} {
}
}
return ip
}
func resourceAllowedAddressPairsV2(d *schema.ResourceData) []ports.AddressPair {
// ports.AddressPair
rawPairs := d.Get("allowed_address_pairs").([]interface{})
if len(rawPairs) == 0 {
return nil
}
pairs := make([]ports.AddressPair, len(rawPairs))
for i, raw := range rawPairs {
rawMap := raw.(map[string]interface{})
pairs[i] = ports.AddressPair{
IPAddress: rawMap["ip_address"].(string),
MACAddress: rawMap["mac_address"].(string),
}
}
return pairs
}
func resourcePortAdminStateUpV2(d *schema.ResourceData) *bool {