def process_update_network(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" LOG.debug("RK: process_update_network(). data: %s" , data) net_id = result.get('id') net_min_attr = data.get(rk_const.RK_MIN_RATE) net_max_attr = data.get(rk_const.RK_MAX_RATE) LOG.debug("RK: update_network: %s and %s", net_min_attr, net_max_attr) if attributes.is_attr_set(net_min_attr) and \ attributes.is_attr_set(net_max_attr): with context.session.begin(subtransactions=True): try: res = rk_db.get_vnet_profile(net_id, context.session) if res: rk_db.update_vnet_rate_limit(net_id, net_min_attr, net_max_attr, context.session) else: # Network not found and can't be updated. Create instead try: rk_db.create_vnet_record(net_id, net_min_attr, net_max_attr, context.session) except Exception as e: LOG.error(_LE("RK: update_network: error %s" % e)) raise ml2_exc.MechanismDriverError() LOG.debug("RK: update_network: res: %s", res) except Exception as a: LOG.error(_LE("RK: update_network: error %s" % a)) raise ml2_exc.MechanismDriverError()
def process_create_network(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" LOG.debug("RK: process_create_network(). data: %s", data) net_id = result.get('id') port_min_attr = data.get(rk_const.RK_MIN_RATE) port_max_attr = data.get(rk_const.RK_MAX_RATE) if not attributes.is_attr_set(port_min_attr) or \ not attributes.is_attr_set(port_max_attr): port_min_attr = cfg.CONF.RATEKEEPER.default_min_rate port_max_attr = cfg.CONF.RATEKEEPER.default_max_rate port_min_attr, port_max_attr = self._validate_rates(port_min_attr, port_max_attr) LOG.debug("RK: port_min_attr %s, port_max_attr %s", port_min_attr, port_max_attr) with context.session.begin(subtransactions=True): try: rk_db.create_vnet_record(net_id, port_min_attr, port_max_attr, context.session) except Exception as e: LOG.error(_LE("RK: error %s" % e)) raise ml2_exc.MechanismDriverError() result[rk_const.RK_MIN_RATE] = port_min_attr result[rk_const.RK_MAX_RATE] = port_max_attr