From 7cd468a3d7dee7d6c92f69a0bb7061ae208ec727 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Mon, 19 Dec 2016 23:05:39 +0100 Subject: Reorganize source tree to use single autotools instance Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion --- src/scripts/vppctl | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 src/scripts/vppctl (limited to 'src/scripts/vppctl') diff --git a/src/scripts/vppctl b/src/scripts/vppctl new file mode 100755 index 00000000..4fdf03c7 --- /dev/null +++ b/src/scripts/vppctl @@ -0,0 +1,121 @@ +#! /usr/bin/python +''' +Copyright 2016 Intel Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' + +from cmd import Cmd +import os +import subprocess +import re +import sys +try: + import readline +except ImportError: + readline = None + +persishist = os.path.expanduser('~/.vpphistory') +persishist_size = 1000 +if not persishist: + os.mknod(persishist, stat.S_IFREG) + +class Vppctl(Cmd): + + def historyWrite(self): + if readline: + readline.set_history_length(persishist_size) + readline.write_history_file(persishist) + + def runVat(self, line): + input_prefix = "exec " + input_command = input_prefix + line + line_remove = '^load_one_plugin:' + s = '\n' + command = ['vpp_api_test'] + + if os.geteuid() != 0: + command = ['sudo', 'vpp_api_test'] + + vpp_process = subprocess.Popen(command, + stderr=subprocess.PIPE, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + stdout_value = vpp_process.communicate(input_command)[0] + + buffer_stdout = stdout_value.splitlines() + + buffer_stdout[:] = [b for b in buffer_stdout + if line_remove not in b] + + for i, num in enumerate(buffer_stdout): + buffer_stdout[i] = num.replace('vat# ','') + + stdout_value = s.join(buffer_stdout) + print stdout_value + + def do_help(self, line): + self.runVat("help") + + def default(self, line): + self.runVat(line) + + def do_exit(self, line): + self.historyWrite() + raise SystemExit + + def emptyline(self): + pass + + def do_EOF(self,line): + self.historyWrite() + sys.stdout.write('\n') + raise SystemExit + + def preloop(self): + if readline and os.path.exists(persishist): + readline.read_history_file(persishist) + + def postcmd(self, stop, line): + self.historyWrite() + +if __name__ == '__main__': + command_args = sys.argv + + + if not len(command_args) > 1: + prompt = Vppctl() + red_set = '\033[31m' + norm_set = '\033[0m' + if sys.stdout.isatty(): + prompt.prompt = 'vpp# ' + try: + prompt.cmdloop(red_set + " _______ _ " + norm_set + " _ _____ ___ \n" + + red_set + " __/ __/ _ \ (_)__ " + norm_set + " | | / / _ \/ _ \\\n" + + red_set + " _/ _// // / / / _ \\" + norm_set + " | |/ / ___/ ___/\n" + + red_set + " /_/ /____(_)_/\___/ " + norm_set + "|___/_/ /_/ \n") + except KeyboardInterrupt: + sys.stdout.write('\n') + else: + try: + prompt.cmdloop() + except KeyboardInterrupt: + sys.stdout.write('\n') + else: + del command_args[0] + stdout_value = " ".join(command_args) + VatAddress = Vppctl() + VatAddress.runVat(stdout_value) + + + -- cgit 1.2.3-korg From a2ac467b845ae8d7995770a5bb5ca706452923c1 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Mon, 23 Jan 2017 22:11:47 +0000 Subject: Add multi-vpp support back into pythonic vppctl Back when vppctl was a shell script, you could use -p or --prefix to set the chroot prefix to drive multiple vpp instances. This patch adds that capability back. Change-Id: Iaa70a20eff13e8d7e206fcceadb7e5d06afa3fc5 Signed-off-by: Ed Warnicke --- src/scripts/vppctl | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/scripts/vppctl') diff --git a/src/scripts/vppctl b/src/scripts/vppctl index 4fdf03c7..01369189 100755 --- a/src/scripts/vppctl +++ b/src/scripts/vppctl @@ -20,6 +20,8 @@ import os import subprocess import re import sys +from optparse import OptionParser + try: import readline except ImportError: @@ -32,6 +34,10 @@ if not persishist: class Vppctl(Cmd): + def __init__(self,api_prefix=None): + Cmd.__init__(self) + self.api_prefix = api_prefix + def historyWrite(self): if readline: readline.set_history_length(persishist_size) @@ -42,10 +48,13 @@ class Vppctl(Cmd): input_command = input_prefix + line line_remove = '^load_one_plugin:' s = '\n' - command = ['vpp_api_test'] + if ( self.api_prefix is None): + command = ['vpp_api_test'] + else: + command = ['vpp_api_test',"chroot prefix %s " % self.api_prefix] if os.geteuid() != 0: - command = ['sudo', 'vpp_api_test'] + command = ['sudo'] + command vpp_process = subprocess.Popen(command, stderr=subprocess.PIPE, @@ -90,15 +99,19 @@ class Vppctl(Cmd): self.historyWrite() if __name__ == '__main__': - command_args = sys.argv - + parser = OptionParser() + parser.add_option("-p","--prefix",action="store",type="string",dest="prefix") + (options,command_args) = parser.parse_args(sys.argv) if not len(command_args) > 1: - prompt = Vppctl() + prompt = Vppctl(options.prefix) red_set = '\033[31m' norm_set = '\033[0m' if sys.stdout.isatty(): - prompt.prompt = 'vpp# ' + if(options.prefix is None): + prompt.prompt = 'vpp# ' + else: + prompt.prompt = '%s# ' % options.prefix try: prompt.cmdloop(red_set + " _______ _ " + norm_set + " _ _____ ___ \n" + red_set + " __/ __/ _ \ (_)__ " + norm_set + " | | / / _ \/ _ \\\n" + @@ -114,7 +127,7 @@ if __name__ == '__main__': else: del command_args[0] stdout_value = " ".join(command_args) - VatAddress = Vppctl() + VatAddress = Vppctl(options.prefix) VatAddress.runVat(stdout_value) -- cgit 1.2.3-korg