summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <psprygada@ansible.com>2016-09-04 08:27:49 -0400
committerPeter Sprygada <psprygada@ansible.com>2016-09-04 08:31:40 -0400
commit7aa1220b96be22b23b220147420695e338db0fc3 (patch)
tree2ccfae23f623a5ba1c5f4c308553ece10c911ba6
parent0c59cc1bcb8899d2434247ad80fd6d83fb199215 (diff)
downloadansible-7aa1220b96be22b23b220147420695e338db0fc3.tar.gz
fix up asa shared module
* add authorize() method to handle authorization * move terminal commands to after authorization completed * add save_config() method to handling writing config to disk * fix minor issues with get_config * adds action plugin asa_config
-rw-r--r--lib/ansible/module_utils/asa.py36
-rw-r--r--lib/ansible/plugins/action/asa_config.py28
2 files changed, 53 insertions, 11 deletions
diff --git a/lib/ansible/module_utils/asa.py b/lib/ansible/module_utils/asa.py
index a0b0d19f8b..e24f3181e8 100644
--- a/lib/ansible/module_utils/asa.py
+++ b/lib/ansible/module_utils/asa.py
@@ -29,11 +29,10 @@
import re
+from ansible.module_utils.network import NetworkModule, NetworkError
from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.shell import CliBase
-
-# temporary fix until modules are update. to be removed before 2.2 final
-from ansible.module_utils.network import get_module
+from ansible.module_utils.netcli import Command
add_argument('show_command', dict(default='show running-config', choices=['show running-config', 'more system:running-config']))
add_argument('context', dict(required=False))
@@ -64,11 +63,20 @@ class Cli(CliBase):
def connect(self, params, **kwargs):
super(Cli, self).connect(params, kickstart=False, **kwargs)
- self.execute('no terminal pager')
if params['context']:
self.change_context(params, **kwargs)
+ def authorize(self, params, **kwargs):
+ passwd = params['auth_pass']
+ cmd = Command('enable', prompt=self.NET_PASSWD_RE, response=passwd)
+ self.execute([cmd, 'no terminal pager'])
+
+ ### Cli methods ###
+
+ def run_commands(self, commands):
+ return self.execute(to_list(commands))
+
def change_context(self, params, **kwargs):
context = params['context']
if context == 'system':
@@ -83,15 +91,21 @@ class Cli(CliBase):
def configure(self, commands):
cmds = ['configure terminal']
cmds.extend(to_list(commands))
+ if cmds[-1] != 'end':
+ cmds.append('end')
responses = self.execute(cmds)
return responses[1:]
- def get_config(self, params, **kwargs):
- if self.filter:
- cmd = 'show running-config %s ' % self.filter
- else:
- cmd = params['show_command']
- if params.get('include_defaults'):
+ def get_config(self, include_defaults=False, **kwargs):
+ cmd = 'show running-config'
+ if include_defaults:
cmd += ' all'
- return self.execute(cmd)
+ return self.run_commands(cmd)[0]
+
+ def load_config(self, commands, **kwargs):
+ return self.configure(commands)
+
+ def save_config(self):
+ self.execute(['write memory'])
+
Cli = register_transport('cli', default=True)(Cli)
diff --git a/lib/ansible/plugins/action/asa_config.py b/lib/ansible/plugins/action/asa_config.py
new file mode 100644
index 0000000000..ffcb0f057f
--- /dev/null
+++ b/lib/ansible/plugins/action/asa_config.py
@@ -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_config import ActionModule as NetActionModule
+
+class ActionModule(NetActionModule, ActionBase):
+ pass
+
+