X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=emuvim%2Fcli%2Fcompute.py;h=87247cb16886d36b1dd5c5c6c9ff590fe8172f20;hb=c5a536a1796846be97e5ba6ce9c20d73b6fd0052;hp=b75b0435601ba07ef6b74fbf998eeda2657b25d8;hpb=5831076971df3aeec3ecbd3d972557709ab27a4f;p=osm%2Fvim-emu.git diff --git a/emuvim/cli/compute.py b/emuvim/cli/compute.py old mode 100644 new mode 100755 index b75b043..87247cb --- a/emuvim/cli/compute.py +++ b/emuvim/cli/compute.py @@ -1,9 +1,11 @@ """ son-emu compute CLI +(c) 2016 by Manuel Peuster """ import argparse import pprint +from tabulate import tabulate import zerorpc @@ -14,7 +16,7 @@ class ZeroRpcClient(object): def __init__(self): self.c = zerorpc.Client() - self.c.connect("tcp://127.0.0.1:4242") # yes, hard coded for now. we'll change this later + self.c.connect("tcp://127.0.0.1:4242") # TODO hard coded for now. we'll change this later self.cmds = {} def execute_command(self, args): @@ -25,8 +27,14 @@ class ZeroRpcClient(object): print "Command not implemented." def start(self, args): + network = {} + if args.get("network") is not None: + network = {"ip": args.get("network")} r = self.c.compute_action_start( - args.get("datacenter"), args.get("name")) + args.get("datacenter"), + args.get("name"), + args.get("image"), + network) pp.pprint(r) def stop(self, args): @@ -35,19 +43,57 @@ class ZeroRpcClient(object): pp.pprint(r) def list(self, args): - print "TODO: Not implemented" + r = self.c.compute_list( + args.get("datacenter")) + table = [] + for c in r: + # for each container add a line to the output table + if len(c) > 1: + name = c[0] + status = c[1] + eth0ip = None + eth0status = "down" + if len(status.get("network")) > 0: + eth0ip = status.get("network")[0][1] + eth0status = "up" if status.get( + "network")[0][3] else "down" + table.append([status.get("datacenter"), + name, + status.get("image"), + eth0ip, + eth0status, + status.get("state").get("Status")]) + headers = ["Datacenter", + "Container", + "Image", + "eth0 IP", + "eth0 status", + "Status"] + print tabulate(table, headers=headers, tablefmt="grid") def status(self, args): - print "TODO: Not implemented" + r = self.c.compute_status( + args.get("datacenter"), args.get("name")) + pp.pprint(r) parser = argparse.ArgumentParser(description='son-emu compute') -parser.add_argument("command", help="Action to be executed.") parser.add_argument( - "--datacenter", "-d", dest="datacenter", help="Data center.") + "command", + choices=['start', 'stop', 'list', 'status'], + help="Action to be executed.") +parser.add_argument( + "--datacenter", "-d", dest="datacenter", + help="Data center to in which the compute instance should be executed") +parser.add_argument( + "--name", "-n", dest="name", + help="Name of compute instance e.g. 'vnf1'") +parser.add_argument( + "--image", dest="image", + help="Name of container image to be used e.g. 'ubuntu'") parser.add_argument( - "--name", "-n", dest="name", help="Compute name.") -# TODO: IP, image, etc. pp. + "--net", dest="network", + help="Network properties of compute instance e.g. '10.0.0.123/8'") def main(argv):