Skip to content

Commit 4669a1b

Browse files
authored
Ronerez/edge proxy support (#216)
1 parent 51e684c commit 4669a1b

File tree

5 files changed

+236
-62
lines changed

5 files changed

+236
-62
lines changed

cterasdk/edge/network.py

Lines changed: 105 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99

1010

1111
class Network(BaseCommand):
12-
""" Gateway Network configuration APIs """
12+
""" Edge Filer Network configuration APIs """
13+
14+
def __init__(self, portal):
15+
super().__init__(portal)
16+
self.proxy = Proxy(self._gateway)
17+
self.mtu = MTU(self._gateway)
18+
self.routes = StaticRoutes(self._gateway)
1319

1420
def get_status(self):
1521
"""
@@ -79,26 +85,6 @@ def set_static_nameserver(self, primary_dns_server, secondary_dns_server=None):
7985

8086
logging.getLogger().info('Nameserver settings updated. %s', {'DNS1': primary_dns_server, 'DNS2': secondary_dns_server})
8187

82-
def reset_mtu(self):
83-
"""
84-
Set the default maximum transmission unit (MTU) settings
85-
"""
86-
self._set_mtu(False, 1500)
87-
88-
def set_mtu(self, mtu):
89-
"""
90-
Set a custom network maximum transmission unit (MTU)
91-
92-
:param int mtu: Maximum transmission unit
93-
"""
94-
self._set_mtu(True, mtu)
95-
96-
def _set_mtu(self, jumbo, mtu):
97-
settings = self._gateway.get('/config/network/ports/0/ethernet')
98-
settings.jumbo = jumbo
99-
settings.mtu = mtu
100-
return self._gateway.put('/config/network/ports/0/ethernet', settings)
101-
10288
def enable_dhcp(self):
10389
"""
10490
Enable DHCP
@@ -178,15 +164,103 @@ def iperf(self, address, port=5201, threads=1, protocol=IPProtocol.TCP, directio
178164
except TaskError as error:
179165
return error.task.result.res
180166

181-
def get_static_routes(self):
167+
168+
class Proxy(BaseCommand):
169+
"""Edge Filer Proxy Configuration APIs"""
170+
171+
def get_configuration(self):
172+
"""
173+
Get Proxy Configuration
174+
"""
175+
return self._gateway.get('/config/network/proxy')
176+
177+
def is_enabled(self):
178+
"""
179+
Check if Proxy Configuration is Enabled
180+
181+
:returns: ``True`` if a proxy server was configured and ``False`` otherwise.
182+
:rtype: bool
183+
"""
184+
return self._gateway.get('/config/network/proxy/configurationMode') != 'NoProxy'
185+
186+
def modify(self, address, port=None, username=None, password=None):
187+
"""
188+
Modify Proxy Configuration
189+
190+
:param str address: Proxy address
191+
:param int,optional port: Proxy port, defaults to ``8080``
192+
:param str,optional username: Username
193+
:param str,optional password: Password
194+
:returns: Proxy settings
195+
:rtype: cterasdk.common.object.Object
196+
"""
197+
return self._configure(True, address, port, username, password)
198+
199+
def _configure(self, enabled, address=None, port=None, username=None, password=None):
200+
param = Object()
201+
param._classname = 'ProxySettings' # pylint: disable=protected-access
202+
param.configurationMode = 'Manual' if enabled else 'NoProxy'
203+
if enabled:
204+
param.port = port if port else 8080
205+
if address:
206+
param.address = address
207+
if username:
208+
param.username = username
209+
if password:
210+
param.password = password
211+
logging.getLogger().info('Updating Proxy Server Configuration.')
212+
response = self._gateway.put('/config/network/proxy', param)
213+
logging.getLogger().info('Updated Proxy Server Configuration.')
214+
return response
215+
216+
def disable(self):
217+
"""
218+
Disable Proxy
219+
220+
:returns: Proxy settings
221+
:rtype: cterasdk.common.object.Object
222+
"""
223+
logging.getLogger().info('Disabling Proxy.')
224+
return self._configure(False)
225+
226+
227+
class MTU(BaseCommand):
228+
"""Edge Filer MTU Configuration APIs"""
229+
230+
def reset(self):
231+
"""
232+
Set the default maximum transmission unit (MTU) settings
233+
"""
234+
return self._configure(False, 1500)
235+
236+
def modify(self, mtu):
237+
"""
238+
Set a custom network maximum transmission unit (MTU)
239+
240+
:param int mtu: Maximum transmission unit
241+
"""
242+
return self._configure(True, mtu)
243+
244+
def _configure(self, jumbo, mtu):
245+
settings = self._gateway.get('/config/network/ports/0/ethernet')
246+
settings.jumbo = jumbo
247+
settings.mtu = mtu
248+
logging.getLogger().info('Configuring MTU. %s', {'MTU': mtu})
249+
return self._gateway.put('/config/network/ports/0/ethernet', settings)
250+
251+
252+
class StaticRoutes(BaseCommand):
253+
"""Edge Filer Static Route Configuration APIs"""
254+
255+
def get(self):
182256
"""
183-
Get all Static Routes
257+
Get All Static Routes
184258
"""
185259
return self._gateway.get('/config/network/static_routes')
186260

187-
def add_static_route(self, source_ip, destination_ip_mask):
261+
def add(self, source_ip, destination_ip_mask):
188262
"""
189-
Set a Static Route
263+
Add a Static Route
190264
191265
:param str source_ip: The source IP (192.168.15.55)
192266
:param str destination_ip_mask: The destination IP and CIDR block (10.5.0.1/32)
@@ -203,9 +277,9 @@ def add_static_route(self, source_ip, destination_ip_mask):
203277
logging.getLogger().error("Static route creation failed.")
204278
raise CTERAException('Static route creation failed', error)
205279

206-
def remove_static_route(self, destination_ip_mask):
280+
def remove(self, destination_ip_mask):
207281
"""
208-
Delete a Static Route
282+
Remove a Static Route
209283
210284
:param str destination_ip_mask: The destination IP and CIDR block (10.5.0.1/32)
211285
"""
@@ -219,13 +293,13 @@ def remove_static_route(self, destination_ip_mask):
219293
logging.getLogger().error("Static route deletion failed.")
220294
raise CTERAException('Static route deletion failed', error)
221295

222-
def clean_all_static_routes(self):
296+
def clear(self):
223297
"""
224-
Clean all Static routes
298+
Clear All Static routes
225299
"""
226300
try:
227301
self._gateway.execute('/config/network', 'cleanStaticRoutes')
228302
logging.getLogger().info('Static routes were deleted successfully')
229303
except CTERAException as error:
230-
logging.getLogger().error("Failed to clean Static routes")
231-
raise CTERAException('Failed to delete Static routes', error)
304+
logging.getLogger().error("Failed to clear static routes")
305+
raise CTERAException('Failed to clear static routes', error)

cterasdk/edge/services.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,27 @@ def connected(self):
4646
"""
4747
return self._gateway.get('/status/services/CTERAPortal/connectionState') == enum.ServicesConnectionState.Connected
4848

49+
def _before_connect_to_services(self, ctera_license, server):
50+
Services._validate_license(ctera_license)
51+
if self._gateway.network.proxy.is_enabled():
52+
logging.getLogger().debug('Skipping TCP connection verification over port 995.')
53+
else:
54+
self._check_cttp_traffic(address=server)
55+
4956
def connect(self, server, user, password, ctera_license=enum.License.EV16):
5057
"""
5158
Connect to a Portal.\n
5259
The connect method will first validate the `license` argument,
53-
ensure the Gateway can establish a TCP connection over port 995 to `server` using :py:func:`Gateway.tcp_connect()` and
54-
verify the Portal does not require device activation via code
60+
ensure the Edge Filer can establish a TCP connection over port 995 to `server` using :py:func:`Gateway.tcp_connect()` and
61+
verify the Portal does not require device activation via code.
62+
TCP connection verification over port 995 is skipped when the Edge Filer is configured to use a proxy.
5563
5664
:param str server: Address of the Portal
5765
:param str user: User for the Portal connection
5866
:param str password: Password for the Portal connection
5967
:param cterasdk.edge.enum.License,optional ctera_license: CTERA License, defaults to cterasdk.edge.enum.License.EV16
6068
"""
61-
Services._validate_license(ctera_license)
62-
self._check_cttp_traffic(address=server)
69+
self._before_connect_to_services(ctera_license, server)
6370
self._check_connection(server)
6471

6572
param = Object()
@@ -78,8 +85,7 @@ def activate(self, server, user, code, ctera_license=enum.License.EV16):
7885
:param str code: Activation code for the Portal connection
7986
:param cterasdk.edge.enum.License,optional ctera_license: CTERA License, defaults to cterasdk.edge.enum.License.EV16
8087
"""
81-
Services._validate_license(ctera_license)
82-
self._check_cttp_traffic(address=server)
88+
self._before_connect_to_services(ctera_license, server)
8389

8490
param = Object()
8591
param.server = server

docs/source/user_guides/Gateway/Gateway.rst

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -982,56 +982,95 @@ Network
982982
983983
filer.network.enable_dhcp()
984984
985-
.. automethod:: cterasdk.edge.network.Network.set_mtu
985+
Proxy Server
986+
^^^^^^^^^^^^
987+
988+
.. automethod:: cterasdk.edge.network.Proxy.get_configuration
989+
:noindex:
990+
991+
.. code-block:: python
992+
993+
configuration = filer.network.proxy.get_configuration()
994+
print(configuration)
995+
996+
.. automethod:: cterasdk.edge.network.Proxy.is_enabled
997+
:noindex:
998+
999+
.. code-block:: python
1000+
1001+
if filer.network.proxy.is_enabled():
1002+
print('Proxy Server is Enabled')
1003+
1004+
.. automethod:: cterasdk.edge.network.Proxy.modify
1005+
:noindex:
1006+
1007+
.. code-block:: python
1008+
1009+
filer.network.proxy.modify('192.168.11.11', 8081, 'proxy-user', 'proxy-user-password')
1010+
1011+
.. automethod:: cterasdk.edge.network.Proxy.disable
1012+
:noindex:
1013+
1014+
.. code-block:: python
1015+
1016+
filer.network.proxy.disable()
1017+
1018+
MTU
1019+
^^^
1020+
1021+
.. automethod:: cterasdk.edge.network.MTU.modify
9861022
:noindex:
9871023

9881024
.. code-block:: python
9891025
990-
filer.network.set_mtu(1320) # set the maximum transmission unit (MTU) to 1320
1026+
filer.network.mtu.modify(1320) # set the maximum transmission unit (MTU) to 1320
9911027
992-
filer.network.set_mtu(9000) # configure 'jumbo' frames (MTU: 9000)
1028+
filer.network.mtu.modify(9000) # configure 'jumbo' frames (MTU: 9000)
9931029
994-
.. automethod:: cterasdk.edge.network.Network.reset_mtu
1030+
.. automethod:: cterasdk.edge.network.MTU.reset
9951031
:noindex:
9961032

9971033
.. code-block:: python
9981034
999-
filer.network.reset_mtu() # disable custom mtu configuration and restore default setting (1500)
1035+
filer.network.mtu.reset() # disable custom mtu configuration and restore default setting (1500)
1036+
1037+
Static Routes
1038+
^^^^^^^^^^^^^
10001039

1001-
.. automethod:: cterasdk.edge.network.Network.get_static_routes
1040+
.. automethod:: cterasdk.edge.network.StaticRoutes.get
10021041
:noindex:
10031042

10041043
.. code-block:: python
10051044
10061045
# get static routes
1007-
filer.network.get_static_routes()
1046+
filer.network.routes.get()
10081047
1009-
.. automethod:: cterasdk.edge.network.Network.add_static_route
1048+
.. automethod:: cterasdk.edge.network.StaticRoutes.add
10101049
:noindex:
10111050

10121051
.. code-block:: python
10131052
10141053
# add static route from 10.10.12.1 to 192.168.55.7/32
1015-
filer.network.add_static_route('10.10.12.1', '192.168.55.7/32')
1054+
filer.network.routes.add('10.10.12.1', '192.168.55.7/32')
10161055
10171056
# add static route from 10.100.102.4 to 172.18.100.0/24
1018-
filer.network.add_static_route('10.100.102.4', '172.18.100.0/24')
1057+
filer.network.routes.add('10.100.102.4', '172.18.100.0/24')
10191058
1020-
.. automethod:: cterasdk.edge.network.Network.remove_static_route
1059+
.. automethod:: cterasdk.edge.network.StaticRoutes.remove
10211060
:noindex:
10221061

10231062
.. code-block:: python
10241063
10251064
# remove static route 192.168.55.7/32
1026-
filer.network.remove_static_route('192.168.55.7/32')
1065+
filer.network.routes.remove('192.168.55.7/32')
10271066
1028-
.. automethod:: cterasdk.edge.network.Network.clean_all_static_routes
1067+
.. automethod:: cterasdk.edge.network.StaticRoutes.clear
10291068
:noindex:
10301069

10311070
.. code-block:: python
10321071
10331072
# remove all static routes - (clean)
1034-
filer.network.clean_all_static_routes()
1073+
filer.network.routes.clear()
10351074
10361075
10371076
Network Diagnostics

0 commit comments

Comments
 (0)