mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-03-12 20:58:28 +03:00
addconn: Add explicit UI for connection username
There have been numerous complaints about the auto-magic nature of usernames and URIs, so let's make it explicit.
This commit is contained in:
parent
e398b0e791
commit
6f4afbcb3b
@ -34,6 +34,18 @@ CONN_SSH = 0
|
||||
CONN_TCP = 1
|
||||
CONN_TLS = 2
|
||||
|
||||
def current_user():
|
||||
try:
|
||||
import getpass
|
||||
return getpass.getuser()
|
||||
except:
|
||||
return ""
|
||||
|
||||
def default_conn_user(conn):
|
||||
if conn == CONN_SSH:
|
||||
return "root"
|
||||
return current_user()
|
||||
|
||||
class vmmConnect(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
"completed": (gobject.SIGNAL_RUN_FIRST,
|
||||
@ -59,6 +71,7 @@ class vmmConnect(gobject.GObject):
|
||||
"on_connection_changed": self.connection_changed,
|
||||
"on_hostname_combo_changed": self.hostname_combo_changed,
|
||||
"on_connect_remote_toggled": self.connect_remote_toggled,
|
||||
"on_username_entry_changed": self.username_changed,
|
||||
|
||||
"on_cancel_clicked": self.cancel,
|
||||
"on_connect_clicked": self.open_connection,
|
||||
@ -128,6 +141,7 @@ class vmmConnect(gobject.GObject):
|
||||
self.window.get_widget("hostname").get_model().clear()
|
||||
self.window.get_widget("hostname").child.set_text("")
|
||||
self.window.get_widget("connect-remote").set_active(False)
|
||||
self.window.get_widget("username-entry").set_text("")
|
||||
self.stop_browse()
|
||||
self.connect_remote_toggled(self.window.get_widget("connect-remote"))
|
||||
self.populate_uri()
|
||||
@ -236,50 +250,65 @@ class vmmConnect(gobject.GObject):
|
||||
def hypervisor_changed(self, src):
|
||||
self.populate_uri()
|
||||
|
||||
def username_changed(self, src):
|
||||
self.populate_uri()
|
||||
|
||||
def connect_remote_toggled(self, src):
|
||||
is_remote = self.is_remote()
|
||||
self.window.get_widget("hostname").set_sensitive(is_remote)
|
||||
self.window.get_widget("connection").set_sensitive(is_remote)
|
||||
self.window.get_widget("autoconnect").set_active(not is_remote)
|
||||
self.window.get_widget("username-entry").set_sensitive(is_remote)
|
||||
if is_remote and self.can_browse:
|
||||
self.start_browse()
|
||||
else:
|
||||
self.stop_browse()
|
||||
|
||||
self.populate_default_user()
|
||||
self.populate_uri()
|
||||
|
||||
def connection_changed(self, src):
|
||||
self.populate_default_user()
|
||||
self.populate_uri()
|
||||
|
||||
def populate_uri(self):
|
||||
uri = self.generate_uri()
|
||||
self.window.get_widget("uri-entry").set_text(uri)
|
||||
|
||||
def populate_default_user(self):
|
||||
conn = self.window.get_widget("connection").get_active()
|
||||
default_user = default_conn_user(conn)
|
||||
self.window.get_widget("username-entry").set_text(default_user)
|
||||
|
||||
def generate_uri(self):
|
||||
hv = self.window.get_widget("hypervisor").get_active()
|
||||
conn = self.window.get_widget("connection").get_active()
|
||||
host = self.window.get_widget("hostname").child.get_text()
|
||||
user = self.window.get_widget("username-entry").get_text()
|
||||
is_remote = self.is_remote()
|
||||
|
||||
user = "root"
|
||||
if conn == CONN_SSH and '@' in host:
|
||||
user, host = host.split('@',1)
|
||||
|
||||
hvstr = ""
|
||||
if hv == HV_XEN:
|
||||
hvstr = "xen"
|
||||
else:
|
||||
hvstr = "qemu"
|
||||
|
||||
addrstr = ""
|
||||
if user:
|
||||
addrstr += user + "@"
|
||||
addrstr += host
|
||||
|
||||
hoststr = ""
|
||||
if not is_remote:
|
||||
hoststr = ":///"
|
||||
elif conn == CONN_TLS:
|
||||
hoststr = "+tls://" + host + "/"
|
||||
elif conn == CONN_SSH:
|
||||
hoststr = "+ssh://" + user + "@" + host + "/"
|
||||
elif conn == CONN_TCP:
|
||||
hoststr = "+tcp://" + host + "/"
|
||||
else:
|
||||
if conn == CONN_TLS:
|
||||
hoststr = "+tls://"
|
||||
if conn == CONN_SSH:
|
||||
hoststr = "+ssh://"
|
||||
if conn == CONN_TCP:
|
||||
hoststr = "+tcp://"
|
||||
hoststr += addrstr + "/"
|
||||
|
||||
uri = hvstr + hoststr
|
||||
if hv == HV_QEMU:
|
||||
|
@ -18,7 +18,7 @@
|
||||
<widget class="GtkTable" id="table1">
|
||||
<property name="visible">True</property>
|
||||
<property name="border_width">6</property>
|
||||
<property name="n_rows">7</property>
|
||||
<property name="n_rows">8</property>
|
||||
<property name="n_columns">2</property>
|
||||
<property name="column_spacing">6</property>
|
||||
<property name="row_spacing">6</property>
|
||||
@ -80,8 +80,8 @@ SSL/TLS with certificates</property>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="top_attach">4</property>
|
||||
<property name="bottom_attach">5</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
@ -91,8 +91,8 @@ SSL/TLS with certificates</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">4</property>
|
||||
<property name="bottom_attach">5</property>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -102,8 +102,9 @@ SSL/TLS with certificates</property>
|
||||
<property name="label" translatable="yes">Generated URI:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="bottom_attach">8</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -115,8 +116,8 @@ SSL/TLS with certificates</property>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="bottom_attach">8</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -170,8 +171,8 @@ SSL/TLS with certificates</property>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="top_attach">4</property>
|
||||
<property name="bottom_attach">5</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
@ -180,13 +181,13 @@ SSL/TLS with certificates</property>
|
||||
<widget class="GtkLabel" id="label90">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">A_utoconnect:</property>
|
||||
<property name="label" translatable="yes">_Autoconnect:</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">autoconnect</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
@ -202,12 +203,49 @@ SSL/TLS with certificates</property>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment3">
|
||||
<property name="visible">True</property>
|
||||
<property name="left_padding">22</property>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.51999998092651367</property>
|
||||
<property name="ypad">2</property>
|
||||
<property name="label" translatable="yes">_Username:</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">username-entry</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="username-entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
<signal name="changed" handler="on_username_entry_changed"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
|
Loading…
x
Reference in New Issue
Block a user