diff options
author | Peter Sprygada <psprygada@ansible.com> | 2016-08-19 10:42:55 -0400 |
---|---|---|
committer | Peter Sprygada <psprygada@ansible.com> | 2016-08-19 11:15:01 -0400 |
commit | 112f14866a8a7e98bcbce6cad88cd28cbef541e7 (patch) | |
tree | 5a183c09ecf472bbe8e611d4d87e812309eb61cf | |
parent | a0a2e1509e828df867d197dd441696ca82e6bfe5 (diff) | |
download | ansible-112f14866a8a7e98bcbce6cad88cd28cbef541e7.tar.gz |
pull Config object out of network and into netcfg
This moves the Config class from network and into netcfg module with
no added features. This is simply a reorganization of code.
-rw-r--r-- | lib/ansible/module_utils/netcfg.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/ansible/module_utils/netcfg.py b/lib/ansible/module_utils/netcfg.py index 298f2b89e5..49de624e51 100644 --- a/lib/ansible/module_utils/netcfg.py +++ b/lib/ansible/module_utils/netcfg.py @@ -33,11 +33,46 @@ import shlex import itertools from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE -from ansible.module_utils.network import to_list DEFAULT_COMMENT_TOKENS = ['#', '!', '/*', '*/'] +def to_list(val): + if isinstance(val, (list, tuple)): + return list(val) + elif val is not None: + return [val] + else: + return list() + +class Config(object): + + def __init__(self, connection): + self.connection = connection + + def invoke(self, method, *args, **kwargs): + try: + return method(*args, **kwargs) + except AttributeError: + exc = get_exception() + raise NetworkError('undefined method "%s"' % method.__name__, exc=str(exc)) + except NotImplementedError: + raise NetworkError('method not supported "%s"' % method.__name__) + + def __call__(self, commands): + lines = to_list(commands) + return self.invoke(self.connection.configure, commands) + + def load_config(self, commands, **kwargs): + commands = to_list(commands) + return self.invoke(self.connection.load_config, commands, **kwargs) + + def get_config(self, **kwargs): + return self.invoke(self.connection.get_config, **kwargs) + + def save_config(self): + return self.invoke(self.connection.save_config) + class ConfigLine(object): def __init__(self, text): |