Merge pull request #1788 from JeanMertz/openstack-floatingip-port
OpenStack: add functionality to attach FloatingIP to Port
This commit is contained in:
commit
5b4bbf08d0
|
@ -14,6 +14,7 @@ func resourceNetworkingFloatingIPV2() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: resourceNetworkFloatingIPV2Create,
|
Create: resourceNetworkFloatingIPV2Create,
|
||||||
Read: resourceNetworkFloatingIPV2Read,
|
Read: resourceNetworkFloatingIPV2Read,
|
||||||
|
Update: resourceNetworkFloatingIPV2Update,
|
||||||
Delete: resourceNetworkFloatingIPV2Delete,
|
Delete: resourceNetworkFloatingIPV2Delete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
@ -33,6 +34,11 @@ func resourceNetworkingFloatingIPV2() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
DefaultFunc: envDefaultFunc("OS_POOL_NAME"),
|
DefaultFunc: envDefaultFunc("OS_POOL_NAME"),
|
||||||
},
|
},
|
||||||
|
"port_id": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Default: "",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +59,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
createOpts := floatingips.CreateOpts{
|
createOpts := floatingips.CreateOpts{
|
||||||
FloatingNetworkID: poolID,
|
FloatingNetworkID: poolID,
|
||||||
|
PortID: d.Get("port_id").(string),
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] Create Options: %#v", createOpts)
|
log.Printf("[DEBUG] Create Options: %#v", createOpts)
|
||||||
floatingIP, err := floatingips.Create(networkClient, createOpts).Extract()
|
floatingIP, err := floatingips.Create(networkClient, createOpts).Extract()
|
||||||
|
@ -78,6 +85,7 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("address", floatingIP.FloatingIP)
|
d.Set("address", floatingIP.FloatingIP)
|
||||||
|
d.Set("port_id", floatingIP.PortID)
|
||||||
poolName, err := getNetworkName(d, meta, floatingIP.FloatingNetworkID)
|
poolName, err := getNetworkName(d, meta, floatingIP.FloatingNetworkID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error retrieving floating IP pool name: %s", err)
|
return fmt.Errorf("Error retrieving floating IP pool name: %s", err)
|
||||||
|
@ -87,6 +95,29 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceNetworkFloatingIPV2Update(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
config := meta.(*Config)
|
||||||
|
networkClient, err := config.networkingV2Client(d.Get("region").(string))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error creating OpenStack network client: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateOpts floatingips.UpdateOpts
|
||||||
|
|
||||||
|
if d.HasChange("port_id") {
|
||||||
|
updateOpts.PortID = d.Get("port_id").(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Update Options: %#v", updateOpts)
|
||||||
|
|
||||||
|
_, err = floatingips.Update(networkClient, d.Id(), updateOpts).Extract()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error updating floating IP: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceNetworkFloatingIPV2Read(d, meta)
|
||||||
|
}
|
||||||
|
|
||||||
func resourceNetworkFloatingIPV2Delete(d *schema.ResourceData, meta interface{}) error {
|
func resourceNetworkFloatingIPV2Delete(d *schema.ResourceData, meta interface{}) error {
|
||||||
config := meta.(*Config)
|
config := meta.(*Config)
|
||||||
networkClient, err := config.networkingV2Client(d.Get("region").(string))
|
networkClient, err := config.networkingV2Client(d.Get("region").(string))
|
||||||
|
|
Loading…
Reference in New Issue