added a first, early prototype of the emulator CLI
authorpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 12 Jan 2016 16:09:20 +0000 (17:09 +0100)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 12 Jan 2016 16:09:20 +0000 (17:09 +0100)
README.md
emuvim/cli/__main__.py [deleted file]
emuvim/cli/compute.py [new file with mode: 0644]
emuvim/cli/network.py [new file with mode: 0644]
emuvim/cli/son-emu-cli [new file with mode: 0755]
emuvim/dcemulator/net.py

index 873a936..92c3655 100644 (file)
--- a/README.md
+++ b/README.md
 
 ### TODO
 * DCemulator
 
 ### TODO
 * DCemulator
- * correctly start and connect new compute resources at runtime
- * remove and disconnect compute resources at runtime
- * do IP management for new containers
- * list active compute resources
+ * ...
 * Cloud-like reference API with CLI for demonstrations
  * Write CLI client
  * Start compute
 * Cloud-like reference API with CLI for demonstrations
  * Write CLI client
  * Start compute
@@ -50,3 +47,8 @@
 * Define API endpoints in topology
  * call startAPI from topology definition and start it in a own thread
  * make it possible to start different API endpoints for different DCs
 * Define API endpoints in topology
  * call startAPI from topology definition and start it in a own thread
  * make it possible to start different API endpoints for different DCs
+* DCemulator
+ * correctly start and connect new compute resources at runtime
+ * remove and disconnect compute resources at runtime
+ * do IP management for new containers
+ * list active compute resources
diff --git a/emuvim/cli/__main__.py b/emuvim/cli/__main__.py
deleted file mode 100644 (file)
index 756ff89..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-"""
- For now only a dummy client. Connects to the zerorpc interface of the
- emulator and performs some actions (start/stop/list).
-
- We will provide a full CLI here later on which looks like:
-
- cli compute start dc1 my_name flavor_a
- cli network create dc1 11.0.0.0/24
-"""
-import time
-import pprint
-import zerorpc
-
-
-def main():
-    pp = pprint.PrettyPrinter(indent=4)
-    print "Example CLI client"
-    # create connection to remote Mininet instance
-    c = zerorpc.Client()
-    c.connect("tcp://127.0.0.1:4242")
-
-    # do some API tests
-    print c.compute_action_start("dc2", "d1")
-    print c.compute_action_start("dc2", "d2")
-
-    time.sleep(1)
-    print c.compute_list("dc2")
-
-    time.sleep(1)
-    pp.pprint(c.compute_status("dc2", "d1"))
-    pp.pprint(c.compute_status("dc2", "d2"))
-
-    time.sleep(5)
-
-    print c.compute_action_stop("dc2", "d1")
-    print c.compute_action_stop("dc2", "d2")
-
-
-if __name__ == '__main__':
-    main()
diff --git a/emuvim/cli/compute.py b/emuvim/cli/compute.py
new file mode 100644 (file)
index 0000000..b75b043
--- /dev/null
@@ -0,0 +1,56 @@
+"""
+son-emu compute CLI
+"""
+
+import argparse
+import pprint
+import zerorpc
+
+
+pp = pprint.PrettyPrinter(indent=4)
+
+
+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.cmds = {}
+
+    def execute_command(self, args):
+        if getattr(self, args["command"]) is not None:
+            # call the local method with the same name as the command arg
+            getattr(self, args["command"])(args)
+        else:
+            print "Command not implemented."
+
+    def start(self, args):
+        r = self.c.compute_action_start(
+            args.get("datacenter"), args.get("name"))
+        pp.pprint(r)
+
+    def stop(self, args):
+        r = self.c.compute_action_stop(
+            args.get("datacenter"), args.get("name"))
+        pp.pprint(r)
+
+    def list(self, args):
+        print "TODO: Not implemented"
+
+    def status(self, args):
+        print "TODO: Not implemented"
+
+
+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.")
+parser.add_argument(
+    "--name", "-n", dest="name", help="Compute name.")
+# TODO: IP, image, etc. pp.
+
+
+def main(argv):
+    args = vars(parser.parse_args(argv))
+    c = ZeroRpcClient()
+    c.execute_command(args)
diff --git a/emuvim/cli/network.py b/emuvim/cli/network.py
new file mode 100644 (file)
index 0000000..0c50dda
--- /dev/null
@@ -0,0 +1,8 @@
+"""
+son-emu network CLI
+"""
+
+
+def main(argv):
+    print "This is the son-emu network CLI."
+    print "Arguments: %s" % str(argv)
diff --git a/emuvim/cli/son-emu-cli b/emuvim/cli/son-emu-cli
new file mode 100755 (executable)
index 0000000..57ae053
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+"""
+ Simple CLI client to interact with a running emulator.
+
+ The CLI offers different tools, e.g., compute, network, ...
+ Each of these tools is implemented as an independent Python
+ module.
+
+ cli compute start dc1 my_name flavor_a
+ cli network create dc1 11.0.0.0/24
+"""
+
+import sys
+import compute
+import network
+
+
+def main():
+    if len(sys.argv) < 2:
+        print "Usage: son-emu-cli <toolname> <arguments>"
+        exit(0)
+    if sys.argv[1] == "compute":
+        compute.main(sys.argv[2:])
+    elif sys.argv[1] == "network":
+        network.main(sys.argv[2:])
+
+if __name__ == '__main__':
+    main()
index f5e58d1..1762e0b 100644 (file)
@@ -4,7 +4,7 @@ Distributed Cloud Emulator (dcemulator)
 """
 import logging
 
 """
 import logging
 
-from mininet.net import Mininet
+from mininet.net import Dockernet
 from mininet.node import Controller, OVSKernelSwitch, Switch, Docker, Host
 from mininet.cli import CLI
 from mininet.log import setLogLevel, info
 from mininet.node import Controller, OVSKernelSwitch, Switch, Docker, Host
 from mininet.cli import CLI
 from mininet.log import setLogLevel, info
@@ -28,7 +28,7 @@ class DCNetwork(object):
 
         # create a Mininet/Dockernet network
         setLogLevel('info')  # set Mininet loglevel
 
         # create a Mininet/Dockernet network
         setLogLevel('info')  # set Mininet loglevel
-        self.mnet = Mininet(controller=Controller, switch=OVSKernelSwitch)
+        self.mnet = Dockernet(controller=Controller, switch=OVSKernelSwitch)
         self.mnet.addController('c0')
 
     def addDatacenter(self, name):
         self.mnet.addController('c0')
 
     def addDatacenter(self, name):