def CopyOpCode(self, opcode, **kwargs):
    """Creates a copy of the given opcode and applies modifications to it

    @type opcode: opcode.OpCode
    @param opcode: the opcode to copy
    @type kwargs: dict
    @param kwargs: dictionary of fields to overwrite in the copy. The special
          value L{REMOVE} can be used to remove fields from the copy.
    @return: a copy of the given opcode

    """
    state = opcode.__getstate__()

    for key, value in kwargs.items():
      if value == self.REMOVE and key in state:
        del state[key]
      else:
        state[key] = value

    return opcodes.OpCode.LoadOpCode(state)
dataset/ETHPy150Open ganeti/ganeti/test/py/cmdlib/testsupport/cmdlib_testcase.py/CmdlibTestCase.CopyOpCode/original