mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
manager: Expand logic to avoid colliding connection descriptions
And drop some unused code
This commit is contained in:
parent
aa823b5b58
commit
7fcdd61920
@ -354,7 +354,8 @@ class vmmConnection(vmmGObject):
|
||||
# Connection pretty print routines #
|
||||
####################################
|
||||
|
||||
def _get_pretty_desc(self, active, shorthost, show_trans):
|
||||
def get_pretty_desc(self, shorthost=True, show_transport=False,
|
||||
show_user=False):
|
||||
def match_whole_string(orig, reg):
|
||||
match = re.match(reg, orig)
|
||||
if not match:
|
||||
@ -383,6 +384,11 @@ class vmmConnection(vmmGObject):
|
||||
hostname = hostname.split(":")[0]
|
||||
|
||||
if hostname:
|
||||
if show_user and username:
|
||||
hostname = username + "@" + hostname
|
||||
if port:
|
||||
hostname += ":" + port
|
||||
|
||||
if shorthost and not is_ip_addr(hostname):
|
||||
rest = hostname.split(".")[0]
|
||||
else:
|
||||
@ -410,16 +416,8 @@ class vmmConnection(vmmGObject):
|
||||
if scheme in pretty_map:
|
||||
hv = pretty_map[scheme]
|
||||
|
||||
if hv == "QEMU" and active and self.caps.is_kvm_available():
|
||||
hv += "/KVM"
|
||||
|
||||
if show_trans:
|
||||
if transport:
|
||||
hv += "+" + transport
|
||||
if username:
|
||||
hostname = username + "@" + hostname
|
||||
if port:
|
||||
hostname += ":" + port
|
||||
if show_transport and transport:
|
||||
hv += "+" + transport
|
||||
|
||||
if path and path != "/system" and path != "/":
|
||||
if path == "/session":
|
||||
@ -432,12 +430,6 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
return "%s (%s)" % (rest, hv)
|
||||
|
||||
def get_pretty_desc_inactive(self, shorthost=True, transport=False):
|
||||
return self._get_pretty_desc(False, shorthost, transport)
|
||||
|
||||
def get_pretty_desc_active(self, shorthost=True, transport=False):
|
||||
return self._get_pretty_desc(True, shorthost, transport)
|
||||
|
||||
|
||||
#######################
|
||||
# API support helpers #
|
||||
|
@ -641,7 +641,7 @@ class vmmManager(vmmGObjectUI):
|
||||
|
||||
def _build_row(self, conn, vm):
|
||||
if conn:
|
||||
name = conn.get_pretty_desc_inactive(False)
|
||||
name = conn.get_pretty_desc(shorthost=False)
|
||||
markup = self._build_conn_markup(conn, name)
|
||||
status = ("<span size='smaller'>%s</span>" %
|
||||
conn.get_state_text())
|
||||
@ -697,6 +697,40 @@ class vmmManager(vmmGObjectUI):
|
||||
self.rows[conn.get_uri()] = model[path]
|
||||
return _iter
|
||||
|
||||
def _ensure_conn_descs_dont_collide(self):
|
||||
# By default we only show hostname + hypervisor in the conn label.
|
||||
# So if we have two URIs like qemu+ssh://host and qemu+tcp://host,
|
||||
# we want to add the transport in the description to differentiate
|
||||
connrows = [row for row in self.rows.values() if row[ROW_IS_CONN]]
|
||||
for row in connrows:
|
||||
conn = row[ROW_HANDLE]
|
||||
connsplit = util.uri_split(conn.get_uri())
|
||||
scheme = connsplit[0]
|
||||
|
||||
show_transport = False
|
||||
show_user = False
|
||||
|
||||
for checkrow in connrows:
|
||||
checkconn = checkrow[ROW_HANDLE]
|
||||
if conn is checkconn:
|
||||
continue
|
||||
checkconnsplit = util.uri_split(checkconn.get_uri())
|
||||
checkscheme = checkconnsplit[0]
|
||||
|
||||
if ((scheme.split("+")[0] == checkscheme.split("+")[0]) and
|
||||
connsplit[2] == checkconnsplit[2] and
|
||||
connsplit[3] == checkconnsplit[3]):
|
||||
show_transport = True
|
||||
if ("+" in scheme and "+" in checkscheme and
|
||||
scheme.split("+")[1] == checkscheme.split("+")[1]):
|
||||
show_user = True
|
||||
|
||||
newname = conn.get_pretty_desc(
|
||||
shorthost=False, show_transport=show_transport,
|
||||
show_user=show_user)
|
||||
if newname != row[ROW_SORT_KEY]:
|
||||
self.conn_state_changed(conn, newname=newname)
|
||||
|
||||
def add_conn(self, engine_ignore, conn):
|
||||
# Called from engine.py signal conn-added
|
||||
|
||||
@ -711,27 +745,9 @@ class vmmManager(vmmGObjectUI):
|
||||
conn.connect("resources-sampled", self.conn_row_updated)
|
||||
conn.connect("state-changed", self.conn_state_changed)
|
||||
|
||||
# add the connection to the treeModel
|
||||
vmlist = self.widget("vm-list")
|
||||
row = self._append_conn(vmlist.get_model(), conn)
|
||||
|
||||
# Try to make sure that 2 row descriptions don't collide
|
||||
connrows = []
|
||||
descs = []
|
||||
for row in self.rows.values():
|
||||
if row[ROW_IS_CONN]:
|
||||
connrows.append(row)
|
||||
for row in connrows:
|
||||
descs.append(row[ROW_SORT_KEY])
|
||||
|
||||
for row in connrows:
|
||||
conn = row[ROW_HANDLE]
|
||||
name = row[ROW_SORT_KEY]
|
||||
if descs.count(name) <= 1:
|
||||
continue
|
||||
|
||||
newname = conn.get_pretty_desc_inactive(False, True)
|
||||
self.conn_state_changed(conn, newname=newname)
|
||||
self._append_conn(vmlist.get_model(), conn)
|
||||
self._ensure_conn_descs_dont_collide()
|
||||
|
||||
def remove_conn(self, engine_ignore, uri):
|
||||
# Called from engine.py signal conn-removed
|
||||
|
@ -397,7 +397,7 @@ class vmmMigrateDialog(vmmGObjectUI):
|
||||
origuri = self.conn.get_uri()
|
||||
|
||||
can_migrate = False
|
||||
desc = destconn.get_pretty_desc_inactive()
|
||||
desc = destconn.get_pretty_desc()
|
||||
reason = ""
|
||||
desturi = destconn.get_uri()
|
||||
|
||||
|
@ -215,7 +215,7 @@ class vmmSystray(vmmGObject):
|
||||
if conn.get_uri() in self.conn_menuitems:
|
||||
return
|
||||
|
||||
menu_item = Gtk.MenuItem.new_with_label(conn.get_pretty_desc_inactive())
|
||||
menu_item = Gtk.MenuItem.new_with_label(conn.get_pretty_desc())
|
||||
menu_item.show()
|
||||
vm_submenu = Gtk.Menu()
|
||||
vm_submenu.show()
|
||||
|
Loading…
Reference in New Issue
Block a user