diff --git a/cterasdk/edge/network.py b/cterasdk/edge/network.py index 9ffe84e2..959c2191 100644 --- a/cterasdk/edge/network.py +++ b/cterasdk/edge/network.py @@ -19,6 +19,7 @@ def __init__(self, portal): self.proxy = Proxy(self._edge) self.mtu = MTU(self._edge) self.routes = StaticRoutes(self._edge) + self.hosts = Hosts(self._edge) def get_status(self): """ @@ -306,3 +307,26 @@ def clear(self): except CTERAException as error: logger.error("Failed to clear static routes") raise CTERAException('Failed to clear static routes') from error + + +class Hosts(BaseCommand): + """Edge Filer Static Route Configuration APIs""" + + def get(self): + """ + Get the Edge Filer's hosts file entries. + """ + return self._edge.api.get('/config/network/hostsFileEntries') + + def add(self, ipaddr, hostname): + """ + Add entry to the Edge Filer's hosts file. + + :param str ipaddr: IP Address + :param str hostname: Hostname + """ + param = Object(ip=ipaddr, hostName=hostname) + return self._edge.api.add('/config/network/hostsFileEntries', param) + + def delete(self, hostname): + return self._edge.api.delete(f'/config/network/hostsFileEntries/{hostname}') diff --git a/docs/source/UserGuides/Edge/Configuration.rst b/docs/source/UserGuides/Edge/Configuration.rst index ef5541a9..c23030d4 100644 --- a/docs/source/UserGuides/Edge/Configuration.rst +++ b/docs/source/UserGuides/Edge/Configuration.rst @@ -949,6 +949,31 @@ Static Routes edge.network.routes.clear() +Hosts +----- + +.. automethod:: cterasdk.edge.network.Hosts.get + :noindex: + +.. code-block:: python + + edge.network.hosts.get() # get a list of hosts file entries + +.. automethod:: cterasdk.edge.network.Hosts.add + :noindex: + +.. code-block:: python + + edge.network.hosts.add('192.168.28.153', 'tenant.ctera.com') + +.. automethod:: cterasdk.edge.network.Hosts.delete + :noindex: + +.. code-block:: python + + edge.network.hosts.delete('tenant.ctera.com') + + Diagnostics ----------- diff --git a/docs/source/UserGuides/Miscellaneous/Changelog.rst b/docs/source/UserGuides/Miscellaneous/Changelog.rst index 6f2455fc..49e4a06e 100644 --- a/docs/source/UserGuides/Miscellaneous/Changelog.rst +++ b/docs/source/UserGuides/Miscellaneous/Changelog.rst @@ -9,7 +9,8 @@ Bug Fixes * Fixed a documentation error related to deleting and undeleting Team Portal tenants. -Related issues and pull requests on GitHub: `#305 `_ +Related issues and pull requests on GitHub: `#306 `_, +`#307 `_ 2.20.14 @@ -20,7 +21,7 @@ Bug Fixes * CTERA Portal: Added support for special characters when copying, moving, renaming, sharing, and deleting files. -Related issues and pull requests on GitHub: `#304 `_ +Related issues and pull requests on GitHub: `#305 `_ 2.20.13 ------- diff --git a/tests/ut/edge/test_network.py b/tests/ut/edge/test_network.py index f04f5e0b..b5e8a37d 100644 --- a/tests/ut/edge/test_network.py +++ b/tests/ut/edge/test_network.py @@ -49,6 +49,9 @@ def setUp(self): self._proxy_user = 'admin' self._proxy_pass = 'password' + self._hosts_ipaddr = '192.168.0.1' + self._hosts_hostname = 'address.ctera.com' + def test_network_status(self): get_response = 'Success' self._init_filer(get_response=get_response) @@ -351,3 +354,27 @@ def _create_proxy_param(enabled=None, address=None, port=None, username=None, pa if password: m.password = password return m + + def test_get_hosts_file(self): + get_response = 'Success' + self._init_filer(get_response=get_response) + ret = network.Network(self._filer).hosts.get() + self._filer.api.get.assert_called_once_with('/config/network/hostsFileEntries') + self.assertEqual(ret, get_response) + + def test_add_hosts_file_entry(self): + add_response = 'Success' + self._init_filer(add_response=add_response) + ret = network.Network(self._filer).hosts.add(self._hosts_ipaddr, self._hosts_hostname) + self._filer.api.add.assert_called_once_with('/config/network/hostsFileEntries', mock.ANY) + actual_param = self._filer.api.add.call_args[0][1] + expected_param = munch.Munch(dict(ip=self._hosts_ipaddr, hostName=self._hosts_hostname)) + self._assert_equal_objects(actual_param, expected_param) + self.assertEqual(ret, add_response) + + def test_delete_hosts_file_entry(self): + delete_response = 'Success' + self._init_filer(delete_response=delete_response) + ret = network.Network(self._filer).hosts.delete(self._hosts_hostname) + self._filer.api.delete.assert_called_once_with(f'/config/network/hostsFileEntries/{self._hosts_hostname}') + self.assertEqual(ret, delete_response)