mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 14:01:42 -07:00
Move connection plugins to using global display
This commit is contained in:
parent
318bfbb207
commit
aa4f213cb5
11 changed files with 192 additions and 131 deletions
|
@ -32,6 +32,12 @@ from ansible import constants as C
|
|||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.connection import ConnectionBase
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
display = display
|
||||
except ImportError:
|
||||
from ansible.utils.display import Display
|
||||
display = Display()
|
||||
|
||||
BUFSIZE = 65536
|
||||
|
||||
|
@ -59,7 +65,7 @@ class Connection(ConnectionBase):
|
|||
self.zoneadm_cmd = self._search_executable('zoneadm')
|
||||
self.zlogin_cmd = self._search_executable('zlogin')
|
||||
|
||||
if not self.zone in self.list_zones():
|
||||
if self.zone not in self.list_zones():
|
||||
raise AnsibleError("incorrect zone name %s" % self.zone)
|
||||
|
||||
@staticmethod
|
||||
|
@ -76,15 +82,15 @@ class Connection(ConnectionBase):
|
|||
|
||||
zones = []
|
||||
for l in process.stdout.readlines():
|
||||
# 1:work:running:/zones/work:3126dc59-9a07-4829-cde9-a816e4c5040e:native:shared
|
||||
s = l.split(':')
|
||||
if s[1] != 'global':
|
||||
zones.append(s[1])
|
||||
# 1:work:running:/zones/work:3126dc59-9a07-4829-cde9-a816e4c5040e:native:shared
|
||||
s = l.split(':')
|
||||
if s[1] != 'global':
|
||||
zones.append(s[1])
|
||||
|
||||
return zones
|
||||
|
||||
def get_zone_path(self):
|
||||
#solaris10vm# zoneadm -z cswbuild list -p
|
||||
#solaris10vm# zoneadm -z cswbuild list -p
|
||||
#-:cswbuild:installed:/zones/cswbuild:479f3c4b-d0c6-e97b-cd04-fd58f2c0238e:native:shared
|
||||
process = subprocess.Popen([self.zoneadm_cmd, '-z', self.zone, 'list', '-p'],
|
||||
stdin=subprocess.PIPE,
|
||||
|
@ -98,7 +104,7 @@ class Connection(ConnectionBase):
|
|||
''' connect to the zone; nothing to do here '''
|
||||
super(Connection, self)._connect()
|
||||
if not self._connected:
|
||||
self._display.vvv("THIS IS A LOCAL ZONE DIR", host=self.zone)
|
||||
display.vvv("THIS IS A LOCAL ZONE DIR", host=self.zone)
|
||||
self._connected = True
|
||||
|
||||
def _buffered_exec_command(self, cmd, stdin=subprocess.PIPE):
|
||||
|
@ -113,11 +119,11 @@ class Connection(ConnectionBase):
|
|||
# -c. Not sure why as cmd could contain shell metachars (like
|
||||
# cmd = "mkdir -p $HOME/pathname && echo $HOME/pathname") which
|
||||
# probably wouldn't work without a shell. Get someone to test that
|
||||
# this connection plugin works and then we can remove this note
|
||||
# this connection plugin works and then we can remove this note
|
||||
executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh'
|
||||
local_cmd = [self.zlogin_cmd, self.zone, executable, '-c', cmd]
|
||||
|
||||
self._display.vvv("EXEC %s" % (local_cmd), host=self.zone)
|
||||
display.vvv("EXEC %s" % (local_cmd), host=self.zone)
|
||||
p = subprocess.Popen(local_cmd, shell=False, stdin=stdin,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
|
@ -156,7 +162,7 @@ class Connection(ConnectionBase):
|
|||
def put_file(self, in_path, out_path):
|
||||
''' transfer a file from local to zone '''
|
||||
super(Connection, self).put_file(in_path, out_path)
|
||||
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.zone)
|
||||
display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.zone)
|
||||
|
||||
out_path = pipes.quote(self._prefix_login_path(out_path))
|
||||
try:
|
||||
|
@ -178,7 +184,7 @@ class Connection(ConnectionBase):
|
|||
def fetch_file(self, in_path, out_path):
|
||||
''' fetch a file from zone to local '''
|
||||
super(Connection, self).fetch_file(in_path, out_path)
|
||||
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.zone)
|
||||
display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.zone)
|
||||
|
||||
in_path = pipes.quote(self._prefix_login_path(in_path))
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue