action: support assigning fields with keyword arguments to the constructor
The basic module has been changed to use the new API.
diff --git a/tests/basic.py b/tests/basic.py
index 43b7de4..a1540a1 100644
--- a/tests/basic.py
+++ b/tests/basic.py
@@ -204,8 +204,7 @@
logging.info("PKT OUT test with %s, port %s" % (opt, dp_port))
msg = message.packet_out(in_port=ofp.OFPP_NONE,
data=str(outpkt))
- act = action.action_output()
- act.port = dp_port
+ act = action.action_output(port=dp_port)
msg.actions.add(act)
logging.info("PacketOut to: " + str(dp_port))
@@ -258,9 +257,8 @@
", ports " + str(dp_ports))
msg = message.packet_out(in_port=ofp.OFPP_NONE,
data=str(outpkt))
- act = action.action_output()
for i in range(0,num_ports):
- act.port = dp_ports[i]
+ act = action.action_output(port=dp_ports[i])
msg.actions.add(act)
logging.info("PacketOut to: " + str(dp_ports))
diff --git a/tools/munger/scripts/action_gen.py b/tools/munger/scripts/action_gen.py
index 116cd7b..2e26144 100644
--- a/tools/munger/scripts/action_gen.py
+++ b/tools/munger/scripts/action_gen.py
@@ -72,10 +72,15 @@
--DOC_INFO--
\"""
- def __init__(self):
+ def __init__(self, **kwargs):
--PARENT_TYPE--.__init__(self)
self.type = --ACTION_NAME--
self.len = self.__len__()
+ for (k, v) in kwargs.items():
+ if hasattr(self, k):
+ setattr(self, k, v)
+ else:
+ raise NameError("field %s does not exist in %s" % (k, self.__class__))
def show(self, prefix=''):
outstr = prefix + "action_--TYPE--\\n"
outstr += --PARENT_TYPE--.show(self, prefix)