Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull Config object out of network and into netcfg #17150

Merged
merged 1 commit into from
Aug 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 36 additions & 1 deletion lib/ansible/module_utils/netcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,46 @@
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):
Expand Down