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

Added support for template module for Dell Networking OS6 devices #17625

Merged
merged 1 commit into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Ansible Changes By Release
* dellos6_command
* dellos6_config
* dellos6_facts
* dellos6_template
- dellos9
* dellos9_command
* dellos9_config
Expand Down
99 changes: 92 additions & 7 deletions lib/ansible/module_utils/dellos6.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,101 @@

from ansible.module_utils.shell import CliBase
from ansible.module_utils.network import Command, register_transport, to_list
from ansible.module_utils.netcfg import NetworkConfig
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine, ignore_line, DEFAULT_COMMENT_TOKENS


def get_config(module):
contents = module.params['running_config']
contents = module.params['config']

if not contents:
contents = module.cli('show running-config all')[0]
module.params['running_config'] = contents
contents = module.config.get_config()
module.params['config'] = contents

return Dellos6NetworkConfig(indent=0, contents=contents[0])


def get_sublevel_config(running_config, module):
contents = list()
current_config_contents = list()
sublevel_config = Dellos6NetworkConfig(indent=0)

obj = running_config.get_object(module.params['parents'])
if obj:
contents = obj.children

for c in contents:
if isinstance(c, ConfigLine):
current_config_contents.append(c.raw)
sublevel_config.add(current_config_contents, module.params['parents'])

return sublevel_config


def os6_parse(lines, indent=None, comment_tokens=None):
sublevel_cmds = [
re.compile(r'^vlan.*$'),
re.compile(r'^stack.*$'),
re.compile(r'^interface.*$'),
re.compile(r'line [(console)|(telnet)|(ssh)].*$'),
re.compile(r'ip ssh !(server).*$'),
re.compile(r'ip address .*$'),
re.compile(r'ip access-list .*$'),
re.compile(r'banner motd.*$'),
re.compile(r'radius-server host auth.*$')]

childline = re.compile(r'^exit$')

config = list()
inSubLevel = False
parent = None
children = list()
subcommandcount = 0

return NetworkConfig(indent=1, contents=contents)
for line in str(lines).split('\n'):
text = str(re.sub(r'([{};])', '', line)).strip()

cfg = ConfigLine(text)
cfg.raw = line

if not text or ignore_line(text, comment_tokens):
parent = None
children = list()
inSubLevel = False
continue

if inSubLevel is False:
for pr in sublevel_cmds:
if pr.match(line):
parent = cfg
config.append(parent)
inSubLevel = True
continue
if parent is None:
config.append(cfg)

# handle sub level commands
elif inSubLevel and childline.match(line):
parent.children = children
inSubLevel = False
children = list()
parent = None

# handle top level commands
elif inSubLevel:
children.append(cfg)
cfg.parents = [parent]
config.append(cfg)

else: # global level
config.append(cfg)

return config


class Dellos6NetworkConfig(NetworkConfig):

def load(self, contents):
self._config = os6_parse(contents, self.indent, DEFAULT_COMMENT_TOKENS)


class Cli(CliBase):
Expand All @@ -60,8 +146,7 @@ class Cli(CliBase):
re.compile(r"(?:incomplete|ambiguous) command", re.I),
re.compile(r"connection timed out", re.I),
re.compile(r"[^\r\n]+ not found", re.I),
re.compile(r"'[^']' +returned error code: ?\d+"),
]
re.compile(r"'[^']' +returned error code: ?\d+")]


def connect(self, params, **kwargs):
Expand Down
28 changes: 28 additions & 0 deletions lib/ansible/plugins/action/dellos6_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.action import ActionBase
from ansible.plugins.action.net_template import ActionModule as NetActionModule

class ActionModule(NetActionModule, ActionBase):
pass