mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 14:41:23 -07:00
Fix funcd to at least import without errors. (#16288)
This plugin was using very old api, so was updated to newer api. Also misc style/pep8 cleanups.
This commit is contained in:
parent
20ef8d5aaf
commit
36bf1e6b7e
1 changed files with 14 additions and 9 deletions
|
@ -24,19 +24,24 @@
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
HAVE_FUNC=False
|
HAVE_FUNC = False
|
||||||
try:
|
try:
|
||||||
import func.overlord.client as fc
|
import func.overlord.client as fc
|
||||||
HAVE_FUNC=True
|
HAVE_FUNC = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from ansible.callbacks import vvv
|
|
||||||
from ansible import errors
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleError
|
||||||
|
|
||||||
|
try:
|
||||||
|
from __main__ import display
|
||||||
|
except ImportError:
|
||||||
|
from ansible.utils.display import Display
|
||||||
|
display = Display()
|
||||||
|
|
||||||
class Connection(object):
|
class Connection(object):
|
||||||
''' Func-based connections '''
|
''' Func-based connections '''
|
||||||
|
@ -50,7 +55,7 @@ class Connection(object):
|
||||||
|
|
||||||
def connect(self, port=None):
|
def connect(self, port=None):
|
||||||
if not HAVE_FUNC:
|
if not HAVE_FUNC:
|
||||||
raise errors.AnsibleError("func is not installed")
|
raise AnsibleError("func is not installed")
|
||||||
|
|
||||||
self.client = fc.Client(self.host)
|
self.client = fc.Client(self.host)
|
||||||
return self
|
return self
|
||||||
|
@ -60,10 +65,10 @@ class Connection(object):
|
||||||
''' run a command on the remote minion '''
|
''' run a command on the remote minion '''
|
||||||
|
|
||||||
if in_data:
|
if in_data:
|
||||||
raise errors.AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
||||||
|
|
||||||
# totally ignores privlege escalation
|
# totally ignores privlege escalation
|
||||||
vvv("EXEC %s" % (cmd), host=self.host)
|
display.vvv("EXEC %s" % (cmd), host=self.host)
|
||||||
p = self.client.command.run(cmd)[self.host]
|
p = self.client.command.run(cmd)[self.host]
|
||||||
return (p[0], p[1], p[2])
|
return (p[0], p[1], p[2])
|
||||||
|
|
||||||
|
@ -77,14 +82,14 @@ class Connection(object):
|
||||||
''' transfer a file from local to remote '''
|
''' transfer a file from local to remote '''
|
||||||
|
|
||||||
out_path = self._normalize_path(out_path, '/')
|
out_path = self._normalize_path(out_path, '/')
|
||||||
vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
||||||
self.client.local.copyfile.send(in_path, out_path)
|
self.client.local.copyfile.send(in_path, out_path)
|
||||||
|
|
||||||
def fetch_file(self, in_path, out_path):
|
def fetch_file(self, in_path, out_path):
|
||||||
''' fetch a file from remote to local '''
|
''' fetch a file from remote to local '''
|
||||||
|
|
||||||
in_path = self._normalize_path(in_path, '/')
|
in_path = self._normalize_path(in_path, '/')
|
||||||
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
||||||
# need to use a tmp dir due to difference of semantic for getfile
|
# need to use a tmp dir due to difference of semantic for getfile
|
||||||
# ( who take a # directory as destination) and fetch_file, who
|
# ( who take a # directory as destination) and fetch_file, who
|
||||||
# take a file directly
|
# take a file directly
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue