diff --git a/endpoints-support.md b/endpoints-support.md index d1e7df72..54a09966 100755 --- a/endpoints-support.md +++ b/endpoints-support.md @@ -27,6 +27,8 @@ |/rest/alerts/{id} |PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |/rest/alerts/{id} |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | |/rest/alerts/AlertChangeLog/{id} |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| **Appliance Network Interfaces** | +|/rest/appliance/network-interfaces |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | **Appliance Time and Locale Configuration** | |/rest/appliance/configuration/time-locale |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | |/rest/appliance/configuration/time-locale |POST | :white_check_mark: | :white_check_mark: | :white_check_mark: | diff --git a/examples/appliance_network_interfaces.py b/examples/appliance_network_interfaces.py new file mode 100644 index 00000000..f1c93f74 --- /dev/null +++ b/examples/appliance_network_interfaces.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +### +# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +### + +from pprint import pprint +from hpOneView.oneview_client import OneViewClient +from config_loader import try_load_from_file + +config = { + "ip": "", + "credentials": { + "userName": "", + "password": "" + } +} + +# Try load config from a file (if there is a config file) +config = try_load_from_file(config) + +oneview_client = OneViewClient(config) + +# Get network interfaces information from appliance +print("\nnetwork interfaces information from appliance:\n ") +network_interfaces = oneview_client.appliance_network_interfaces.get_all() +pprint(network_interfaces) diff --git a/hpOneView/oneview_client.py b/hpOneView/oneview_client.py index 6c1a7bf5..4ab8f7e1 100755 --- a/hpOneView/oneview_client.py +++ b/hpOneView/oneview_client.py @@ -107,6 +107,7 @@ from hpOneView.resources.security.roles import Roles from hpOneView.resources.security.users import Users from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation +from hpOneView.resources.settings.appliance_network_interfaces import ApplianceNetworkInterfaces from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration from hpOneView.resources.settings.versions import Versions @@ -192,6 +193,7 @@ def __init__(self, config): self.__users = None self.__appliance_time_and_locale_configuration = None self.__appliance_node_information = None + self.__appliance_network_interfaces = None self.__versions = None self.__backups = None self.__login_details = None @@ -1129,6 +1131,18 @@ def appliance_node_information(self): self.__appliance_node_information = ApplianceNodeInformation(self.__connection) return self.__appliance_node_information + @property + def appliance_network_interfaces(self): + """ + Gets the ApplianceNetworkInterfaces API client. + + Returns: + ApplianceNetworkInterfaces: + """ + if not self.__appliance_network_interfaces: + self.__appliance_network_interfaces = ApplianceNetworkInterfaces(self.__connection) + return self.__appliance_network_interfaces + @property def appliance_time_and_locale_configuration(self): """ diff --git a/hpOneView/resources/settings/appliance_network_interfaces.py b/hpOneView/resources/settings/appliance_network_interfaces.py new file mode 100644 index 00000000..d1c40551 --- /dev/null +++ b/hpOneView/resources/settings/appliance_network_interfaces.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +### +# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +### + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future import standard_library + +standard_library.install_aliases() + +from hpOneView.resources.resource import ResourceClient + + +class ApplianceNetworkInterfaces(object): + """ + ApplianceNetworkInformation API client. + """ + URI = '/rest/appliance/network-interfaces' + + def __init__(self, con): + self._client = ResourceClient(con, self.URI) + + def get_all(self): + """ + Retrieves applicance network information + Returns: + dict: Appliance's network information + """ + uri = self.URI + return self._client.get(uri) diff --git a/tests/unit/resources/settings/test_appliance_network_interfaces.py b/tests/unit/resources/settings/test_appliance_network_interfaces.py new file mode 100644 index 00000000..f77cbfc2 --- /dev/null +++ b/tests/unit/resources/settings/test_appliance_network_interfaces.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +### +# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +### + +import unittest + +import mock + +from hpOneView.connection import connection +from hpOneView.resources.settings.appliance_network_interfaces import ApplianceNetworkInterfaces +from hpOneView.resources.resource import ResourceClient + + +class ApplianceNetworkInterfacesTest(unittest.TestCase): + def setUp(self): + self.host = '127.0.0.1' + self.connection = connection(self.host) + self._network_interfaces = ApplianceNetworkInterfaces(self.connection) + + @mock.patch.object(ResourceClient, 'get') + def test_get_status_called_once(self, mock_get): + self._network_interfaces.get_all() + mock_get.assert_called_once_with('/rest/appliance/network-interfaces') diff --git a/tests/unit/test_oneview_client.py b/tests/unit/test_oneview_client.py index f3ae5b7f..cc0c03b4 100755 --- a/tests/unit/test_oneview_client.py +++ b/tests/unit/test_oneview_client.py @@ -77,6 +77,7 @@ from hpOneView.resources.security.roles import Roles from hpOneView.resources.security.users import Users from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation +from hpOneView.resources.settings.appliance_network_interfaces import ApplianceNetworkInterfaces from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration from hpOneView.resources.settings.versions import Versions from tests.test_utils import mock_builtin @@ -890,6 +891,14 @@ def test_lazy_loading_appliance_node_information(self): appliance_node_information = self._oneview.appliance_node_information self.assertEqual(appliance_node_information, self._oneview.appliance_node_information) + def test_appliance_network_interfaces_has_right_type(self): + self.assertIsInstance(self._oneview.appliance_network_interfaces, + ApplianceNetworkInterfaces) + + def test_lazy_loading_appliance_network_interfaces(self): + appliance_network_interfaces = self._oneview.appliance_network_interfaces + self.assertEqual(appliance_network_interfaces, self._oneview.appliance_network_interfaces) + def test_appliance_time_and_locale_configuration_has_right_type(self): self.assertIsInstance(self._oneview.appliance_time_and_locale_configuration, ApplianceTimeAndLocaleConfiguration) diff --git a/tox.ini b/tox.ini index 68c4de6c..60300cd5 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ envlist = docs, py34, py36, py27-coverage, py27-flake8 skip_missing_interpreters = true [flake8] -ignore = E402 +ignore = E402,W504,W605 max-line-length = 160 exclude = hpOneView/__init__.py max-complexity = 14