"""
from mininet.node import Docker
from mininet.link import Link
+from emuvim.dcemulator.resourcemodel import NotEnoughResourcesAvailable
import logging
import time
import json
# apply resource limits to container if a resource model is defined
if self._resource_model is not None:
- self._resource_model.allocate(d)
- self._resource_model.write_allocation_log(d, self.resource_log_path)
+ try:
+ self._resource_model.allocate(d)
+ self._resource_model.write_allocation_log(d, self.resource_log_path)
+ except NotEnoughResourcesAvailable as ex:
+ LOG.warning("Allocation of container %r was blocked by resource model." % name)
+ LOG.info(ex.message)
+ # ensure that we remove the container
+ self.net.removeDocker(name)
+ return None
# connect all given networks
# if no --net option is given, network = [{}], so 1 empty dict in the list
:param action: allocate or free
:return:
"""
- pass
\ No newline at end of file
+ pass
+
+
+class NotEnoughResourcesAvailable(BaseException):
+ pass
import time
import json
import logging
-from emuvim.dcemulator.resourcemodel import BaseResourceModel
+from emuvim.dcemulator.resourcemodel import BaseResourceModel, NotEnoughResourcesAvailable
LOG = logging.getLogger("rm.upb.simple")
LOG.setLevel(logging.DEBUG)
fl_cu = self._get_flavor(d).get("compute")
# check for over provisioning
if self.dc_alloc_cu + fl_cu > self.dc_max_cu and self.raise_no_cpu_resources_left:
- raise Exception("Not enough compute resources left.")
+ raise NotEnoughResourcesAvailable("Not enough compute resources left.")
self.dc_alloc_cu += fl_cu
def _allocate_mem(self, d):
fl_mu = self._get_flavor(d).get("memory")
# check for over provisioning
if self.dc_alloc_mu + fl_mu > self.dc_max_mu and self.raise_no_mem_resources_left:
- raise Exception("Not enough memory resources left.")
+ raise NotEnoughResourcesAvailable("Not enough memory resources left.")
self.dc_alloc_mu += fl_mu
def free(self, d):
import time
import os
from emuvim.test.base import SimpleTestTopology
-from emuvim.dcemulator.resourcemodel import BaseResourceModel, ResourceFlavor
+from emuvim.dcemulator.resourcemodel import BaseResourceModel, ResourceFlavor, NotEnoughResourcesAvailable, ResourceModelRegistrar
from emuvim.dcemulator.resourcemodel.upb.simple import UpbSimpleCloudDcRM, UpbOverprovisioningCloudDcRM
-from emuvim.dcemulator.resourcemodel import ResourceModelRegistrar
+
class testResourceModel(SimpleTestTopology):
rm.allocate(c7) # calculate allocation
rm.allocate(c8) # calculate allocation
rm.allocate(c9) # calculate allocation
- except Exception as e:
+ except NotEnoughResourcesAvailable as e:
self.assertIn("Not enough compute", e.message)
exception = True
self.assertTrue(exception)
rm.allocate(c6) # calculate allocation
rm.allocate(c7) # calculate allocation
rm.allocate(c8) # calculate allocation
- except Exception as e:
+ except NotEnoughResourcesAvailable as e:
self.assertIn("Not enough memory", e.message)
exception = True
self.assertTrue(exception)