Fix backup issue in network config modules and network action plugins common code refactor (#50301)

* Fix backup issue in network config modules

*  Fix `get_working_path` not found issue introduced due to
   backup config code refactor (PR #50208)

*  Further refactor config related action plugins to minimize
   duplicate code

*  Remove unwated imports in config action plugins

* Add common network class for action plugin and related code refactor

* Fix review comment
This commit is contained in:
Ganesh Nalawade 2019-01-04 16:06:13 +05:30 committed by GitHub
commit 71113ee291
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 168 additions and 2347 deletions

View file

@ -19,22 +19,20 @@ __metaclass__ = type
import copy
import os
import time
import re
import uuid
import hashlib
from ansible.module_utils._text import to_text, to_bytes
from ansible.module_utils.connection import Connection
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase
from ansible.plugins.action.network import ActionModule as NetworkActionModule
from ansible.module_utils.six.moves.urllib.parse import urlsplit
from ansible.utils.display import Display
display = Display()
class ActionModule(ActionBase):
class ActionModule(NetworkActionModule):
def run(self, tmp=None, task_vars=None):
socket_path = None
@ -111,33 +109,12 @@ class ActionModule(ActionBase):
filename_list = re.split('/|:', src_path)
return filename_list[-1]
def _get_working_path(self):
cwd = self._loader.get_basedir()
if self._task._role is not None:
cwd = self._task._role._role_path
return cwd
def _get_default_dest(self, src_path):
dest_path = self._get_working_path()
src_fname = self._get_src_filename_from_path(src_path)
filename = '%s/%s' % (dest_path, src_fname)
return filename
def _get_network_os(self, task_vars):
if 'network_os' in self._task.args and self._task.args['network_os']:
display.vvvv('Getting network OS from task argument')
network_os = self._task.args['network_os']
elif self._play_context.network_os:
display.vvvv('Getting network OS from inventory')
network_os = self._play_context.network_os
elif 'network_os' in task_vars.get('ansible_facts', {}) and task_vars['ansible_facts']['network_os']:
display.vvvv('Getting network OS from fact')
network_os = task_vars['ansible_facts']['network_os']
else:
raise AnsibleError('ansible_network_os must be specified on this host to use platform agnostic modules')
return network_os
def _handle_existing_file(self, conn, source, dest, proto, timeout):
if not os.path.exists(dest):
return True