Skip to content

Commit

Permalink
Support dynamic network type address
Browse files Browse the repository at this point in the history
Signed-off-by: Yussuf Shaikh <yussuf.shaikh@ibm.com>
  • Loading branch information
yussufsh authored and hkantare committed Mar 23, 2022
1 parent 32d52f6 commit bb6e6fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ibm/service/power/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m
for i, pvmip := range powervmdata.Addresses {

p := make(map[string]interface{})
p["ip"] = pvmip.IP
p["ip"] = pvmip.IPAddress
p["network_name"] = pvmip.NetworkName
p["network_id"] = pvmip.NetworkID
p["macaddress"] = pvmip.MacAddress
Expand Down
25 changes: 13 additions & 12 deletions ibm/service/power/data_source_ibm_pi_instance_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,20 @@ func dataSourceIBMPIInstancesIPRead(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

for _, address := range powervmdata.Addresses {
if address.NetworkName == networkName {
log.Printf("Printing the ip %s", address.IP)
d.SetId(address.NetworkID)
d.Set("ip", address.IP)
d.Set("network_id", address.NetworkID)
d.Set("macaddress", address.MacAddress)
d.Set("external_ip", address.ExternalIP)
d.Set("type", address.Type)
for _, network := range powervmdata.Networks {
if network.NetworkName == networkName {
log.Printf("Printing the ip %s", network.IPAddress)
d.SetId(network.NetworkID)
d.Set("ip", network.IPAddress)
d.Set("network_id", network.NetworkID)
d.Set("macaddress", network.MacAddress)
d.Set("external_ip", network.ExternalIP)
d.Set("type", network.Type)

IPObject := net.ParseIP(address.IP).To4()

d.Set("ipoctet", strconv.Itoa(int(IPObject[3])))
IPObject := net.ParseIP(network.IPAddress).To4()
if len(IPObject) > 0 {
d.Set("ipoctet", strconv.Itoa(int(IPObject[3])))
}

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/power/data_source_ibm_pi_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func flattenPvmInstanceNetworks(list []*models.PVMInstanceNetwork) (networks []m
for i, pvmip := range list {

p := make(map[string]interface{})
p["ip"] = pvmip.IP
p["ip"] = pvmip.IPAddress
p["network_name"] = pvmip.NetworkName
p["network_id"] = pvmip.NetworkID
p["macaddress"] = pvmip.MacAddress
Expand Down

0 comments on commit bb6e6fe

Please sign in to comment.