Skip to content

Commit

Permalink
More updates based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
kushaldas committed Nov 13, 2018
1 parent f22753f commit b7f5f7f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ansible_module/conns/qubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def __init__(self, play_context, new_stdin, *args, **kwargs):

self._remote_vmname = self._play_context.remote_addr
self._connected = False
self._hostname = subprocess.check_output(["hostname"]).decode("utf-8").strip()
# Default username in Qubes
self.user = "user"
if self._play_context.remote_user:
Expand Down Expand Up @@ -108,10 +107,8 @@ def _qubes(self, cmd=None, in_data=None, shell="qubes.VMShell"):
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

# Here we are writing the actual command to the remote bash
p.stdin.write(to_bytes("%s" % cmd, errors='surrogate_or_strict'))
p.stdin.write(to_bytes(cmd, errors='surrogate_or_strict'))
stdout, stderr = p.communicate(input=in_data)
stdout = to_bytes(stdout, errors='surrogate_or_strict')
stderr = to_bytes(stderr, errors='surrogate_or_strict')
return p.returncode, stdout, stderr

def _connect(self):
Expand Down Expand Up @@ -146,20 +143,20 @@ def put_file(self, in_path, out_path):
retcode, dummy, dummy = self._qubes('cat > "{0}"\n'.format(out_path), source_data)

if retcode != 0:
raise RuntimeError('Failed to write target file {0}'.format(out_path))
raise RuntimeError('Failed to put_file to {0}'.format(out_path))

def fetch_file(self, in_path, out_path):
"""Obtain file specified via 'in_path' from the container and place it at 'out_path' """
super(Connection, self).fetch_file(in_path, out_path)
display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self._remote_vmname)

# We are running in dom0
cmd_args_list = ["qvm-run", "--pass-io", self._remote_vmname, "'cat {0}'".format(in_path)]
cmd_args_list = ["qvm-run", "--pass-io", self._remote_vmname, "cat {0}".format(in_path)]
with open(out_path, "wb") as fobj:
p = subprocess.Popen(cmd_args_list, shell=False, stdout=fobj)
p.communicate()
if p.returncode != 0:
raise RuntimeError('Failed to write target file {0}'.format(out_path))
raise RuntimeError('Failed to fetch file to {0}'.format(out_path))

def close(self):
""" Closing the connection """
Expand Down

0 comments on commit b7f5f7f

Please sign in to comment.