diff options
author | Christian Breunig <christian@breunig.cc> | 2023-04-01 10:52:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-01 10:52:44 +0200 |
commit | dcd2edc6ddeeba156125aa5663898029b20d553a (patch) | |
tree | 4adda4cd9b97c024bb71f32ae2930aa35e59056c /python | |
parent | 0a49c0af4dbdcad9e494d4fba2212f156485fd7d (diff) | |
parent | a78982625a8a18069bd5a13744734873698fd0f9 (diff) | |
download | vyos-1x-dcd2edc6ddeeba156125aa5663898029b20d553a.tar.gz vyos-1x-dcd2edc6ddeeba156125aa5663898029b20d553a.zip |
Merge pull request #1926 from aapostoliuk/T5093-sagitta
ipsec: T5093: Fixed 'reset vpn ipsec profile' command
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ipsec.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/python/vyos/ipsec.py b/python/vyos/ipsec.py index cb7c39ff6..bb5611025 100644 --- a/python/vyos/ipsec.py +++ b/python/vyos/ipsec.py @@ -139,3 +139,41 @@ def terminate_vici_by_name(ike_name: str, child_name: str) -> None: else: raise ViciCommandError( f'Failed to terminate SA for IKE {ike_name}') + + +def vici_initiate(ike_sa_name: str, child_sa_name: str, src_addr: str, + dst_addr: str) -> bool: + """Initiate IKE SA connection with specific peer + + Args: + ike_sa_name (str): an IKE SA connection name + child_sa_name (str): a child SA profile name + src_addr (str): source address + dst_addr (str): remote address + + Returns: + bool: a result of initiation command + """ + from vici import Session as vici_session + + try: + session = vici_session() + except Exception: + raise ViciInitiateError("IPsec not initialized") + + try: + session_generator = session.initiate({ + 'ike': ike_sa_name, + 'child': child_sa_name, + 'timeout': '-1', + 'my-host': src_addr, + 'other-host': dst_addr + }) + # a dummy `for` loop is required because of requirements + # from vici. Without a full iteration on the output, the + # command to vici may not be executed completely + for _ in session_generator: + pass + return True + except Exception: + raise ViciCommandError(f'Failed to initiate SA for IKE {ike_sa_name}')
\ No newline at end of file |