minor cleanup, pushed ipv6 fixing to init
pushed up using host short var made close conditional, started implementing close for controlmaster
This commit is contained in:
parent
ca89467e37
commit
97bc92d2df
1 changed files with 23 additions and 24 deletions
|
@ -46,6 +46,9 @@ class Connection(ConnectionBase):
|
||||||
self.HASHED_KEY_MAGIC = "|1|"
|
self.HASHED_KEY_MAGIC = "|1|"
|
||||||
self._has_pipelining = True
|
self._has_pipelining = True
|
||||||
|
|
||||||
|
# FIXME: make this work, should be set from connection info
|
||||||
|
self._ipv6 = False
|
||||||
|
|
||||||
# FIXME: move the lockfile locations to ActionBase?
|
# FIXME: move the lockfile locations to ActionBase?
|
||||||
#fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_EX)
|
#fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_EX)
|
||||||
#self.cp_dir = utils.prepare_writeable_dir('$HOME/.ansible/cp',mode=0700)
|
#self.cp_dir = utils.prepare_writeable_dir('$HOME/.ansible/cp',mode=0700)
|
||||||
|
@ -275,6 +278,8 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
super(Connection, self).exec_command(cmd, tmp_path, executable=executable, in_data=in_data)
|
super(Connection, self).exec_command(cmd, tmp_path, executable=executable, in_data=in_data)
|
||||||
|
|
||||||
|
host = self._connection_info.remote_addr
|
||||||
|
|
||||||
ssh_cmd = self._password_cmd()
|
ssh_cmd = self._password_cmd()
|
||||||
ssh_cmd += ("ssh", "-C")
|
ssh_cmd += ("ssh", "-C")
|
||||||
if not in_data:
|
if not in_data:
|
||||||
|
@ -288,16 +293,14 @@ class Connection(ConnectionBase):
|
||||||
ssh_cmd.append("-q")
|
ssh_cmd.append("-q")
|
||||||
ssh_cmd += self._common_args
|
ssh_cmd += self._common_args
|
||||||
|
|
||||||
# FIXME: ipv6 stuff needs to be figured out. It's in the connection info, however
|
if self._ipv6:
|
||||||
# not sure if it's all working yet so this remains commented out
|
ssh_cmd += ['-6']
|
||||||
#if self._ipv6:
|
ssh_cmd.append(host)
|
||||||
# ssh_cmd += ['-6']
|
|
||||||
ssh_cmd.append(self._connection_info.remote_addr)
|
|
||||||
|
|
||||||
ssh_cmd.append(cmd)
|
ssh_cmd.append(cmd)
|
||||||
self._display.vvv("EXEC {0}".format(' '.join(ssh_cmd)), host=self._connection_info.remote_addr)
|
self._display.vvv("EXEC {0}".format(' '.join(ssh_cmd)), host=host)
|
||||||
|
|
||||||
not_in_host_file = self.not_in_host_file(self._connection_info.remote_addr)
|
not_in_host_file = self.not_in_host_file(host)
|
||||||
|
|
||||||
# FIXME: move the locations of these lock files, same as init above
|
# FIXME: move the locations of these lock files, same as init above
|
||||||
#if C.HOST_KEY_CHECKING and not_in_host_file:
|
#if C.HOST_KEY_CHECKING and not_in_host_file:
|
||||||
|
@ -400,17 +403,14 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
# FIXME: make a function, used in all 3 methods EXEC/PUT/FETCH
|
# FIXME: make a function, used in all 3 methods EXEC/PUT/FETCH
|
||||||
host = self._connection_info.remote_addr
|
host = self._connection_info.remote_addr
|
||||||
|
if self._ipv6:
|
||||||
|
host = '[%s]' % host
|
||||||
|
|
||||||
self._display.vvv("PUT {0} TO {1}".format(in_path, out_path), host=host)
|
self._display.vvv("PUT {0} TO {1}".format(in_path, out_path), host=host)
|
||||||
if not os.path.exists(in_path):
|
if not os.path.exists(in_path):
|
||||||
raise AnsibleFileNotFound("file or module does not exist: {0}".format(in_path))
|
raise AnsibleFileNotFound("file or module does not exist: {0}".format(in_path))
|
||||||
cmd = self._password_cmd()
|
cmd = self._password_cmd()
|
||||||
|
|
||||||
# FIXME: ipv6 stuff needs to be figured out. It's in the connection info, however
|
|
||||||
# not sure if it's all working yet so this remains commented out
|
|
||||||
#if self._ipv6:
|
|
||||||
# host = '[%s]' % host
|
|
||||||
|
|
||||||
if C.DEFAULT_SCP_IF_SSH:
|
if C.DEFAULT_SCP_IF_SSH:
|
||||||
cmd.append('scp')
|
cmd.append('scp')
|
||||||
cmd.extend(self._common_args)
|
cmd.extend(self._common_args)
|
||||||
|
@ -438,16 +438,13 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
# FIXME: make a function, used in all 3 methods EXEC/PUT/FETCH
|
# FIXME: make a function, used in all 3 methods EXEC/PUT/FETCH
|
||||||
host = self._connection_info.remote_addr
|
host = self._connection_info.remote_addr
|
||||||
|
if self._ipv6:
|
||||||
|
host = '[%s]' % host
|
||||||
|
|
||||||
self._display.vvv("FETCH {0} TO {1}".format(in_path, out_path), host=host)
|
self._display.vvv("FETCH {0} TO {1}".format(in_path, out_path), host=host)
|
||||||
cmd = self._password_cmd()
|
cmd = self._password_cmd()
|
||||||
|
|
||||||
|
|
||||||
# FIXME: ipv6 stuff needs to be figured out. It's in the connection info, however
|
|
||||||
# not sure if it's all working yet so this remains commented out
|
|
||||||
#if self._ipv6:
|
|
||||||
# host = '[%s]' % self._connection_info.remote_addr
|
|
||||||
|
|
||||||
if C.DEFAULT_SCP_IF_SSH:
|
if C.DEFAULT_SCP_IF_SSH:
|
||||||
cmd.append('scp')
|
cmd.append('scp')
|
||||||
cmd.extend(self._common_args)
|
cmd.extend(self._common_args)
|
||||||
|
@ -469,13 +466,15 @@ class Connection(ConnectionBase):
|
||||||
def close(self):
|
def close(self):
|
||||||
''' not applicable since we're executing openssh binaries '''
|
''' not applicable since we're executing openssh binaries '''
|
||||||
|
|
||||||
if 'ControlMaster' in self._common_args:
|
if self._connected:
|
||||||
cmd = ['ssh','-O','stop']
|
|
||||||
cmd.extend(self._common_args)
|
|
||||||
cmd.append(self._connection_info.remote_addr)
|
|
||||||
|
|
||||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
if 'ControlMaster' in self._common_args:
|
||||||
stdout, stderr = p.communicate()
|
cmd = ['ssh','-O','stop']
|
||||||
|
cmd.extend(self._common_args)
|
||||||
|
cmd.append(self._connection_info.remote_addr)
|
||||||
|
|
||||||
self._connected = False
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
|
||||||
|
self._connected = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue