@@ -27,8 +27,33 @@ class TransactionSubmitException(F5SDKError):
2727
2828
2929class TransactionContextManager (object ):
30- def __init__ (self , transaction ):
30+ def __init__ (self , transaction , validate_only = False ):
31+ """Initialize a new Transaction context
32+
33+ Args:
34+ validate_only (bool): Will not commit the transaction, but only
35+ validate that it will succeed or not.
36+
37+ Attributes:
38+ transaction (Transaction): The transaction object that was sent
39+ to the context manager
40+ validate_only (bool): Specifies whether the transaction should
41+ commit itself upon `__exit__` or whether the commands in the
42+ transaction should just be checked to make sure they don't
43+ raise an error.
44+ bigip (dict): A reference to the dictionary containing the BIG-IP
45+ mgmt_root
46+ icr (iControlRESTSession): A reference to the dictionary
47+ containing the iControl REST session
48+ original_headers (dict): A deep copy of all the headers that were
49+ originally part of the iControl REST session. A copy is needed
50+ so that we can revert back to them after the transaction has
51+ been committed, since the only way to commit the transaction
52+ is to set the X-F5-REST-Coordination-Id to the value of the
53+ transaction ID of the transaction.
54+ """
3155 self .transaction = transaction
56+ self .validate_only = validate_only
3257 self .bigip = transaction ._meta_data ['bigip' ]
3358 self .icr = self .bigip ._meta_data ['icr_session' ]
3459 self .original_headers = copy .deepcopy (self .icr .session .headers )
@@ -68,10 +93,12 @@ def __exit__(self, exc_type, exc_value, exc_tb):
6893 parameters will be None
6994 :returns: void
7095 """
96+
7197 self .icr .session .headers = dict ()
7298 if exc_tb is None :
7399 try :
74- self .transaction .update (state = "VALIDATING" )
100+ self .transaction .modify (state = "VALIDATING" ,
101+ validateOnly = self .validate_only )
75102 except Exception as e :
76103 logging .debug (e )
77104 raise TransactionSubmitException (e )
0 commit comments