blob: f132e8627a8e32be9fd6d4420b928c108f8a0a16 [file] [log] [blame]
Maru Newbyb096d9f2015-03-09 18:54:54 +00001# 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
15import shlex
16import subprocess
17
18from neutron.openstack.common import log as logging
19
20LOG = logging.getLogger(__name__)
21
22
23def 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