Added support template module for Dell Networking OS6 devices

This commit is contained in:
Senthil Kumar Ganesan 2016-09-17 10:55:40 -07:00
parent e07b854505
commit 463349c0d1
3 changed files with 122 additions and 8 deletions

View file

@ -70,6 +70,7 @@ Ansible Changes By Release
* dellos6_command
* dellos6_config
* dellos6_facts
* dellos6_template
- dellos9
* dellos9_command
* dellos9_config

View file

@ -33,15 +33,101 @@ import re
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']
if not contents:
contents = module.cli('show running-config all')[0]
module.params['running_config'] = contents
contents = module.params['config']
return NetworkConfig(indent=1, contents=contents)
if not 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
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):
@ -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):

View file

@ -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