From 4ed8306099d4561ecb9e706ed54d2d2e5f087478 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 31 Aug 2016 15:03:18 -0400 Subject: [PATCH] add Ssh transport class to openswitch shared module This adds a Ssh transport class for working directly with DC config on OpenSwitch enabled nodes. --- lib/ansible/module_utils/openswitch.py | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/openswitch.py b/lib/ansible/module_utils/openswitch.py index adc2fec57af..25209f42920 100644 --- a/lib/ansible/module_utils/openswitch.py +++ b/lib/ansible/module_utils/openswitch.py @@ -57,6 +57,7 @@ def get_opsidl(): return (extschema, opsidl) + class Response(object): def __init__(self, resp, hdrs): @@ -76,6 +77,7 @@ class Response(object): return None class Rest(object): + def __init__(self): self.url = None self.url_args = ModuleStub(url_argument_spec(), self._error) @@ -229,4 +231,27 @@ class Cli(CliBase): def save_config(self): self.execute(['copy running-config startup-config']) -Cli = register_transport('cli', default=True)(Cli) +Cli = register_transport('cli')(Cli) + +class Ssh(object): + + def __init__(self): + if not HAS_OPS: + msg = 'ops.dc lib is required but does not appear to be available' + raise NetworkError(msg) + self._opsidl = None + + def configure(self, config): + if not self._opsidl: + (self._extschema, self._opsidl) = get_opsidl() + return ops.dc.write(self._extschema, self._opsidl) + + def get_config(self): + if not self._opsidl: + (self._extschema, self._opsidl) = get_opsidl() + return ops.dc.read(self._extschema, self._opsidl) + + def load_config(self, config): + return self.configure(config) + +Ssh = register_transport('ssh', default=True)(Ssh)