added status and list commands to cli
authorpeusterm <manuel.peuster@uni-paderborn.de>
Wed, 13 Jan 2016 10:17:53 +0000 (11:17 +0100)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Wed, 13 Jan 2016 10:17:53 +0000 (11:17 +0100)
emuvim/api/zerorpcapi.py
emuvim/cli/compute.py
emuvim/cli/network.py
emuvim/cli/son-emu-cli
emuvim/dcemulator/node.py

index 28519c6..ecf822c 100644 (file)
@@ -76,8 +76,17 @@ class MultiDatacenterApi(object):
     def compute_list(self, dc_name):
         logging.info("RPC CALL: compute list")
         try:
     def compute_list(self, dc_name):
         logging.info("RPC CALL: compute list")
         try:
-            return [(c.name, c.IP())
-                    for c in self.dcs.get(dc_name).listCompute()]
+            if dc_name is None:
+                # return list with all compute nodes in all DCs
+                all_containers = []
+                for dc in self.dcs.itervalues():
+                    all_containers += dc.listCompute()
+                return [(c.name, c.getStatus())
+                        for c in all_containers]
+            else:
+                # return list of compute nodes for specified DC
+                return [(c.name, c.getStatus())
+                        for c in self.dcs.get(dc_name).listCompute()]
         except Exception as ex:
             logging.exception("RPC error.")
             return ex.message
         except Exception as ex:
             logging.exception("RPC error.")
             return ex.message
index b75b043..c5f2231 100644 (file)
@@ -1,9 +1,11 @@
 """
 son-emu compute CLI
 """
 son-emu compute CLI
+(c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
 """
 
 import argparse
 import pprint
 """
 
 import argparse
 import pprint
+from tabulate import tabulate
 import zerorpc
 
 
 import zerorpc
 
 
@@ -14,7 +16,7 @@ class ZeroRpcClient(object):
 
     def __init__(self):
         self.c = zerorpc.Client()
 
     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):
         self.cmds = {}
 
     def execute_command(self, args):
@@ -35,10 +37,38 @@ class ZeroRpcClient(object):
         pp.pprint(r)
 
     def list(self, args):
         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):
 
     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 = argparse.ArgumentParser(description='son-emu compute')
index 0c50dda..080b0ac 100644 (file)
@@ -1,5 +1,6 @@
 """
 son-emu network CLI
 """
 son-emu network CLI
+(c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
 """
 
 
 """
 
 
index 57ae053..56fe58b 100755 (executable)
@@ -2,6 +2,8 @@
 """
  Simple CLI client to interact with a running emulator.
 
 """
  Simple CLI client to interact with a running emulator.
 
+ (c) 2016 by Manuel Peuster <manuel.peuster@upb.de>
+
  The CLI offers different tools, e.g., compute, network, ...
  Each of these tools is implemented as an independent Python
  module.
  The CLI offers different tools, e.g., compute, network, ...
  Each of these tools is implemented as an independent Python
  module.
index 87a5a6e..def1e2d 100644 (file)
@@ -21,6 +21,7 @@ class EmulatorCompute(Docker):
     def __init__(
             self, name, dimage, **kwargs):
         logging.debug("Create EmulatorCompute instance: %s" % name)
     def __init__(
             self, name, dimage, **kwargs):
         logging.debug("Create EmulatorCompute instance: %s" % name)
+        self.datacenter = None  # pointer to current DC
 
         # call original Docker.__init__
         Docker.__init__(self, name, dimage, **kwargs)
 
         # call original Docker.__init__
         Docker.__init__(self, name, dimage, **kwargs)
@@ -50,6 +51,8 @@ class EmulatorCompute(Docker):
         status["memswap_limit"] = self.memswap_limit
         status["state"] = self.dcli.inspect_container(self.dc)["State"]
         status["id"] = self.dcli.inspect_container(self.dc)["Id"]
         status["memswap_limit"] = self.memswap_limit
         status["state"] = self.dcli.inspect_container(self.dc)["State"]
         status["id"] = self.dcli.inspect_container(self.dc)["Id"]
+        status["datacenter"] = (None if self.datacenter is None
+                                else self.datacenter.name)
         return status
 
 
         return status
 
 
@@ -104,7 +107,9 @@ class Datacenter(object):
         # create the container and connect it to the given network
         d = self.net.addDocker("%s" % (name), dimage=image)
         self.net.addLink(d, self.switch, params1=network)
         # create the container and connect it to the given network
         d = self.net.addDocker("%s" % (name), dimage=image)
         self.net.addLink(d, self.switch, params1=network)
+        # do bookkeeping
         self.containers[name] = d
         self.containers[name] = d
+        d.datacenter = self
         return name  # we might use UUIDs for naming later on
 
     def stopCompute(self, name):
         return name  # we might use UUIDs for naming later on
 
     def stopCompute(self, name):