[virt-tools-list] [PATCH 2/2] add preferences option to enable 'show first ip'
Dylan Stephano-Shachter
dstephanoshachter at gmail.com
Fri Mar 2 06:27:57 UTC 2018
---
data/org.virt-manager.virt-manager.gschema.xml | 6 ++++++
ui/preferences.ui | 15 +++++++++++++++
virtManager/config.py | 8 ++++++++
virtManager/domain.py | 3 +--
virtManager/engine.py | 7 +++++++
virtManager/manager.py | 8 +++++++-
virtManager/preferences.py | 9 +++++++++
7 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/data/org.virt-manager.virt-manager.gschema.xml b/data/org.virt-manager.virt-manager.gschema.xml
index d88450f5..61901cc8 100644
--- a/data/org.virt-manager.virt-manager.gschema.xml
+++ b/data/org.virt-manager.virt-manager.gschema.xml
@@ -47,6 +47,12 @@
<description>Show system tray icon while app is running</description>
</key>
+ <key name="show-ip" type="b">
+ <default>false</default>
+ <summary>Show first IP address</summary>
+ <description>Show the first IP address of each machine (requires qemu-guest-agent)</description>
+ </key>
+
<key name="manager-window-height" type="i">
<default>0</default>
<summary>Default manager window height</summary>
diff --git a/ui/preferences.ui b/ui/preferences.ui
index 81802a28..af14220c 100644
--- a/ui/preferences.ui
+++ b/ui/preferences.ui
@@ -58,6 +58,21 @@
<property name="top_attach">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="prefs-show-ip">
+ <property name="label" translatable="yes">Show first IP address</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_prefs_show_ip_toggled" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/virtManager/config.py b/virtManager/config.py
index 4d47b477..81db38ea 100644
--- a/virtManager/config.py
+++ b/virtManager/config.py
@@ -396,6 +396,14 @@ class vmmConfig(object):
def set_view_system_tray(self, val):
self.conf.set("/system-tray", val)
+ # Display first IP
+ def on_show_ip_changed(self, cb):
+ return self.conf.notify_add("/show-ip", cb)
+ def get_show_ip(self):
+ return self.conf.get("/show-ip")
+ def set_show_ip(self, val):
+ self.conf.set("/show-ip", val)
+
# Stats history and interval length
def get_stats_history_length(self):
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 83828348..5c1d3d3f 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -1172,8 +1172,7 @@ class vmmDomain(vmmLibvirtObject):
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"
+ 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"
diff --git a/virtManager/engine.py b/virtManager/engine.py
index b0b90065..c3b5f47c 100644
--- a/virtManager/engine.py
+++ b/virtManager/engine.py
@@ -121,6 +121,8 @@ class vmmEngine(vmmGObject):
self.config.on_stats_update_interval_changed(self.reschedule_timer))
self.add_gsettings_handle(
self.config.on_view_system_tray_changed(self.system_tray_changed))
+ self.add_gsettings_handle(
+ self.config.on_show_ip_changed(self.show_ip_changed))
self.schedule_timer()
self.load_stored_uris()
@@ -214,6 +216,11 @@ class vmmEngine(vmmGObject):
# Show the manager so that the user can control the application
self._show_manager()
+ def show_ip_changed(self, *ignore):
+ showip_enabled = self.config.get_show_ip()
+ if self.windows == 0 and not showip_enabled:
+ self._show_manager()
+
def _add_default_conn(self):
manager = self.get_manager()
diff --git a/virtManager/manager.py b/virtManager/manager.py
index c5b3ed4f..83ca7512 100644
--- a/virtManager/manager.py
+++ b/virtManager/manager.py
@@ -331,6 +331,8 @@ class vmmManager(vmmGObjectUI):
self.connmenu.show_all()
def init_vmlist(self):
+ self.add_gsettings_handle(
+ self.config.on_show_ip_changed(self.show_ip_changed))
vmlist = self.widget("vm-list")
self.widget("vm-notebook").set_show_tabs(False)
@@ -463,6 +465,10 @@ class vmmManager(vmmGObjectUI):
# Action listeners #
####################
+ def show_ip_changed(self):
+ logging.debug("Updating show_ip")
+ # TODO Update the currently listed machines
+
def window_resized(self, ignore, ignore2):
if not self.is_visible():
return
@@ -643,7 +649,7 @@ class vmmManager(vmmGObjectUI):
def _build_vm_markup(self, name, status, ipaddr):
domtext = ("<span size='smaller' weight='bold'>%s</span>" %
util.xml_escape(name))
- if status == 'Running':
+ if status == 'Running' and self.config.get_show_ip():
statetext = "<span size='smaller'>%s (%s)</span>" % (status, ipaddr)
else:
statetext = "<span size='smaller'>%s</span>" % status
diff --git a/virtManager/preferences.py b/virtManager/preferences.py
index bf67590f..c8906801 100644
--- a/virtManager/preferences.py
+++ b/virtManager/preferences.py
@@ -34,6 +34,7 @@ class vmmPreferences(vmmGObjectUI):
self._init_ui()
self.refresh_view_system_tray()
+ self.refresh_show_ip()
self.refresh_update_interval()
self.refresh_console_accels()
self.refresh_console_scaling()
@@ -61,6 +62,7 @@ class vmmPreferences(vmmGObjectUI):
"on_prefs_close_clicked": self.close,
"on_prefs_system_tray_toggled": self.change_view_system_tray,
+ "on_prefs_show_ip_toggled": self.change_show_ip,
"on_prefs_stats_update_interval_changed": self.change_update_interval,
"on_prefs_console_accels_toggled": self.change_console_accels,
"on_prefs_console_scaling_changed": self.change_console_scaling,
@@ -178,6 +180,10 @@ class vmmPreferences(vmmGObjectUI):
val = self.config.get_view_system_tray()
self.widget("prefs-system-tray").set_active(bool(val))
+ def refresh_show_ip(self):
+ val = self.config.get_show_ip()
+ self.widget("prefs-show-ip").set_active(bool(val))
+
def refresh_update_interval(self):
self.widget("prefs-stats-update-interval").set_value(
self.config.get_stats_update_interval())
@@ -330,6 +336,9 @@ class vmmPreferences(vmmGObjectUI):
def change_view_system_tray(self, src):
self.config.set_view_system_tray(src.get_active())
+ def change_show_ip(self, src):
+ self.config.set_show_ip(src.get_active())
+
def change_update_interval(self, src):
self.config.set_stats_update_interval(src.get_value_as_int())
--
2.14.3
More information about the virt-tools-list
mailing list