summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Warnicke <hagbard@gmail.com>2017-01-23 22:11:47 +0000
committerDamjan Marion <dmarion.lists@gmail.com>2017-01-27 01:03:27 +0000
commita2ac467b845ae8d7995770a5bb5ca706452923c1 (patch)
tree1faf49bca5aba3ff231f70e86f219deac229d067
parent7ff11136b1a528bd3d9b0795fa0005b40c2b3b9f (diff)
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 <hagbard@gmail.com>
-rwxr-xr-xsrc/scripts/vppctl27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/scripts/vppctl b/src/scripts/vppctl
index 4fdf03c78ff..01369189503 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)
008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * 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.
 */

#ifndef included_clib_lock_h
#define included_clib_lock_h

#include <vppinfra/clib.h>

typedef struct
{
  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
  u32 lock;
#if CLIB_DEBUG > 0
  pid_t pid;
  uword thread_index;
  void *frame_address;
#endif
} *clib_spinlock_t;

static inline void
clib_spinlock_init (clib_spinlock_t * p)
{
  *p = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
  memset ((void *) *p, 0, CLIB_CACHE_LINE_BYTES);
}

static inline void
clib_spinlock_free (clib_spinlock_t * p)
{
  if (*p)
    {
      clib_mem_free ((void *) *p);
      *p = 0;
    }
}

static_always_inline void
clib_spinlock_lock (clib_spinlock_t * p)
{
  while (__sync_lock_test_and_set (&(*p)->lock, 1))
#if __x86_64__
    __builtin_ia32_pause ()
#endif
      ;
#if CLIB_DEBUG > 0
  (*p)->frame_address = __builtin_frame_address (0);
  (*p)->pid = getpid ();
  (*p)->thread_index = os_get_thread_index ();
#endif
}

static_always_inline void
clib_spinlock_lock_if_init (clib_spinlock_t * p)
{
  if (PREDICT_FALSE (*p != 0))
    clib_spinlock_lock (p);
}

static_always_inline void
clib_spinlock_unlock (clib_spinlock_t * p)
{
  (*p)->lock = 0;
#if CLIB_DEBUG > 0
  (*p)->frame_address = 0;
  (*p)->pid = 0;
  (*p)->thread_index = 0;
#endif
}

static_always_inline void
clib_spinlock_unlock_if_init (clib_spinlock_t * p)
{
  if (PREDICT_FALSE (*p != 0))
    clib_spinlock_unlock (p);
}

#endif

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */