| stevenvanrossem | c5a536a | 2016-02-16 14:52:39 +0100 | [diff] [blame] | 1 | """
|
| 2 | son-emu network CLI
|
| 3 | (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
|
| 4 | """
|
| 5 |
|
| 6 | import argparse
|
| 7 | import pprint
|
| 8 | from tabulate import tabulate
|
| 9 | import zerorpc
|
| 10 |
|
| 11 |
|
| 12 | pp = pprint.PrettyPrinter(indent=4)
|
| 13 |
|
| 14 | class ZeroRpcClient(object):
|
| 15 |
|
| 16 | def __init__(self):
|
| 17 | self.c = zerorpc.Client()
|
| 18 | # TODO connect to DCNetwork API
|
| 19 | #self.c.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later
|
| 20 | self.c.connect("tcp://127.0.0.1:5151")
|
| 21 | self.cmds = {}
|
| 22 |
|
| 23 | def execute_command(self, args):
|
| 24 | if getattr(self, args["command"]) is not None:
|
| 25 | # call the local method with the same name as the command arg
|
| 26 | getattr(self, args["command"])(args)
|
| 27 | else:
|
| 28 | print "Command not implemented."
|
| 29 |
|
| 30 | def add(self, args):
|
| 31 | r = self.c.network_action_start(
|
| 32 | #args.get("datacenter"),
|
| 33 | args.get("source"),
|
| 34 | args.get("destination"))
|
| 35 | pp.pprint(r)
|
| 36 |
|
| 37 | def remove(self, args):
|
| 38 | r = self.c.network_action_stop(
|
| 39 | #args.get("datacenter"),
|
| 40 | args.get("source"),
|
| 41 | args.get("destination"))
|
| 42 | pp.pprint(r)
|
| 43 |
|
| 44 |
|
| 45 | parser = argparse.ArgumentParser(description='son-emu network')
|
| 46 | parser.add_argument(
|
| 47 | "command",
|
| 48 | help="Action to be executed: add|remove")
|
| 49 | parser.add_argument(
|
| 50 | "--datacenter", "-d", dest="datacenter",
|
| 51 | help="Data center to in which the network action should be initiated")
|
| 52 | parser.add_argument(
|
| 53 | "--source", "-src", dest="source",
|
| 54 | help="vnf name of the source of the chain")
|
| 55 | parser.add_argument(
|
| 56 | "--destination", "-dst", dest="destination",
|
| 57 | help="vnf name of the destination of the chain")
|
| 58 |
|
| 59 | def main(argv):
|
| stevenvanrossem | c5a536a | 2016-02-16 14:52:39 +0100 | [diff] [blame] | 60 | args = vars(parser.parse_args(argv))
|
| 61 | c = ZeroRpcClient()
|
| 62 | c.execute_command(args)
|