cpu resource control via rest api + unittest including ELAN test
diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py
index 731331b..3b4dd54 100755
--- a/src/emuvim/dcemulator/net.py
+++ b/src/emuvim/dcemulator/net.py
@@ -47,6 +47,9 @@
LOG = logging.getLogger("dcemulator.net")
LOG.setLevel(logging.DEBUG)
+# default CPU period used for cpu percentage-based cfs values (microseconds)
+CPU_PERIOD = 1000000
+
class DCNetwork(Containernet):
"""
Wraps the original Mininet/Containernet class and provides
@@ -56,7 +59,7 @@
"""
def __init__(self, controller=RemoteController, monitor=False,
- enable_learning=False, # learning switch behavior of the default ovs switches icw Ryu controller can be turned off/on, neede for E-LAN functionality
+ enable_learning=False, # learning switch behavior of the default ovs switches icw Ryu controller can be turned off/on, needed for E-LAN functionality
dc_emulation_max_cpu=1.0, # fraction of overall CPU time for emulation
dc_emulation_max_mem=512, # emulation max mem in MB
**kwargs):
@@ -121,6 +124,7 @@
# initialize resource model registrar
self.rm_registrar = ResourceModelRegistrar(
dc_emulation_max_cpu, dc_emulation_max_mem)
+ self.cpu_period = CPU_PERIOD
def addDatacenter(self, label, metadata={}, resource_log_path=None):
"""
diff --git a/src/emuvim/dcemulator/node.py b/src/emuvim/dcemulator/node.py
index 8219761..8e7a63a 100755
--- a/src/emuvim/dcemulator/node.py
+++ b/src/emuvim/dcemulator/node.py
@@ -38,7 +38,6 @@
DCDPID_BASE = 1000 # start of switch dpid's used for data center switches
-
class EmulatorCompute(Docker):
"""
Emulator specific compute node class.
@@ -148,7 +147,7 @@
def start(self):
pass
- def startCompute(self, name, image=None, command=None, network=None, flavor_name="tiny"):
+ def startCompute(self, name, image=None, command=None, network=None, flavor_name="tiny", **kwargs):
"""
Create a new container as compute resource and connect it to this
data center.
@@ -174,15 +173,28 @@
if len(network) < 1:
network.append({})
+ # apply hard-set resource limits=0
+ cpu_percentage = kwargs.get('cpu_percent')
+ if cpu_percentage:
+ cpu_period = self.net.cpu_period
+ cpu_quota = self.net.cpu_period * float(cpu_percentage)
+ else:
+ cpu_quota = None
+ cpu_period = None
+
# create the container
d = self.net.addDocker(
"%s" % (name),
dimage=image,
dcmd=command,
datacenter=self,
- flavor_name=flavor_name
+ flavor_name=flavor_name,
+ cpu_period = cpu_period,
+ cpu_quota = cpu_quota
)
+
+
# apply resource limits to container if a resource model is defined
if self._resource_model is not None:
try: