From f86a4bfc622bd36da5d33dea18d27621afdab95e Mon Sep 17 00:00:00 2001 From: Janos Bonic <86970079+janosdebugs@users.noreply.github.com> Date: Mon, 13 Jun 2022 11:20:34 +0200 Subject: [PATCH] Added the ability to get (not just wait for) non-local IP addresses --- vm.go | 12 ++++++++++++ vm_ip_get_nonlocal.go | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 vm_ip_get_nonlocal.go diff --git a/vm.go b/vm.go index 1095284..ce9124c 100644 --- a/vm.go +++ b/vm.go @@ -66,6 +66,11 @@ type VMClient interface { // The returned result will be a map of network interface names and the list of IP addresses assigned to them, // excluding any IP addresses in the specified parameters. GetVMIPAddresses(id VMID, params VMIPSearchParams, retries ...RetryStrategy) (map[string][]net.IP, error) + // GetVMNonLocalIPAddresses fetches the IP addresses and filters them to return only non-local IP addresses. + // + // The returned result will be a map of network interface names and the list of IP addresses assigned to them, + // excluding any IP addresses in the specified parameters. + GetVMNonLocalIPAddresses(id VMID, retries ...RetryStrategy) (map[string][]net.IP, error) // WaitForVMIPAddresses waits for at least one IP address to be reported that is not in specified ranges. // // The returned result will be a map of network interface names and the list of IP addresses assigned to them, @@ -486,6 +491,9 @@ type VM interface { // // The optional parameters let you filter the returned interfaces and IP addresses. GetIPAddresses(params VMIPSearchParams, retries ...RetryStrategy) (map[string][]net.IP, error) + // GetNonLocalIPAddresses fetches the IP addresses, filters them for non-local IP addresses, and returns a map of the + // interface name and list of IP addresses. + GetNonLocalIPAddresses(retries ...RetryStrategy) (map[string][]net.IP, error) // WaitForIPAddresses waits for at least one IP address to be reported that is not in specified ranges. // // The returned result will be a map of network interface names and the list of IP addresses assigned to them, @@ -1872,6 +1880,10 @@ func (v *vm) GetIPAddresses(params VMIPSearchParams, retries ...RetryStrategy) ( return v.client.GetVMIPAddresses(v.id, params, retries...) } +func (v *vm) GetNonLocalIPAddresses(retries ...RetryStrategy) (map[string][]net.IP, error) { + return v.client.GetVMNonLocalIPAddresses(v.id, retries...) +} + func (v *vm) HostID() *HostID { return v.hostID } diff --git a/vm_ip_get_nonlocal.go b/vm_ip_get_nonlocal.go new file mode 100644 index 0000000..1d3a9b5 --- /dev/null +++ b/vm_ip_get_nonlocal.go @@ -0,0 +1,14 @@ +package ovirtclient + +import "net" + +func (m *mockClient) GetVMNonLocalIPAddresses(id VMID, retries ...RetryStrategy) ( + result map[string][]net.IP, + err error, +) { + return waitForIPAddresses(id, nonLocalIPSearchParams, retries, m.logger, m) +} + +func (o *oVirtClient) GetVMNonLocalIPAddresses(id VMID, retries ...RetryStrategy) (map[string][]net.IP, error) { + return waitForIPAddresses(id, nonLocalIPSearchParams, retries, o.logger, o) +}