55from smc .vpn .elements import VPNProfile , VPNSite
66from smc .base .decorators import cached_property
77from smc .base .util import element_resolver
8+ from smc .core .engine import InternalEndpoint
89
910
1011class 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):
493518class 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