Example #1
0
 def do_addflow(self, arg, forced=False):
     """
     addflow [bridge] flow
     Add a flow to a bridge.
     """
     args = arg.replace('"', '').replace("'", "").split()
     if len(args) < 2:
         output('Not enough parameters are given, use like ')
         output('br-int addflow priority=3 ip actions=OUTPUT:1\n')
         return
     bridge, flow_str = args[0], ' '.join(args[1:])
     if not br_exists(bridge):
         if self.bridge:
             bridge, flow_str = self.bridge, ' '.join(args)
         else:
             output('Please give a valid bridge.\n')
             return
     flow = fmt_flow_str(flow_str)
     if not flow:
         output('Please give a valid flow.\n')
         return
     if not br_addflow(bridge, flow):
         output('Add flow <%s> to %s failed.\n' % (flow, bridge))
     else:
         output('Add flow <%s> to %s done.\n' % (flow, bridge))
Example #2
0
 def do_addflow(self, arg, forced=False):
     """
     addflow [bridge] flow
     Add a flow to a bridge.
     """
     args = arg.replace('"', '').replace("'", "").split()
     if len(args) < 2:
         output('Not enough parameters are given, use like ')
         output('br-int addflow priority=3 ip actions=OUTPUT:1\n')
         return
     bridge, flow_str = args[0], ' '.join(args[1:])
     if not br_exists(bridge):
         if self.bridge:
             bridge, flow_str = self.bridge, ' '.join(args)
         else:
             output('Please give a valid bridge.\n')
             return
     flow = fmt_flow_str(flow_str)
     if not flow:
         output('Please give a valid flow.\n')
         return
     if not br_addflow(bridge, flow):
         output('Add flow <%s> to %s failed.\n' % (flow, bridge))
     else:
         output('Add flow <%s> to %s done.\n' % (flow, bridge))
Example #3
0
 def do_set(self, arg):
     """
     <bridge> set
     Set the default bridge
     """
     if not arg:
         output("Argument is missed\n")
     elif not br_exists(arg):
         output("The bridge does not exist.\n You can check available bridges using show\n")
     else:
         self.prompt = color_str("g", PROMPT_KW[:-2] + ":%s> " % color_str("b", arg))
         self.bridge = arg
         output("Set the default bridge to %s.\n" % self.bridge)
Example #4
0
 def do_set(self, arg):
     """
     <bridge> set
     Set the default bridge
     """
     if not arg:
         output('Argument is missed\n')
     elif not br_exists(arg):
         output('The bridge does not exist.\n You can check available bridges using show\n')
     else:
         self.prompt = color_str('g', PROMPT_KW[:-2] + ':%s> ' % color_str('b', arg))
         self.bridge = arg
         output('Set the default bridge to %s.\n' % self.bridge)
Example #5
0
 def do_set(self, arg):
     """
     <bridge> set
     Set the default bridge
     """
     if not arg:
         output('Argument is missed\n')
     elif not br_exists(arg):
         output('The bridge does not exist.\n You can check available bridges using show\n')
     else:
         self.prompt = color_str('g', PROMPT_KW[:-2] + ':%s> ' % color_str('b', arg))
         self.bridge = arg
         output('Set the default bridge to %s.\n' % self.bridge)
Example #6
0
 def do_addflow(self, arg):
     """
     addflow [bridge] flow
     Add a flow to a bridge.
     """
     args = arg.replace('"', "").replace("'", "").split()
     bridge, flow_str = args[0], " ".join(args[1:])
     if not br_exists(bridge) and self.bridge:
         bridge, flow_str = self.bridge, " ".join(args)
     else:
         output("Please give a valid bridge.\n")
         return
     flow = fmt_flow_str(flow_str)
     if not flow:
         output("Please give a valid flow.\n")
         return
     if not br_addflow(bridge, flow):
         output("Add flow <%s> to %s failed.\n" % (flow, bridge))
     else:
         output("Add flow <%s> to %s done.\n" % (flow, bridge))
Example #7
0
 def default(self, line):
     # bridge, cmd, line = self.parseline( line )
     if len(line.split()) < 2:
         error("*** Unknown command: %s ***\n" % line)
         return
     bridge, cmd, args = "", "", ""
     if len(line.split()) == 2:
         bridge, cmd = line.split()
     else:
         bridge, cmd, args = line.split()[0], line.split()[1], " ".join(line.split()[2:])
     if br_exists(bridge):
         try:
             if args:
                 getattr(self, "do_%s" % cmd)(" ".join([bridge, args]))
             else:
                 getattr(self, "do_%s" % cmd)(bridge)
         except AttributeError:
             error("*** Unknown command: %s, cmd=%s, bridge=%s, args=%s ***\n" % (line, cmd, bridge, args))
     else:
         error("*** Bridge %s is not existed\n" % bridge)
Example #8
0
 def do_addflow(self, arg):
     """
     addflow [bridge] flow
     Add a flow to a bridge.
     """
     args = arg.replace('"', '').replace("'", "").split()
     bridge, flow_str = args[0], ' '.join(args[1:])
     if not br_exists(bridge) and self.bridge:
         bridge, flow_str = self.bridge, ' '.join(args)
     else:
         output('Please give a valid bridge.\n')
         return
     flow = fmt_flow_str(flow_str)
     if not flow:
         output('Please give a valid flow.\n')
         return
     if not br_addflow(bridge, flow):
         output('Add flow <%s> to %s failed.\n' % (flow, bridge))
     else:
         output('Add flow <%s> to %s done.\n' % (flow, bridge))
Example #9
0
 def default(self, line):
     #bridge, cmd, line = self.parseline( line )
     if len(line.split()) < 2:
         error('*** Unknown command: %s ***\n' % line)
         return
     bridge, cmd, args = '', '', ''
     if len(line.split()) == 2:
         bridge, cmd = line.split()
     else:
         bridge, cmd, args = line.split()[0], line.split()[1], ' '.join(line.split()[2:])
     if br_exists(bridge):
         try:
             if args:
                 getattr(self, 'do_%s' % cmd)(' '.join([bridge, args]))
             else:
                 getattr(self, 'do_%s' % cmd)(bridge)
         except AttributeError:
             error('*** Unknown command: %s, cmd=%s, bridge=%s, args=%s ***\n' % (line, cmd, bridge, args))
     else:
         error('*** Bridge %s is not existed\n' % bridge)
Example #10
0
 def default(self, line):
     #bridge, cmd, line = self.parseline( line )
     if len(line.split()) < 2:
         error('*** Unknown command: %s ***\n' % line)
         return
     bridge, cmd, args = '', '', ''
     if len(line.split()) == 2:
         bridge, cmd = line.split()
     else:
         bridge, cmd, args = \
             line.split()[0], line.split()[1], ' '.join(line.split()[2:])
     if br_exists(bridge):
         try:
             if args:
                 getattr(self, 'do_%s' % cmd)(' '.join([bridge, args]))
             else:
                 getattr(self, 'do_%s' % cmd)(bridge)
         except AttributeError:
             error('*** Unknown command: '
                   '%s, cmd=%s, bridge=%s, args=%s '
                   '***\n' % (line, cmd, bridge, args))
     else:
         error('*** Bridge %s is not existed\n' % bridge)