def get_by_id(cls, context, id): db_obj = db_api.get_object(context, cls.db_model, **{cls.primary_key: id}) if db_obj: obj = cls(context, **db_obj) obj.obj_reset_changes() return obj
def delete(self): models = (("network", self.network_binding_model), ("port", self.port_binding_model)) with db_api.autonested_transaction(self._context.session): for object_type, model in models: binding_db_obj = db_api.get_object(self._context, model, policy_id=self.id) if binding_db_obj: raise exceptions.QosPolicyInUse( policy_id=self.id, object_type=object_type, object_id=binding_db_obj["%s_id" % object_type] ) super(QosPolicy, self).delete()
def delete(self): models = (('network', self.network_binding_model), ('port', self.port_binding_model)) with db_api.autonested_transaction(self._context.session): for object_type, model in models: binding_db_obj = db_api.get_object(self._context, model, policy_id=self.id) if binding_db_obj: raise exceptions.QosPolicyInUse( policy_id=self.id, object_type=object_type, object_id=binding_db_obj['%s_id' % object_type]) super(QosPolicy, self).delete()
def get_by_id(cls, context, id): db_obj = db_api.get_object(context, cls.db_model, id=id) if db_obj: obj = cls(context, **db_obj) obj.obj_reset_changes() return obj
def _get_object_policy(cls, context, model, **kwargs): with db_api.autonested_transaction(context.session): binding_db_obj = db_api.get_object(context, model, **kwargs) if binding_db_obj: return cls.get_by_id(context, binding_db_obj['policy_id'])
def _get_object_policy(cls, context, model, **kwargs): with db_api.autonested_transaction(context.session): binding_db_obj = db_api.get_object(context, model, **kwargs) if binding_db_obj: return cls.get_by_id(context, binding_db_obj["policy_id"])