From 1dc030f5572d4a41e642e918ba83b28e4accaa2c Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Wed, 21 Dec 2016 12:00:13 +0200 Subject: [PATCH] Add a function to get all the IPs of a VM Now that we've started using multiple networks, it's nice to be able to get all IPs of a VM. Apparently, there's a strange scheme for the names: The first is , the others are . We should probably change it, but regardless, for now this allows getting all IPs. --- lago/plugins/vm.py | 11 +++++++++++ lago/virt.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/lago/plugins/vm.py b/lago/plugins/vm.py index 2f23b8a5..15d01572 100644 --- a/lago/plugins/vm.py +++ b/lago/plugins/vm.py @@ -338,6 +338,17 @@ def iscsi_name(self): def ip(self): return str(self.virt_env.get_net().resolve(self.name())) + def all_ips(self): + nets = {} + ips = [] + nets = self.virt_env.get_nets() + for net in nets.values(): + mapping = net.mapping() + for hostname, ip in mapping.items(): + if hostname.startswith(self.name()): + ips.append(str(ip)) + return ips + def ssh( self, command, diff --git a/lago/virt.py b/lago/virt.py index 35a9da21..3b08287a 100644 --- a/lago/virt.py +++ b/lago/virt.py @@ -345,6 +345,9 @@ def add_mapping(self, name, ip, save=True): def resolve(self, name): return self._spec['mapping'][name] + def mapping(self): + return self._spec['mapping'] + def _libvirt_name(self): return self._env.prefixed_name(self.name(), max_length=15)