示例#1
0
 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
示例#2
0
 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
示例#3
0
 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})
示例#4
0
    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
示例#5
0
    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