Maru Newby | b096d9f | 2015-03-09 18:54:54 +0000 | [diff] [blame^] | 1 | # All Rights Reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import shlex |
| 16 | import subprocess |
| 17 | |
| 18 | from neutron.openstack.common import log as logging |
| 19 | |
| 20 | LOG = logging.getLogger(__name__) |
| 21 | |
| 22 | |
| 23 | def copy_file_to_host(file_from, dest, host, username, pkey): |
| 24 | dest = "%s@%s:%s" % (username, host, dest) |
| 25 | cmd = "scp -v -o UserKnownHostsFile=/dev/null " \ |
| 26 | "-o StrictHostKeyChecking=no " \ |
| 27 | "-i %(pkey)s %(file1)s %(dest)s" % {'pkey': pkey, |
| 28 | 'file1': file_from, |
| 29 | 'dest': dest} |
| 30 | args = shlex.split(cmd.encode('utf-8')) |
| 31 | subprocess_args = {'stdout': subprocess.PIPE, |
| 32 | 'stderr': subprocess.STDOUT} |
| 33 | proc = subprocess.Popen(args, **subprocess_args) |
| 34 | stdout, stderr = proc.communicate() |
| 35 | if proc.returncode != 0: |
| 36 | LOG.error(("Command {0} returned with exit status {1}," |
| 37 | "output {2}, error {3}").format(cmd, proc.returncode, |
| 38 | stdout, stderr)) |
| 39 | return stdout |