Skip to content

Commit

Permalink
Merge pull request #19 from kushaldas/fetch_file_directly
Browse files Browse the repository at this point in the history
Fetches the file directly to the right path.
  • Loading branch information
kushaldas committed Oct 25, 2018
2 parents aaadc8d + c56007f commit 0c65623
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions ansible_module/conns/qubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,15 @@ def fetch_file(self, in_path, 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)

cmd = ""
# Find the actual filename
filename = os.path.basename(in_path)

# We are running in dom0
cmd_args_list = ["qvm-run", "--pass-io", self._remote_vmname, "'cat {0}'".format(in_path)]
p = subprocess.Popen(cmd_args_list, shell=False, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

stdout, stderr = p.communicate()
tmp_path = os.path.join(C.DEFAULT_LOCAL_TMP, filename)
with open(tmp_path, "wb") as fobj:
fobj.write(stdout)

# Now create the mv command to move to the right place
cmd = ["mv", tmp_path, out_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))

subprocess.check_call(cmd)

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

0 comments on commit 0c65623

Please sign in to comment.