Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cterasdk/edge/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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}')
25 changes: 25 additions & 0 deletions docs/source/UserGuides/Edge/Configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------

Expand Down
5 changes: 3 additions & 2 deletions docs/source/UserGuides/Miscellaneous/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/ctera/ctera-python-sdk/pull/305>`_
Related issues and pull requests on GitHub: `#306 <https://github.com/ctera/ctera-python-sdk/pull/306>`_,
`#307 <https://github.com/ctera/ctera-python-sdk/pull/307>`_


2.20.14
Expand All @@ -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 <https://github.com/ctera/ctera-python-sdk/pull/304>`_
Related issues and pull requests on GitHub: `#305 <https://github.com/ctera/ctera-python-sdk/pull/305>`_

2.20.13
-------
Expand Down
27 changes: 27 additions & 0 deletions tests/ut/edge/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)