summaryrefslogtreecommitdiff
path: root/libvirt/resource_libvirt_domain.go
diff options
context:
space:
mode:
authorChristian Simon <simon@swine.de>2017-12-02 18:19:50 +0000
committerChristian Simon <simon@swine.de>2017-12-02 18:19:50 +0000
commit25123515b40e84c8239088cad4482d7b9fb1767e (patch)
tree4ad60acc121ffc091b4d88addbb69e46bac77641 /libvirt/resource_libvirt_domain.go
parent380076c1943ebd10c5e5f54ad4ac751a736c5c1f (diff)
downloadterraform-provider-libvirt-25123515b40e84c8239088cad4482d7b9fb1767e.tar
terraform-provider-libvirt-25123515b40e84c8239088cad4482d7b9fb1767e.tar.gz
Make add/updateHost a bit more resilient
* provide a updateOrAddHost method that first will try to update an existing one, before adding a host entry
Diffstat (limited to 'libvirt/resource_libvirt_domain.go')
-rw-r--r--libvirt/resource_libvirt_domain.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go
index 95a7b7fe..ffbdc40b 100644
--- a/libvirt/resource_libvirt_domain.go
+++ b/libvirt/resource_libvirt_domain.go
@@ -587,9 +587,9 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
if ip == nil {
return fmt.Errorf("Could not parse addresses '%s'", address)
}
- // TODO: we should check the IP is contained in the DHCP addresses served
+
log.Printf("[INFO] Adding IP/MAC/host=%s/%s/%s to %s", ip.String(), mac, hostname, networkName)
- if err := addHost(network, ip.String(), mac, hostname); err != nil {
+ if err := updateOrAddHost(network, ip.String(), mac, hostname); err != nil {
return err
}
}
@@ -720,7 +720,7 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
for _, addressI := range addressesI.([]interface{}) {
address := addressI.(string)
log.Printf("[INFO] Finally adding IP/MAC/host=%s/%s/%s", address, mac, pending.hostname)
- addHost(pending.network, address, mac, pending.hostname)
+ updateOrAddHost(pending.network, address, mac, pending.hostname)
if err != nil {
return fmt.Errorf("Could not add IP/MAC/host=%s/%s/%s: %s", address, mac, pending.hostname, err)
}
@@ -818,7 +818,7 @@ func resourceLibvirtDomainUpdate(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Could not parse addresses '%s'", address)
}
log.Printf("[INFO] Updating IP/MAC/host=%s/%s/%s in '%s' network", ip.String(), mac, hostname, networkName)
- if err := updateHost(network, ip.String(), mac, hostname); err != nil {
+ if err := updateOrAddHost(network, ip.String(), mac, hostname); err != nil {
return err
}
}