network: Add install() command, remove function from vmmConnection

This is the pattern used by other virtinst objects
This commit is contained in:
Cole Robinson 2013-09-30 15:06:52 -04:00
parent b9bcc84d35
commit 98a95b2e2d
3 changed files with 26 additions and 18 deletions

View File

@ -732,18 +732,6 @@ class vmmConnection(vmmGObject):
def define_interface(self, xml):
return self._backend.interfaceDefineXML(xml, 0)
def create_network(self, xml, start=True, autostart=True):
net = self.define_network(xml)
try:
if start:
net.create()
net.setAutostart(autostart)
except:
net.undefine()
raise
return net
def _rename_helper(self, objtype, define_cb, obj, origxml, newxml):
# Undefine the original object
obj.delete()

View File

@ -753,25 +753,22 @@ class vmmCreateNetwork(vmmGObjectUI):
self.conn.schedule_priority_tick(pollnet=True)
self.close()
def _async_net_create(self, asyncjob, xml):
def _async_net_create(self, asyncjob, net):
ignore = asyncjob
self.conn.create_network(xml)
net.install()
def finish(self, ignore):
try:
net = self._build_xmlobj()
xml = net.get_xml_config()
except Exception, e:
self.err.show_erro(_("Error generating network xml: %s" % str(e)))
return
logging.debug("Generated network XML:\n" + xml)
self.topwin.set_sensitive(False)
self.topwin.get_window().set_cursor(
Gdk.Cursor.new(Gdk.CursorType.WATCH))
progWin = vmmAsyncJob(self._async_net_create, [xml],
progWin = vmmAsyncJob(self._async_net_create, [net],
self._finish_cb, [],
_("Creating virtual network..."),
_("Creating the virtual network may take a "

View File

@ -20,6 +20,8 @@
Classes for building and installing libvirt <network> XML
"""
import logging
import libvirt
from virtinst import util
@ -179,3 +181,24 @@ class Network(XMLBuilder):
route = _NetworkRoute(self.conn)
self._add_child(route)
return route
##################
# build routines #
##################
def install(self, start=True, autostart=True):
xml = self.get_xml_config()
logging.debug("Creating virtual network '%s' with xml:\n%s",
self.name, xml)
net = self.conn.networkDefineXML(xml)
try:
if start:
net.create()
if autostart:
net.setAutostart(autostart)
except:
net.undefine()
raise
return net