def _rollback_on_failure(self, iface): ''' Called by the Timer in a new thread to cancel wrong network configuration and rollback to previous configuration. ''' conn = LibvirtConnection("qemu:///system").get() try: conn.changeRollback() if iface.isActive(): iface.destroy() iface.create() except libvirt.libvirtError as e: # In case the timeout thread is preempted, and confirm_change() is # called before our changeRollback(), we can just ignore the # VIR_ERR_OPERATION_INVALID error. if e.get_error_code() != libvirt.VIR_ERR_OPERATION_INVALID: raise
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: conn.changeRollback() raise OperationFailed('GINNET0004E', {'err': e.message})
def _rollback_on_failure(self, gateway): _, err, rc = run_command(['ip', 'route', 'del', 'default']) if rc and not ('No such process' in err): raise OperationFailed('GINNET0010E', {'reason': err}) if gateway: _, err, rc = run_command( ['ip', 'route', 'add', 'default', 'via', gateway]) if rc: raise OperationFailed('GINNET0011E', {'reason': err}) conn = LibvirtConnection("qemu:///system").get() try: conn.changeRollback() except libvirt.libvirtError as e: # In case the timeout thread is preempted, and confirm_change() is # called before our changeRollback(), we can just ignore the # VIR_ERR_OPERATION_INVALID error. if e.get_error_code() != libvirt.VIR_ERR_OPERATION_INVALID: raise
def _rollback_on_failure(self, gateway): _, err, rc = run_command(['ip', 'route', 'del', 'default']) if rc and not ('No such process' in err): raise OperationFailed('GINNET0010E', {'reason': err}) if gateway: _, err, rc = run_command(['ip', 'route', 'add', 'default', 'via', gateway]) if rc: raise OperationFailed('GINNET0011E', {'reason': err}) conn = LibvirtConnection("qemu:///system").get() try: conn.changeRollback() except libvirt.libvirtError as e: # In case the timeout thread is preempted, and confirm_change() is # called before our changeRollback(), we can just ignore the # VIR_ERR_OPERATION_INVALID error. if e.get_error_code() != libvirt.VIR_ERR_OPERATION_INVALID: raise