'Defer apply context.'

@contextlib.contextmanager
def defer_apply(self):

    self.defer_apply_on()
    try:
        (yield)
    finally:
        try:
            self.defer_apply_off()
        except n_exc.IpTablesApplyException:
            raise
        except Exception:
            msg = _('Failure    applying    iptables    rules')
            LOG.exception(msg)
            raise n_exc.IpTablesApplyException(msg)
