Add autoconnect option for hypervisor connections.

This commit is contained in:
Cole Robinson 2008-03-24 11:39:19 -04:00
parent 4273563b3b
commit fd97ffbd4e
5 changed files with 106 additions and 2 deletions

View File

@ -311,7 +311,7 @@ class vmmConfig:
# the url isn't already in the list, so add it
uris.insert(len(uris) - 1,uri)
self.conf.set_list(self.conf_dir + "/connections/uris", gconf.VALUE_STRING, uris)
def remove_connection(self, uri):
uris = self.conf.get_list(self.conf_dir + "/connections/uris", gconf.VALUE_STRING)
if uris == None:
@ -319,6 +319,31 @@ class vmmConfig:
if uris.count(uri) != 0:
uris.remove(uri)
self.conf.set_list(self.conf_dir + "/connections/uris", gconf.VALUE_STRING, uris)
if self.get_conn_autoconnect(uri):
uris = self.conf.get_list(self.conf_dir + \
"/connections/autoconnect",\
gconf.VALUE_STRING)
uris.remove(uri)
self.conf.set_list(self.conf_dir + "/connections/autoconnect", \
gconf.VALUE_STRING, uris)
def get_conn_autoconnect(self, uri):
uris = self.conf.get_list(self.conf_dir + "/connections/autoconnect",\
gconf.VALUE_STRING)
return ((uris is not None) and (uri in uris))
def toggle_conn_autoconnect(self, uri):
uris = self.conf.get_list(self.conf_dir + "/connections/autoconnect",\
gconf.VALUE_STRING)
if uris is None:
uris = []
if uri in uris:
uris.remove(uri)
else:
uris.append(uri)
self.conf.set_list(self.conf_dir + "/connections/autoconnect", \
gconf.VALUE_STRING, uris)
def get_media_urls(self):
return self.conf.get_list(self.conf_dir + "/urls/media", gconf.VALUE_STRING)

View File

@ -142,6 +142,7 @@ class vmmConnection(gobject.GObject):
# Resource utilization statistics
self.record = []
self.hostinfo = None
self.autoconnect = self.config.get_conn_autoconnect(self.get_uri())
# Probe for network devices
try:
@ -504,6 +505,17 @@ class vmmConnection(gobject.GObject):
def get_max_vcpus(self, type=None):
return virtinst.util.get_max_vcpus(self.vmm, type)
def get_autoconnect(self):
# Use a local variable to cache autoconnect so we don't repeatedly
# have to poll gconf
return self.autoconnect
def toggle_autoconnect(self):
if self.is_remote():
return
self.config.toggle_conn_autoconnect(self.get_uri())
self.autoconnect = (not self.autoconnect)
def connect(self, name, callback):
handle_id = gobject.GObject.connect(self, name, callback)

View File

@ -70,6 +70,7 @@ class vmmEngine(gobject.GObject):
self.schedule_timer()
self.load_stored_uris()
self.autostart_connections()
self.tick()
def load_stored_uris(self):
@ -79,6 +80,12 @@ class vmmEngine(gobject.GObject):
for uri in uris:
self.add_connection(uri)
def autostart_connections(self):
for uri in self.connections:
conn = self.connections[uri]["connection"]
if conn.get_autoconnect():
self.connect_to_uri(uri)
def connect_to_uri(self, uri, readOnly=None):
return self._connect_to_uri(None, uri, readOnly)

View File

@ -54,6 +54,7 @@ class vmmHost(gobject.GObject):
self.window.get_widget("overview-memory").set_text(self.conn.pretty_host_memory_size())
self.window.get_widget("overview-cpus").set_text(str(self.conn.host_active_processor_count()))
self.window.get_widget("overview-arch").set_text(self.conn.host_architecture())
self.window.get_widget("config-autoconnect").set_active(conn.get_autoconnect())
netListModel = gtk.ListStore(str, str, str)
self.window.get_widget("net-list").set_model(netListModel)
@ -100,6 +101,7 @@ class vmmHost(gobject.GObject):
"on_net_delete_clicked": self.delete_network,
"on_net_stop_clicked": self.stop_network,
"on_net_start_clicked": self.start_network,
"on_config_autoconnect_toggled": self.toggle_autoconnect,
})
self.conn.connect("resources-sampled", self.refresh_resources)
@ -108,6 +110,8 @@ class vmmHost(gobject.GObject):
self.refresh_resources()
def show(self):
# Update autostart value
self.window.get_widget("config-autoconnect").set_active(self.conn.get_autoconnect())
dialog = self.window.get_widget("vmm-host")
dialog.present()
@ -140,6 +144,11 @@ class vmmHost(gobject.GObject):
self.add = vmmCreateNetwork(self.config, self.conn)
self.add.show()
def toggle_autoconnect(self, ignore=None):
if self.conn.get_autoconnect() != \
self.window.get_widget("config-autoconnect").get_active():
self.conn.toggle_autoconnect()
def show_help(self, src):
# From the Details window, show the help document from the Details page
self.emit("action-show-help", "virt-manager-host-window")

View File

@ -127,7 +127,7 @@
<widget class="GtkTable" id="table1">
<property name="border_width">3</property>
<property name="visible">True</property>
<property name="n_rows">6</property>
<property name="n_rows">7</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">3</property>
@ -463,6 +463,57 @@
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label72">
<property name="visible">True</property>
<property name="label" translatable="yes">Autoconnect:</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="config-autoconnect">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_config_autoconnect_toggled" last_modification_time="Mon, 24 Mar 2008 15:38:20 GMT"/>
</widget>
<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="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
</child>
</widget>