def _create_libvirt_network_iface(self, iface_xml): conn = LibvirtConnection("qemu:///system").get() # Only one active transaction is allowed in the system level. # It implies that we can use changeBegin() as a synchronized point. conn.changeBegin() try: iface = conn.interfaceDefineXML(iface_xml) self._rollback_timer = Timer( self._confirm_timout, self._rollback_on_failure, args=[iface]) if iface.isActive(): iface.destroy() iface.create() self._rollback_timer.start() except Exception as e: self._rollback_on_failure(iface) raise OperationFailed('GINNET0004E', {'err': e.message})
def _create_libvirt_network_iface(self, iface_xml): conn = LibvirtConnection("qemu:///system").get() # Only one active transaction is allowed in the system level. # It implies that we can use changeBegin() as a synchronized point. conn.changeBegin() try: iface = conn.interfaceDefineXML(iface_xml) self._rollback_timer = Timer(self._confirm_timout, self._rollback_on_failure, args=[iface]) if iface.isActive(): iface.destroy() iface.create() self._rollback_timer.start() except Exception as e: self._rollback_on_failure(iface) raise OperationFailed('GINNET0004E', {'err': e.message})
def _save_gateway_changes(self, old_iface, old_gateway): def save_config(conn, iface, gateway=None): n = IPv4Network(get_dev_netaddr(iface)) net_params = {'ipaddr': str(n.ip), 'netmask': str(n.netmask)} if gateway: net_params['gateway'] = gateway iface_xml = InterfaceModel()._create_iface_xml(iface, net_params) iface = conn.interfaceDefineXML(iface_xml) route = self._get_default_route_entry() gateway = route.gateway new_iface = route.dev conn = LibvirtConnection("qemu:///system").get() conn.changeBegin() save_config(conn, new_iface, gateway) if old_iface and new_iface != old_iface: save_config(conn, old_iface) self._rollback_timer = Timer(self._confirm_timeout, self._rollback_on_failure, args=[old_gateway]) self._rollback_timer.start()
def _save_gateway_changes(self, old_iface, old_gateway): def save_config(conn, iface, gateway=None): n = IPv4Network(get_dev_netaddr(iface)) net_params = {'ipaddr': str(n.ip), 'netmask': str(n.netmask)} if gateway: net_params['gateway'] = gateway iface_xml = InterfaceModel()._create_iface_xml(iface, net_params) iface = conn.interfaceDefineXML(iface_xml) route = self._get_default_route_entry() gateway = route.gateway new_iface = route.dev conn = LibvirtConnection("qemu:///system").get() conn.changeBegin() save_config(conn, new_iface, gateway) if old_iface and new_iface != old_iface: save_config(conn, old_iface) self._rollback_timer = Timer( self._confirm_timeout, self._rollback_on_failure, args=[old_gateway]) self._rollback_timer.start()