Skip to content

Commit c87bd6a

Browse files
authored
Saimon/edge hosts file entries (#307)
1 parent cc9c342 commit c87bd6a

4 files changed

Lines changed: 79 additions & 2 deletions

File tree

cterasdk/edge/network.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self, portal):
1919
self.proxy = Proxy(self._edge)
2020
self.mtu = MTU(self._edge)
2121
self.routes = StaticRoutes(self._edge)
22+
self.hosts = Hosts(self._edge)
2223

2324
def get_status(self):
2425
"""
@@ -306,3 +307,26 @@ def clear(self):
306307
except CTERAException as error:
307308
logger.error("Failed to clear static routes")
308309
raise CTERAException('Failed to clear static routes') from error
310+
311+
312+
class Hosts(BaseCommand):
313+
"""Edge Filer Static Route Configuration APIs"""
314+
315+
def get(self):
316+
"""
317+
Get the Edge Filer's hosts file entries.
318+
"""
319+
return self._edge.api.get('/config/network/hostsFileEntries')
320+
321+
def add(self, ipaddr, hostname):
322+
"""
323+
Add entry to the Edge Filer's hosts file.
324+
325+
:param str ipaddr: IP Address
326+
:param str hostname: Hostname
327+
"""
328+
param = Object(ip=ipaddr, hostName=hostname)
329+
return self._edge.api.add('/config/network/hostsFileEntries', param)
330+
331+
def delete(self, hostname):
332+
return self._edge.api.delete(f'/config/network/hostsFileEntries/{hostname}')

docs/source/UserGuides/Edge/Configuration.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,31 @@ Static Routes
949949
edge.network.routes.clear()
950950
951951
952+
Hosts
953+
-----
954+
955+
.. automethod:: cterasdk.edge.network.Hosts.get
956+
:noindex:
957+
958+
.. code-block:: python
959+
960+
edge.network.hosts.get() # get a list of hosts file entries
961+
962+
.. automethod:: cterasdk.edge.network.Hosts.add
963+
:noindex:
964+
965+
.. code-block:: python
966+
967+
edge.network.hosts.add('192.168.28.153', 'tenant.ctera.com')
968+
969+
.. automethod:: cterasdk.edge.network.Hosts.delete
970+
:noindex:
971+
972+
.. code-block:: python
973+
974+
edge.network.hosts.delete('tenant.ctera.com')
975+
976+
952977
Diagnostics
953978
-----------
954979

docs/source/UserGuides/Miscellaneous/Changelog.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Bug Fixes
99

1010
* Fixed a documentation error related to deleting and undeleting Team Portal tenants.
1111

12-
Related issues and pull requests on GitHub: `#305 <https://github.com/ctera/ctera-python-sdk/pull/305>`_
12+
Related issues and pull requests on GitHub: `#306 <https://github.com/ctera/ctera-python-sdk/pull/306>`_,
13+
`#307 <https://github.com/ctera/ctera-python-sdk/pull/307>`_
1314

1415

1516
2.20.14
@@ -20,7 +21,7 @@ Bug Fixes
2021

2122
* CTERA Portal: Added support for special characters when copying, moving, renaming, sharing, and deleting files.
2223

23-
Related issues and pull requests on GitHub: `#304 <https://github.com/ctera/ctera-python-sdk/pull/304>`_
24+
Related issues and pull requests on GitHub: `#305 <https://github.com/ctera/ctera-python-sdk/pull/305>`_
2425

2526
2.20.13
2627
-------

tests/ut/edge/test_network.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def setUp(self):
4949
self._proxy_user = 'admin'
5050
self._proxy_pass = 'password'
5151

52+
self._hosts_ipaddr = '192.168.0.1'
53+
self._hosts_hostname = 'address.ctera.com'
54+
5255
def test_network_status(self):
5356
get_response = 'Success'
5457
self._init_filer(get_response=get_response)
@@ -351,3 +354,27 @@ def _create_proxy_param(enabled=None, address=None, port=None, username=None, pa
351354
if password:
352355
m.password = password
353356
return m
357+
358+
def test_get_hosts_file(self):
359+
get_response = 'Success'
360+
self._init_filer(get_response=get_response)
361+
ret = network.Network(self._filer).hosts.get()
362+
self._filer.api.get.assert_called_once_with('/config/network/hostsFileEntries')
363+
self.assertEqual(ret, get_response)
364+
365+
def test_add_hosts_file_entry(self):
366+
add_response = 'Success'
367+
self._init_filer(add_response=add_response)
368+
ret = network.Network(self._filer).hosts.add(self._hosts_ipaddr, self._hosts_hostname)
369+
self._filer.api.add.assert_called_once_with('/config/network/hostsFileEntries', mock.ANY)
370+
actual_param = self._filer.api.add.call_args[0][1]
371+
expected_param = munch.Munch(dict(ip=self._hosts_ipaddr, hostName=self._hosts_hostname))
372+
self._assert_equal_objects(actual_param, expected_param)
373+
self.assertEqual(ret, add_response)
374+
375+
def test_delete_hosts_file_entry(self):
376+
delete_response = 'Success'
377+
self._init_filer(delete_response=delete_response)
378+
ret = network.Network(self._filer).hosts.delete(self._hosts_hostname)
379+
self._filer.api.delete.assert_called_once_with(f'/config/network/hostsFileEntries/{self._hosts_hostname}')
380+
self.assertEqual(ret, delete_response)

0 commit comments

Comments
 (0)