[virt-tools-list] [PATCH 1/2] show the first ip address of running vms
Dylan Stephano-Shachter
dstephanoshachter at gmail.com
Fri Mar 2 06:27:56 UTC 2018
---
virtManager/domain.py | 17 +++++++++++++++++
virtManager/manager.py | 13 +++++++++----
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 6d3dac2d..83828348 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -20,6 +20,7 @@
import logging
import os
+import re
import time
import threading
@@ -50,6 +51,8 @@ vm_status_icons = {
libvirt.VIR_DOMAIN_PMSUSPENDED: "state_paused",
}
+IP_REGEX = re.compile('[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')
+
class _SENTINEL(object):
pass
@@ -1163,6 +1166,20 @@ class vmmDomain(vmmLibvirtObject):
# Libvirt API wrappers #
########################
+ def get_first_ip_addr(self):
+ try:
+ ifaces = self._backend.interfaceAddresses(source=1)
+ for iface in ifaces:
+ if iface != 'lo' and IP_REGEX.match(ifaces[iface]['addrs'][0]['addr']):
+ return ifaces[iface]['addrs'][0]['addr']
+ else:
+ return "IP not found"
+ except libvirt.libvirtError as err:
+ if 'QEMU guest agent is not connected' in str(err):
+ return "qemu-guest-agent not running"
+ else:
+ return str(err)
+
def _conn_tick_poll_param(self):
return "pollvm"
def class_name(self):
diff --git a/virtManager/manager.py b/virtManager/manager.py
index d38fc4e4..c5b3ed4f 100644
--- a/virtManager/manager.py
+++ b/virtManager/manager.py
@@ -640,10 +640,13 @@ class vmmManager(vmmGObjectUI):
color = "#5b5b5b"
return color
- def _build_vm_markup(self, name, status):
+ def _build_vm_markup(self, name, status, ipaddr):
domtext = ("<span size='smaller' weight='bold'>%s</span>" %
util.xml_escape(name))
- statetext = "<span size='smaller'>%s</span>" % status
+ if status == 'Running':
+ statetext = "<span size='smaller'>%s (%s)</span>" % (status, ipaddr)
+ else:
+ statetext = "<span size='smaller'>%s</span>" % status
return domtext + "\n" + statetext
def _build_row(self, conn, vm):
@@ -659,7 +662,8 @@ class vmmManager(vmmGObjectUI):
else:
name = vm.get_name_or_title()
status = vm.run_status()
- markup = self._build_vm_markup(name, status)
+ ipaddr = vm.get_first_ip_addr()
+ markup = self._build_vm_markup(name, status, ipaddr)
status_icon = vm.run_status_icon_name()
hint = vm.get_description()
color = None
@@ -741,11 +745,12 @@ class vmmManager(vmmGObjectUI):
name = vm.get_name_or_title()
status = vm.run_status()
+ ipaddr = vm.get_first_ip_addr()
row[ROW_SORT_KEY] = name
row[ROW_STATUS_ICON] = vm.run_status_icon_name()
row[ROW_IS_VM_RUNNING] = vm.is_active()
- row[ROW_MARKUP] = self._build_vm_markup(name, status)
+ row[ROW_MARKUP] = self._build_vm_markup(name, status, ipaddr)
desc = vm.get_description()
row[ROW_HINT] = util.xml_escape(desc)
--
2.14.3
More information about the virt-tools-list
mailing list