Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit cbbde10

Browse files
committed
Added the Appliance Node Information resource
- Added get_status and get_version methods, binding to the respective uris - Added unit tests - Added new resource to CHANGELOG
1 parent 6c6c192 commit cbbde10

File tree

6 files changed

+187
-0
lines changed

6 files changed

+187
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v4.1.0 (Unreleased)
2+
3+
#### New Resources:
4+
- Appliance node information
15

26
# v4.0.0
37
#### Notes
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
###
3+
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
###
23+
24+
from pprint import pprint
25+
from hpOneView.oneview_client import OneViewClient
26+
from config_loader import try_load_from_file
27+
28+
config = {
29+
"ip": "<oneview_ip>",
30+
"credentials": {
31+
"userName": "<username>",
32+
"password": "<password>"
33+
}
34+
}
35+
36+
# Try load config from a file (if there is a config file)
37+
config = try_load_from_file(config)
38+
39+
oneview_client = OneViewClient(config)
40+
41+
# Get node status information from appliance
42+
print("\nGet node status information from appliance:\n ")
43+
node_status = oneview_client.appliance_node_information.get_status()
44+
pprint(node_status)
45+
46+
# Get node version information from appliance
47+
print("\nGet node version information from appliance\n")
48+
node_version = oneview_client.appliance_node_information.get_version()
49+
pprint(node_version)

hpOneView/oneview_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
from hpOneView.resources.uncategorized.os_deployment_servers import OsDeploymentServers
104104
from hpOneView.resources.security.certificate_rabbitmq import CertificateRabbitMQ
105105
from hpOneView.resources.security.users import Users
106+
from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation
106107
from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration
107108

108109
ONEVIEW_CLIENT_INVALID_PROXY = 'Invalid Proxy format'
@@ -184,6 +185,7 @@ def __init__(self, config):
184185
self.__certificate_rabbitmq = None
185186
self.__users = None
186187
self.__appliance_time_and_locale_configuration = None
188+
self.__appliance_node_information = None
187189
self.__backups = None
188190
# TODO: Implement: con.set_trusted_ssl_bundle(args.cert)
189191

@@ -1089,6 +1091,18 @@ def users(self):
10891091
self.__users = Users(self.__connection)
10901092
return self.__users
10911093

1094+
@property
1095+
def appliance_node_information(self):
1096+
"""
1097+
Gets the ApplianceNodeInformation API client.
1098+
1099+
Returns:
1100+
ApplianceNodeInformation:
1101+
"""
1102+
if not self.__appliance_node_information:
1103+
self.__appliance_node_information = ApplianceNodeInformation(self.__connection)
1104+
return self.__appliance_node_information
1105+
10921106
@property
10931107
def appliance_time_and_locale_configuration(self):
10941108
"""
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- coding: utf-8 -*-
2+
###
3+
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
###
23+
24+
from __future__ import absolute_import
25+
from __future__ import division
26+
from __future__ import print_function
27+
from __future__ import unicode_literals
28+
29+
from future import standard_library
30+
31+
standard_library.install_aliases()
32+
33+
from hpOneView.resources.resource import ResourceClient
34+
35+
36+
class ApplianceNodeInformation(object):
37+
"""
38+
ApplianceNodeInformation API client.
39+
40+
"""
41+
URI = '/rest/appliance/nodeinfo'
42+
43+
def __init__(self, con):
44+
self._client = ResourceClient(con, self.URI)
45+
46+
def get_status(self):
47+
"""
48+
Retrieves node's status information
49+
50+
Returns:
51+
dict: Node's status information
52+
"""
53+
uri = self.URI + '/status'
54+
return self._client.get(uri)
55+
56+
def get_version(self):
57+
"""
58+
Retrieves node's version information
59+
60+
Returns:
61+
dict: Node's version information
62+
"""
63+
uri = self.URI + '/version'
64+
return self._client.get(uri)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
###
3+
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
###
23+
24+
import unittest
25+
26+
import mock
27+
28+
from hpOneView.connection import connection
29+
from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation
30+
from hpOneView.resources.resource import ResourceClient
31+
32+
33+
class ApplianceTimeAndLocaleConfigurationTest(unittest.TestCase):
34+
def setUp(self):
35+
self.host = '127.0.0.1'
36+
self.connection = connection(self.host)
37+
self._node_information = ApplianceNodeInformation(self.connection)
38+
39+
@mock.patch.object(ResourceClient, 'get')
40+
def test_get_status_called_once(self, mock_get):
41+
self._node_information.get_status()
42+
mock_get.assert_called_once_with('/rest/appliance/nodeinfo/status')
43+
44+
@mock.patch.object(ResourceClient, 'get')
45+
def test_get_version_called_once(self, mock_get):
46+
self._node_information.get_version()
47+
mock_get.assert_called_once_with('/rest/appliance/nodeinfo/version')

tests/unit/test_oneview_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from hpOneView.resources.activity.events import Events
7575
from hpOneView.resources.security.certificate_rabbitmq import CertificateRabbitMQ
7676
from hpOneView.resources.security.users import Users
77+
from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation
7778
from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration
7879
from tests.test_utils import mock_builtin
7980

@@ -741,6 +742,14 @@ def test_lazy_loading_users(self):
741742
user = self._oneview.users
742743
self.assertEqual(user, self._oneview.users)
743744

745+
def test_appliance_node_information_has_right_type(self):
746+
self.assertIsInstance(self._oneview.appliance_node_information,
747+
ApplianceNodeInformation)
748+
749+
def test_lazy_loading_appliance_node_information(self):
750+
appliance_node_information = self._oneview.appliance_node_information
751+
self.assertEqual(appliance_node_information, self._oneview.appliance_node_information)
752+
744753
def test_appliance_time_and_locale_configuration_has_right_type(self):
745754
self.assertIsInstance(self._oneview.appliance_time_and_locale_configuration,
746755
ApplianceTimeAndLocaleConfiguration)

0 commit comments

Comments
 (0)