Skip to content

Commit

Permalink
Fix VM getters to work with shutdown VMs
Browse files Browse the repository at this point in the history
convertSDKNicConfiguration() was assuming that VMs will have an active
NIC configuration. This is not the case for shutdown VMs, so we need to
account for that.

Signed-off-by: Aravindh Puthiyaparambil <aravindh.foss@pm.me>
  • Loading branch information
Aravindh Puthiyaparambil committed Oct 23, 2024
1 parent a5d2d8c commit 402d845
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,28 @@ func convertSDKInitialization(sdkObject *ovirtsdk.Vm) (*initialization, error) {
}

func convertSDKNicConfiguration(sdkObject *ovirtsdk.NicConfiguration) NicConfiguration {
ipv4 := sdkObject.MustIp()
name, _ := sdkObject.Name()
ipv4, ok := sdkObject.Ip()
if !ok {
return NewNicConfiguration(
name, IP{
Address: "",
Gateway: "",
Netmask: "",
Version: IPVERSION_V4,
},
)
}

// It is fine for these values to be empty strings to account for shutdown VMs where these values are not set.
address, _ := ipv4.Address()
gateway, _ := ipv4.Gateway()
netmask, _ := ipv4.Netmask()
nicConfiguration := NewNicConfiguration(
sdkObject.MustName(), IP{
Address: ipv4.MustAddress(),
Gateway: ipv4.MustGateway(),
Netmask: ipv4.MustNetmask(),
name, IP{
Address: address,
Gateway: gateway,
Netmask: netmask,
Version: IPVERSION_V4,
},
)
Expand Down

0 comments on commit 402d845

Please sign in to comment.