Skip to content

Commit

Permalink
adding hostname when reserve ip
Browse files Browse the repository at this point in the history
  • Loading branch information
stobias123 committed Nov 10, 2020
1 parent 0aeaf39 commit e9a288e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ require (
github.com/hashicorp/terraform v0.12.29
github.com/hashicorp/terraform-plugin-sdk v1.15.0
github.com/sirupsen/logrus v1.6.0
github.com/stobias123/gosolar v0.4.0
github.com/stobias123/gosolar v0.4.2
)
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stobias123/gosolar v0.4.0 h1:pLarMj/edVZDav1TETI37XXFvCad8Hr8FV84JFJI0jM=
github.com/stobias123/gosolar v0.4.0/go.mod h1:DjgQtGiBnBwAb5oKhAAn6oXC5XB1Q9dwPjpf3k6wb/I=
github.com/stobias123/gosolar v0.4.2 h1:HBGtJoFUcSQvL7EWVUtjIWWry33yrtihazd9G8tjIfU=
github.com/stobias123/gosolar v0.4.2/go.mod h1:0+9qw5WGetp5oAs7lpSDR+PcjdR++fiq6tkRgfxT5VU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down Expand Up @@ -514,6 +514,7 @@ golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa h1:KIDDMLT1O0Nr7TSxp8xM5tJcdn8tgyAONntO829og1M=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
Expand Down
10 changes: 9 additions & 1 deletion resource_ip_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ func resourceIPAddressCreate(d *schema.ResourceData, m interface{}) error {
suggestedIP := client.GetFirstAvailableIP(subnet.Address, fmt.Sprintf("%d", subnet.CIDR))
log.Info(suggestedIP)
reservedIP := client.ReserveIP(suggestedIP.Address)
client.CommentOnIPNode(suggestedIP.Address, d.Get("hostname").(string))

// This is really kind of sloppy, I should be returning err from gosolar.
if len(d.Get("hostname").(string)) > 0 {
ipHostname := client.AddHostnametoIPNode(suggestedIP.Address, d.Get("hostname").(string))

log.Info("SetHostname")
log.Info(ipHostname)
}

log.Info("Reserved IP")
log.Info(reservedIP)

log.Info("Suggested IP")
log.Info(suggestedIP)

d.Set("vlan", subnet.VLAN)
//d.Set("subnet_name", subnet.DisplayName)
d.Set("address", suggestedIP.Address)
Expand Down

0 comments on commit e9a288e

Please sign in to comment.