Skip to content

Commit 504cfdc

Browse files
committed
SMC-22764 Add tunnel endpoint feature pull request
- Pulled in and tested tunnel endpoint from gabstopper/smc-python#68 - Updated type to differentiate from GatewayTunnel - Added name from deducted name to InternalEndpoints so it appears in endpoint tunnel object
1 parent a69d192 commit 504cfdc

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

smc/core/engine.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,12 @@ class InternalEndpoint(SubElement):
15031503
:ivar str balancing_mode: VPN load balancing mode. Valid options are:
15041504
'standby', 'aggregate', 'active' (default: 'active')
15051505
"""
1506+
@property
1507+
def name(self):
1508+
"""
1509+
Get the name from deducted name
1510+
"""
1511+
return self.data.get('deducted_name')
15061512

15071513
@property
15081514
def interface_id(self):

smc/vpn/policy.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from smc.vpn.elements import VPNProfile, VPNSite
66
from smc.base.decorators import cached_property
77
from smc.base.util import element_resolver
8+
from smc.core.engine import InternalEndpoint
89

910

1011
class PolicyVPN(Element):
@@ -482,6 +483,30 @@ def tunnel_side_b(self):
482483
return type('TunnelSideB', (GatewayNode,), {
483484
'href': self.data.get('gateway_node_2')})()
484485

486+
@property
487+
def endpoint_tunnels(self):
488+
"""
489+
Return all Endpoint tunnels for this gateway tunnel. A tunnel
490+
is defined as two end points within the VPN topology.
491+
Endpoints are automatically configureed based on whether they
492+
are a central gateway or satellite gateway. This provides
493+
access to enabling/disabling and setting the preshared key
494+
for the linked endpoints. List all Endpoint tunnel mappings
495+
for this policy vpn::
496+
497+
for tunnel in policy.tunnels:
498+
tunnela = tunnel.tunnel_side_a
499+
tunnelb = tunnel.tunnel_side_b
500+
print(tunnela.gateway)
501+
print(tunnelb.gateway)
502+
for endpointtunnel in tunnel.endpoint_tunnels:
503+
print(endpointtunnel)
504+
505+
:rtype: SubElementCollection(GatewayTunnel)
506+
"""
507+
return sub_collection(
508+
self.get_relation('gateway_endpoint_tunnel'), EndpointTunnel)
509+
485510
def __str__(self):
486511
return '{0}(tunnel_side_a={1},tunnel_side_b={2})'.format(
487512
self.__class__.__name__, self.tunnel_side_a.name, self.tunnel_side_b.name)
@@ -493,4 +518,63 @@ def __repr__(self):
493518
class ClientGateway(Element):
494519
typeof = 'client_gateway'
495520

496-
521+
class EndpointTunnel(SubElement):
522+
"""
523+
An Endpoint tunnel represents the point to point connection
524+
between two IPSEC endpoints in a PolicyVPN configuration.
525+
The tunnel arrangement is based on whether the nodes are placed
526+
as a central gateway or a satellite gateway. This provides access
527+
to see the point to point connections, whether the link is enabled,
528+
and setting the presharred key.
529+
"""
530+
531+
def enable_disable(self):
532+
"""
533+
Enable or disable the tunnel link between endpoints.
534+
535+
:raises UpdateElementFailed: failed with reason
536+
:return: None
537+
"""
538+
if self.enabled:
539+
self.update(enabled=False)
540+
else:
541+
self.update(enabled=True)
542+
543+
@property
544+
def enabled(self):
545+
"""
546+
Whether the VPN link between endpoints is enabled
547+
548+
:rtype: bool
549+
"""
550+
return self.data.get('enabled', False)
551+
552+
553+
@property
554+
def internal_endpoint_side_a(self):
555+
"""
556+
Return the Internal Endpoint for tunnel side A. This will
557+
be an instance of InternalEndpoint.
558+
559+
:rtype: InternalEndpoint
560+
"""
561+
return type('EndpointTunnelSideA', (InternalEndpoint,), {
562+
'href': self.data.get('endpoint_1')})()
563+
564+
@property
565+
def internal_endpoint_side_b(self):
566+
"""
567+
Return the Internal Endpoint for tunnel side B. This will
568+
be an instance of InternalEndpoint.
569+
570+
:rtype: InternalEndpoint
571+
"""
572+
return type('EndpointTunnelSideB', (InternalEndpoint,), {
573+
'href': self.data.get('endpoint_2')})()
574+
575+
def __str__(self):
576+
return '{0}(name={1})'.format(
577+
self.__class__.__name__, self.name)
578+
579+
def __repr__(self):
580+
return str(self)

0 commit comments

Comments
 (0)