# allocate in resource resource model and compute resource limits for new container
if self._resource_model is not None:
- # TODO pass resource limits to new container (cf. Dockernet API)
- cpu_limit, mem_limit, disk_limit = self._resource_model.allocate(name, flavor_name)
+ # TODO pass resource limits to new container (cf. Dockernet API) Issue #47
+ (cpu_limit, mem_limit, disk_limit) = alloc = self._resource_model.allocate(name, flavor_name)
+ logging.info("Allocation result: %r" % str(alloc))
# create the container
d = self.net.addDocker(
"%s" % (name),
if dc in self._resource_models:
raise Exception("There is already an resource model assigned to this DC.")
self._resource_models[dc] = rm
+ rm.registrar = self
LOG.info("Registrar: Added resource model: %r" % rm)
+ @property
+ def num_models(self):
+ return len(self._resource_models)
+
+ @property
+ def resource_models(self):
+ return list(self._resource_models.itervalues())
-class ResourceFlavor(object):
+class ResourceFlavor(object):
+ """
+ Simple class that represents resource flavors (c.f. OpenStack).
+ Can contain arbitrary metrics.
+ """
def __init__(self, name, metrics):
self.name = name
- self.metrics = metrics
+ self._metrics = metrics
LOG.debug("Create flavor %r with metrics: %r" % (name, metrics))
+ def get(self, metric_key):
+ return self._metrics.get(metric_key)
+
class BaseResourceModel(object):
+ """
+ Base class for a resource limitation model.
+ Has to be extended by a real resource model implementtion.
+ """
def __init__(self):
self._flavors=dict()
self._initDefaultFlavors()
+ self.registrar = None # pointer to registrar
LOG.info("Resource model %r initialized" % self)
def __repr__(self):
"xlarge", {"compute": 32, "memory": 1024, "disk": 160}))
def addFlavour(self, fl):
+ """
+ Add a new flavor to the resource model.
+ :param fl: flavor object
+ :return: None
+ """
if fl.name in self._flavors:
raise Exception("Flavor with name %r already exists!" % fl.name)
self._flavors[fl.name] = fl
def allocate(self, name, flavor_name):
- LOG.info("RM-ALLOCATE: %r with flavor: %r" % (name, flavor_name))
- return 0.0, 0.0, 0.0
+ """
+ This method has to be overwritten by a real resource model.
+ :param name: Name of the started compute instance.
+ :param flavor_name: Name of the flavor to be allocated.
+ :return: 3-tuple: (CPU-fraction, Mem-limit, Disk-limit)
+ """
+ LOG.warning("Allocating in BaseResourceModel: %r with flavor: %r" % (name, flavor_name))
+ return -1.0, -1.0, -1.0 # return invalid values to indicate that this RM is a dummy
def free(self, name):
- LOG.info("RM-FREE: %r" % name)
-
+ """
+ This method has to be overwritten by a real resource model.
+ :param name: Name of the compute instance that is stopped.
+ :return: True/False
+ """
+ LOG.warning("Free in BaseResourceModel: %r" % name)
+ return True
--- /dev/null
+"""
+Playground for resource models created by University of Paderborn.
+"""
+import logging
+from emuvim.dcemulator.resourcemodel import BaseResourceModel
+
+LOG = logging.getLogger("rm.upb.simple")
+LOG.setLevel(logging.DEBUG)
+
+
+class UpbSimpleCloudDcApproxRM(BaseResourceModel):
+ """
+ This will be an example resource model that limits the overall
+ resources that can be deployed per data center.
+ """
+ # TODO Implement resource model issue #12
+
+ def __init__(self, max_cu=32, max_mu=1024):
+ self._max_cu = max_cu
+ self._max_mu = max_mu
+ super(self.__class__, self).__init__()
+
from emuvim.dcemulator.net import DCNetwork
from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint
from emuvim.api.sonata import SonataDummyGatekeeperEndpoint
-from emuvim.dcemulator.resourcemodel.upbrm import UpbSimpleCloudDcApproxRM
+from emuvim.dcemulator.resourcemodel.upb.simple import UpbSimpleCloudDcApproxRM
logging.basicConfig(level=logging.INFO)
net.addLink(dc2, s1, delay="20ms")
# create and assign resource models for each DC
- rm1 = UpbSimpleCloudDcApproxRM()
- rm2 = UpbSimpleCloudDcApproxRM()
+ rm1 = UpbSimpleCloudDcApproxRM(max_cu=10, max_mu=1024)
+ rm2 = UpbSimpleCloudDcApproxRM(max_cu=20)
dc1.assignResourceModel(rm1)
dc2.assignResourceModel(rm2)