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

Commit e274761

Browse files
authored
Merge pull request #334 from HewlettPackard/new_resource/version
Add support to the Version resource
2 parents e29f507 + 127ad73 commit e274761

File tree

7 files changed

+171
-3
lines changed

7 files changed

+171
-3
lines changed

CHANGELOG.md

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 4.4.0(Unreleased)
2+
#### New Resources:
3+
- Version
4+
15
# 4.3.0
26
#### Notes
37
Added endpoints-support.md to track the supported and tested endpoints for the different HPE OneView REST APIs
@@ -130,7 +134,7 @@ Bugfixes and corrections.
130134
- Developer friendly interface
131135
- Standardization for building new endpoint clients
132136
- Core client implementation
133-
- Support for Pythons logging library
137+
- Support for Python's logging library
134138
- Added possibility to load connection settings from configuration file
135139
- Simple access to OneView API endpoints through OneViewClient module
136140
3. Added developer-focused samples

endpoints-support.md

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
|<sub>/rest/logical-switches/{id}</sub> |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: |
252252
|<sub>/rest/logical-switches/{id}/refresh</sub> |PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: |
253253
| **Login Details** |
254-
|<sub>/rest/logindetails</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark:
254+
|<sub>/rest/logindetails</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark:
255255
| **Managed SANs** |
256256
|<sub>/rest/fc-sans/managed-sans</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
257257
|<sub>/rest/fc-sans/managed-sans/{id}</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
@@ -511,7 +511,7 @@
511511
|<sub>/rest/uplink-sets/{id}</sub> | PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: |
512512
|<sub>/rest/uplink-sets/{id}</sub> | DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: |
513513
| **Version** |
514-
|<sub>/rest/version</sub> | GET | | | |
514+
|<sub>/rest/version</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
515515

516516

517517
## HPE Synergy Image Streamer

examples/versions.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 the current version and the minimum version
42+
print("Get the current version and the minimum version")
43+
version = oneview_client.versions.get_version()
44+
pprint(version)

hpOneView/oneview_client.py

100644100755
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
from hpOneView.resources.security.users import Users
108108
from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation
109109
from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration
110+
from hpOneView.resources.settings.versions import Versions
110111

111112
ONEVIEW_CLIENT_INVALID_PROXY = 'Invalid Proxy format'
112113

@@ -189,6 +190,7 @@ def __init__(self, config):
189190
self.__users = None
190191
self.__appliance_time_and_locale_configuration = None
191192
self.__appliance_node_information = None
193+
self.__versions = None
192194
self.__backups = None
193195
self.__login_details = None
194196
# TODO: Implement: con.set_trusted_ssl_bundle(args.cert)
@@ -1132,6 +1134,18 @@ def appliance_time_and_locale_configuration(self):
11321134
self.__appliance_time_and_locale_configuration = ApplianceTimeAndLocaleConfiguration(self.__connection)
11331135
return self.__appliance_time_and_locale_configuration
11341136

1137+
@property
1138+
def versions(self):
1139+
"""
1140+
Gets the Version API client.
1141+
1142+
Returns:
1143+
Version:
1144+
"""
1145+
if not self.__versions:
1146+
self.__versions = Versions(self.__connection)
1147+
return self.__versions
1148+
11351149
@property
11361150
def backups(self):
11371151
"""
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 Versions(object):
37+
"""
38+
Version API client. It indicates the range of API versions supported by the appliance.
39+
40+
"""
41+
URI = '/rest/version'
42+
43+
def __init__(self, con):
44+
self._client = ResourceClient(con, self.URI)
45+
46+
def get_version(self):
47+
"""
48+
Returns the range of possible API versions supported by the appliance.
49+
The response contains the current version and the minimum version.
50+
The current version is the recommended version to specify in the REST header.
51+
The other versions are supported for backward compatibility, but might not support the most current features.
52+
53+
Returns:
54+
dict: The minimum and maximum supported API versions.
55+
"""
56+
version = self._client.get(self.URI)
57+
return version
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
import mock
24+
import unittest
25+
26+
from hpOneView.connection import connection
27+
from hpOneView.resources.settings.versions import Versions
28+
from hpOneView.resources.resource import ResourceClient
29+
30+
31+
class VersionsTest(unittest.TestCase):
32+
def setUp(self):
33+
self.host = '127.0.0.1'
34+
self.connection = connection(self.host)
35+
self._client = Versions(self.connection)
36+
37+
@mock.patch.object(ResourceClient, 'get')
38+
def test_get_with_uri_called_once(self, mock_get):
39+
self._client.get_version()
40+
mock_get.assert_called_once_with('/rest/version')

tests/unit/test_oneview_client.py

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
from hpOneView.resources.security.users import Users
7979
from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation
8080
from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration
81+
from hpOneView.resources.settings.versions import Versions
8182
from tests.test_utils import mock_builtin
8283

8384
OS_ENVIRON_CONFIG_MINIMAL = {
@@ -883,3 +884,11 @@ def test_appliance_time_and_locale_configuration_has_right_type(self):
883884
def test_lazy_loading_appliance_time_and_locale_configuration(self):
884885
appliance_time_and_locale_configuration = self._oneview.appliance_time_and_locale_configuration
885886
self.assertEqual(appliance_time_and_locale_configuration, self._oneview.appliance_time_and_locale_configuration)
887+
888+
def test_should_get_appliance_current_version_and_minimum_version(self):
889+
self.assertIsInstance(self._oneview.versions,
890+
Versions)
891+
892+
def test_lazy_loading_appliance_version_information(self):
893+
versions = self._oneview.versions
894+
self.assertEqual(versions, self._oneview.versions)

0 commit comments

Comments
 (0)