comparison planemo/lib/python3.7/site-packages/boto/vpc/vpnconnection.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 # Copyright (c) 2009-2010 Mitch Garnaat http://garnaat.org/
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21 import boto
22 from datetime import datetime
23 from boto.resultset import ResultSet
24
25 """
26 Represents a VPN Connectionn
27 """
28
29 from boto.ec2.ec2object import TaggedEC2Object
30
31 class VpnConnectionOptions(object):
32 """
33 Represents VPN connection options
34
35 :ivar static_routes_only: Indicates whether the VPN connection uses static
36 routes only. Static routes must be used for devices that don't support
37 BGP.
38
39 """
40 def __init__(self, static_routes_only=None):
41 self.static_routes_only = static_routes_only
42
43 def __repr__(self):
44 return 'VpnConnectionOptions'
45
46 def startElement(self, name, attrs, connection):
47 pass
48
49 def endElement(self, name, value, connection):
50 if name == 'staticRoutesOnly':
51 self.static_routes_only = True if value == 'true' else False
52 else:
53 setattr(self, name, value)
54
55 class VpnStaticRoute(object):
56 """
57 Represents a static route for a VPN connection.
58
59 :ivar destination_cidr_block: The CIDR block associated with the local
60 subnet of the customer data center.
61 :ivar source: Indicates how the routes were provided.
62 :ivar state: The current state of the static route.
63 """
64 def __init__(self, destination_cidr_block=None, source=None, state=None):
65 self.destination_cidr_block = destination_cidr_block
66 self.source = source
67 self.available = state
68
69 def __repr__(self):
70 return 'VpnStaticRoute: %s' % self.destination_cidr_block
71
72 def startElement(self, name, attrs, connection):
73 pass
74
75 def endElement(self, name, value, connection):
76 if name == 'destinationCidrBlock':
77 self.destination_cidr_block = value
78 elif name == 'source':
79 self.source = value
80 elif name == 'state':
81 self.state = value
82 else:
83 setattr(self, name, value)
84
85 class VpnTunnel(object):
86 """
87 Represents telemetry for a VPN tunnel
88
89 :ivar outside_ip_address: The Internet-routable IP address of the
90 virtual private gateway's outside interface.
91 :ivar status: The status of the VPN tunnel. Valid values: UP | DOWN
92 :ivar last_status_change: The date and time of the last change in status.
93 :ivar status_message: If an error occurs, a description of the error.
94 :ivar accepted_route_count: The number of accepted routes.
95 """
96 def __init__(self, outside_ip_address=None, status=None, last_status_change=None,
97 status_message=None, accepted_route_count=None):
98 self.outside_ip_address = outside_ip_address
99 self.status = status
100 self.last_status_change = last_status_change
101 self.status_message = status_message
102 self.accepted_route_count = accepted_route_count
103
104 def __repr__(self):
105 return 'VpnTunnel: %s' % self.outside_ip_address
106
107 def startElement(self, name, attrs, connection):
108 pass
109
110 def endElement(self, name, value, connection):
111 if name == 'outsideIpAddress':
112 self.outside_ip_address = value
113 elif name == 'status':
114 self.status = value
115 elif name == 'lastStatusChange':
116 self.last_status_change = datetime.strptime(value,
117 '%Y-%m-%dT%H:%M:%S.%fZ')
118 elif name == 'statusMessage':
119 self.status_message = value
120 elif name == 'acceptedRouteCount':
121 try:
122 value = int(value)
123 except ValueError:
124 boto.log.warning('Error converting code (%s) to int' % value)
125 self.accepted_route_count = value
126 else:
127 setattr(self, name, value)
128
129 class VpnConnection(TaggedEC2Object):
130 """
131 Represents a VPN Connection
132
133 :ivar id: The ID of the VPN connection.
134 :ivar state: The current state of the VPN connection.
135 Valid values: pending | available | deleting | deleted
136 :ivar customer_gateway_configuration: The configuration information for the
137 VPN connection's customer gateway (in the native XML format). This
138 element is always present in the
139 :class:`boto.vpc.VPCConnection.create_vpn_connection` response;
140 however, it's present in the
141 :class:`boto.vpc.VPCConnection.get_all_vpn_connections` response only
142 if the VPN connection is in the pending or available state.
143 :ivar type: The type of VPN connection (ipsec.1).
144 :ivar customer_gateway_id: The ID of the customer gateway at your end of
145 the VPN connection.
146 :ivar vpn_gateway_id: The ID of the virtual private gateway
147 at the AWS side of the VPN connection.
148 :ivar tunnels: A list of the vpn tunnels (always 2)
149 :ivar options: The option set describing the VPN connection.
150 :ivar static_routes: A list of static routes associated with a VPN
151 connection.
152
153 """
154 def __init__(self, connection=None):
155 super(VpnConnection, self).__init__(connection)
156 self.id = None
157 self.state = None
158 self.customer_gateway_configuration = None
159 self.type = None
160 self.customer_gateway_id = None
161 self.vpn_gateway_id = None
162 self.tunnels = []
163 self.options = None
164 self.static_routes = []
165
166 def __repr__(self):
167 return 'VpnConnection:%s' % self.id
168
169 def startElement(self, name, attrs, connection):
170 retval = super(VpnConnection, self).startElement(name, attrs, connection)
171 if retval is not None:
172 return retval
173 if name == 'vgwTelemetry':
174 self.tunnels = ResultSet([('item', VpnTunnel)])
175 return self.tunnels
176 elif name == 'routes':
177 self.static_routes = ResultSet([('item', VpnStaticRoute)])
178 return self.static_routes
179 elif name == 'options':
180 self.options = VpnConnectionOptions()
181 return self.options
182 return None
183
184 def endElement(self, name, value, connection):
185 if name == 'vpnConnectionId':
186 self.id = value
187 elif name == 'state':
188 self.state = value
189 elif name == 'customerGatewayConfiguration':
190 self.customer_gateway_configuration = value
191 elif name == 'type':
192 self.type = value
193 elif name == 'customerGatewayId':
194 self.customer_gateway_id = value
195 elif name == 'vpnGatewayId':
196 self.vpn_gateway_id = value
197 else:
198 setattr(self, name, value)
199
200 def delete(self, dry_run=False):
201 return self.connection.delete_vpn_connection(
202 self.id,
203 dry_run=dry_run
204 )