Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
| 3 | # Copyright (C) 2015-2017, The University of Memphis, |
| 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
| 6 | # |
| 7 | # This file is part of Mini-NDN. |
| 8 | # See AUTHORS.md for a complete list of Mini-NDN authors and contributors. |
| 9 | # |
| 10 | # Mini-NDN is free software: you can redistribute it and/or modify |
| 11 | # it under the terms of the GNU General Public License as published by |
| 12 | # the Free Software Foundation, either version 3 of the License, or |
| 13 | # (at your option) any later version. |
| 14 | # |
| 15 | # Mini-NDN is distributed in the hope that it will be useful, |
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | # GNU General Public License for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU General Public License |
| 21 | # along with Mini-NDN, e.g., in COPYING.md file. |
| 22 | # If not, see <http://www.gnu.org/licenses/>. |
| 23 | |
| 24 | from subprocess import call |
Ashlesh Gawande | 95789cc | 2017-02-27 12:38:04 -0600 | [diff] [blame] | 25 | from mininet.cli import CLI |
| 26 | import sys |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame] | 27 | from os.path import isfile |
Ashlesh Gawande | f5f304b | 2016-06-16 16:42:41 -0500 | [diff] [blame] | 28 | |
| 29 | sshbase = [ 'ssh', '-q', '-t', '-i/home/mininet/.ssh/id_rsa' ] |
| 30 | scpbase = [ 'scp', '-i', '/home/mininet/.ssh/id_rsa' ] |
| 31 | devnull = open('/dev/null', 'w') |
| 32 | |
| 33 | def ssh(login, cmd): |
| 34 | rcmd = sshbase + [login, cmd] |
| 35 | call(rcmd, stdout=devnull, stderr=devnull) |
| 36 | |
| 37 | def scp(*args): |
| 38 | tmp = [] |
| 39 | for arg in args: |
| 40 | tmp.append(arg) |
| 41 | rcmd = scpbase + tmp |
| 42 | call(rcmd, stdout=devnull, stderr=devnull) |
Ashlesh Gawande | 95789cc | 2017-02-27 12:38:04 -0600 | [diff] [blame] | 43 | |
Alexander Lane | 4fa8881 | 2018-05-23 12:56:52 -0500 | [diff] [blame] | 44 | def copyExistentFile(node, fileList, destination): |
| 45 | for file in fileList: |
| 46 | if isfile(file): |
| 47 | node.cmd("cp {} {}".format(file, destination)) |
| 48 | break |
| 49 | if not isfile(destination): |
| 50 | fileName = destination.split("/")[-1] |
| 51 | raise IOError("{} not found in expected directory.".format(fileName)) |
| 52 | |
| 53 | |
Ashlesh Gawande | 95789cc | 2017-02-27 12:38:04 -0600 | [diff] [blame] | 54 | class MiniNDNCLI(CLI): |
| 55 | prompt = 'mini-ndn> ' |
| 56 | def __init__(self, mininet, stdin=sys.stdin, script=None): |
| 57 | CLI.__init__(self, mininet, stdin=sys.stdin, script=None) |