### 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
* 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
+++ /dev/null
-"""
- 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()
--- /dev/null
+"""
+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)
--- /dev/null
+"""
+son-emu network CLI
+"""
+
+
+def main(argv):
+ print "This is the son-emu network CLI."
+ print "Arguments: %s" % str(argv)
--- /dev/null
+#!/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()
"""
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
# 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):