99
1010
1111class 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 )
0 commit comments