From be3a6ffa5ad7aefed1d87eb5f1aa748e37edd5df Mon Sep 17 00:00:00 2001 From: sskaje Date: Mon, 30 Dec 2024 18:30:12 +0800 Subject: [PATCH] T4930: code style changes --- python/vyos/ifconfig/wireguard.py | 34 +++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/python/vyos/ifconfig/wireguard.py b/python/vyos/ifconfig/wireguard.py index 10869b8694..ceaecd875f 100644 --- a/python/vyos/ifconfig/wireguard.py +++ b/python/vyos/ifconfig/wireguard.py @@ -181,36 +181,54 @@ def get_latest_handshakes(self): def reset_peer(self, peer_name=None, public_key=None): from vyos.configquery import ConfigTreeQuery + c = ConfigTreeQuery() - max_dns_retry = c.value(['interfaces', 'wireguard', self.ifname, 'max-dns-retry']) + max_dns_retry = c.value( + ['interfaces', 'wireguard', self.ifname, 'max-dns-retry'] + ) if max_dns_retry is None: max_dns_retry = 3 current_peers = self._dump().get(self.ifname, {}).get('peers', {}) for peer in c.list_nodes(['interfaces', 'wireguard', self.ifname, 'peer']): - peer_public_key = c.value(['interfaces', 'wireguard', self.ifname, 'peer', peer, 'public-key']) + peer_public_key = c.value( + ['interfaces', 'wireguard', self.ifname, 'peer', peer, 'public-key'] + ) if peer_name is None or peer == peer_name or public_key == peer_public_key: - address = c.value(['interfaces', 'wireguard', self.ifname, 'peer', peer, 'address']) - port = c.value(['interfaces', 'wireguard', self.ifname, 'peer', peer, 'port']) + address = c.value( + ['interfaces', 'wireguard', self.ifname, 'peer', peer, 'address'] + ) + port = c.value( + ['interfaces', 'wireguard', self.ifname, 'peer', peer, 'port'] + ) if not address or not port: if peer_name is not None: print(f'Peer {peer_name} endpoint not set') continue - if c.exists(['interfaces', 'wireguard', self.ifname, 'peer', peer, 'disable']): + if c.exists( + ['interfaces', 'wireguard', self.ifname, 'peer', peer, 'disable'] + ): continue - cmd = f"wg set {self.ifname} peer {peer_public_key} endpoint {address}:{port}" + cmd = f'wg set {self.ifname} peer {peer_public_key} endpoint {address}:{port}' try: - if peer_public_key in current_peers and 'endpoint' in current_peers[peer_public_key] and current_peers[peer_public_key]['endpoint'] is not None: + if ( + peer_public_key in current_peers + and 'endpoint' in current_peers[peer_public_key] + and current_peers[peer_public_key]['endpoint'] is not None + ): current_endpoint = current_peers[peer_public_key]['endpoint'] message = f'Resetting {self.ifname} peer {peer_public_key} from {current_endpoint} endpoint to {address}:{port} ... ' else: message = f'Resetting {self.ifname} peer {peer_public_key} endpoint to {address}:{port} ... ' - print(message, end='',) + print( + message, + end='', + ) self._cmd( cmd, env={'WG_ENDPOINT_RESOLUTION_RETRIES': str(max_dns_retry)}