Introduce event_name property
The event_name is typically set manually as a class attribute and the value is the same as the class name. That requires to re-set the class attribute whenever a new subclass is created. The patch makes the event_name a property that always calls to its own class name so we do not need to explicitly name the event. If a different name than the class name is needed, we can always override the property itself. Change-Id: I1a62a2e1b4f4aeecf0ec9698f7b55ed0bed73a5a Signed-off-by: Jakub Libosvar <libosvar@redhat.com>
This commit is contained in:
@@ -36,7 +36,6 @@ class RowEvent(object, metaclass=abc.ABCMeta):
|
||||
ROW_UPDATE = "update"
|
||||
ROW_DELETE = "delete"
|
||||
ONETIME = False
|
||||
event_name = 'RowEvent'
|
||||
priority = 20
|
||||
|
||||
def __init__(self, events, table, conditions, old_conditions=None):
|
||||
@@ -85,9 +84,18 @@ class RowEvent(object, metaclass=abc.ABCMeta):
|
||||
def run(self, event, row, old):
|
||||
"""Method to run when the event matches"""
|
||||
|
||||
@property
|
||||
def event_name(self):
|
||||
if not hasattr(self, '_event_name'):
|
||||
return self.__class__.__name__
|
||||
return self._event_name
|
||||
|
||||
@event_name.setter
|
||||
def event_name(self, value):
|
||||
self._event_name = value
|
||||
|
||||
|
||||
class WaitEvent(RowEvent):
|
||||
event_name = 'WaitEvent'
|
||||
ONETIME = True
|
||||
priority = 10
|
||||
|
||||
|
@@ -14,8 +14,6 @@ from ovsdbapp.backend.ovs_idl import event
|
||||
|
||||
|
||||
class WaitForPortBindingEvent(event.WaitEvent):
|
||||
event_name = 'WaitForPortBindingEvent'
|
||||
|
||||
def __init__(self, port, timeout=5):
|
||||
super(WaitForPortBindingEvent, self).__init__(
|
||||
(self.ROW_CREATE,), 'Port_Binding', (('logical_port', '=', port),),
|
||||
|
Reference in New Issue
Block a user