From 3be4baa7e19133f0c41188bb1c2ee6ae3a82d470 Mon Sep 17 00:00:00 2001 From: Marco Capitani Date: Thu, 12 Apr 2018 11:54:47 +0200 Subject: model & irati: add QOS cubes Fixes #45 Only implemented in IRATI, other prototypes warn and ignore. --- rumba/elements/topology.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'rumba/elements') diff --git a/rumba/elements/topology.py b/rumba/elements/topology.py index 24dcfa2..0ff1957 100644 --- a/rumba/elements/topology.py +++ b/rumba/elements/topology.py @@ -212,6 +212,8 @@ class NormalDIF(DIF): if policy is None: policy = Policy(self) self.policy = policy + self.qos_cubes = [] + self._last_cube_id = 0 def add_policy(self, comp, pol, **params): """ @@ -243,6 +245,43 @@ class NormalDIF(DIF): % (comp, pol, params) return s + def add_qos_cube(self, name, **kwargs): + """ + Adds a QoS Cube to this DIF + + :param name: the name to be assigned to the QoS cube + :type name: `str` + :param kwargs: the parameters of the QoS cube (prototype dependent) + """ + self.del_qos_cube(name, strict=False) + c_id = self._last_cube_id + 1 + self._last_cube_id = c_id + kwargs["name"] = name + kwargs["cube_id"] = c_id + self.qos_cubes.append(kwargs) + + def del_qos_cube(self, name, strict=True): + """ + Deletes a QoS cube from this DIF + + :param name: the name of the cube to delete + :type name: `str` + :param strict: if no cube with the provided name exists, + raise an exception if and only if `strict` is `True` + :type strict: `bool` + """ + for i, cube in enumerate(self.qos_cubes): + if cube["name"] == name: + index = i + break + else: # no match + if strict: + raise ValueError("No cube with name %s found in dif %s" + % (name, self.name)) + else: + return + self.qos_cubes.pop(index) + class Distribution(Enum): """ -- cgit v1.2.3