Port the rest of the file to the 2.4/3 compatible syntax (#15873)

Since the modules can use a paramiko transport (ergo
python 2.4 syntax), we need to keep compat with 2.4 and python 3,
so we need to use the get_exception trick, even if the various juniper
libraries are not compatible with 2.4.
This commit is contained in:
Michael Scherer 2016-05-16 14:11:15 +02:00 committed by Brian Coca
parent a4f6fc0dc2
commit fae492324e

View file

@ -158,7 +158,8 @@ class Netconf(object):
self.config = Config(self.device) self.config = Config(self.device)
except Exception, exc: except Exception:
exc = get_exception()
self._fail('unable to connect to %s: %s' % (host, str(exc))) self._fail('unable to connect to %s: %s' % (host, str(exc)))
def run_commands(self, commands, **kwargs): def run_commands(self, commands, **kwargs):
@ -169,9 +170,11 @@ class Netconf(object):
try: try:
resp = self.device.cli(command=cmd, format=fmt) resp = self.device.cli(command=cmd, format=fmt)
response.append(resp) response.append(resp)
except (ValueError, RpcError), exc: except (ValueError, RpcError):
exc = get_exception()
self._fail('Unable to get cli output: %s' % str(exc)) self._fail('Unable to get cli output: %s' % str(exc))
except Exception, exc: except Exception:
exc = get_exception()
self._fail('Uncaught exception - please report: %s' % str(exc)) self._fail('Uncaught exception - please report: %s' % str(exc))
return response return response
@ -180,14 +183,16 @@ class Netconf(object):
try: try:
self.config.unlock() self.config.unlock()
self._locked = False self._locked = False
except UnlockError, exc: except UnlockError:
exc = get_exception()
self.module.log('unable to unlock config: {0}'.format(str(exc))) self.module.log('unable to unlock config: {0}'.format(str(exc)))
def lock_config(self): def lock_config(self):
try: try:
self.config.lock() self.config.lock()
self._locked = True self._locked = True
except LockError, exc: except LockError:
exc = get_exception()
self.module.log('unable to lock config: {0}'.format(str(exc))) self.module.log('unable to lock config: {0}'.format(str(exc)))
def check_config(self): def check_config(self):
@ -200,7 +205,8 @@ class Netconf(object):
if confirm and confirm > 0: if confirm and confirm > 0:
kwargs['confirm'] = confirm kwargs['confirm'] = confirm
return self.config.commit(**kwargs) return self.config.commit(**kwargs)
except CommitError, exc: except CommitError:
exc = get_exception()
msg = 'Unable to commit configuration: {0}'.format(str(exc)) msg = 'Unable to commit configuration: {0}'.format(str(exc))
self._fail(msg=msg) self._fail(msg=msg)
@ -215,7 +221,8 @@ class Netconf(object):
try: try:
self.config.load(candidate, format=format, merge=merge, self.config.load(candidate, format=format, merge=merge,
overwrite=overwrite) overwrite=overwrite)
except ConfigLoadError, exc: except ConfigLoadError:
exc = get_exception()
msg = 'Unable to load config: {0}'.format(str(exc)) msg = 'Unable to load config: {0}'.format(str(exc))
self._fail(msg=msg) self._fail(msg=msg)
@ -234,7 +241,8 @@ class Netconf(object):
try: try:
result = self.config.rollback(identifier) result = self.config.rollback(identifier)
except Exception, exc: except Exception:
exc = get_exception()
msg = 'Unable to rollback config: {0}'.format(str(exc)) msg = 'Unable to rollback config: {0}'.format(str(exc))
self._fail(msg=msg) self._fail(msg=msg)