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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Extends support to below features for REST API version 2400.

#### Features supported
- Appliance Configuration Timeconfig
- Appliance Time and Locale Configuration

# 5.6.0
#### Notes
Expand Down
3 changes: 3 additions & 0 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
|<sub>/rest/appliance/trap-destinations/{id}</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/appliance/trap-destinations/{id}</sub> |PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/appliance/trap-destinations/{id}</sub> |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Appliance Time and Locale Configuration**
|<sub>/rest/appliance/configuration/time-locale</sub> |GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: |
|<sub>/rest/appliance/configuration/time-locale</sub> |POST | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: |
| **Certificates Server**
|<sub>/rest/certificates/servers</sub> |POST | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/certificates/https/remote/{address}</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down
44 changes: 24 additions & 20 deletions examples/appliance_time_and_locale_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2019] Hewlett Packard Enterprise Development LP
# (C) Copyright [2021] Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -27,38 +27,42 @@
}
}

options = {
"locale": "en_US.UTF-8",
"timezone": "UTC",
"ntpServers": ["127.0.0.1"],
}


# Try load config from a file (if there is a config file)
config = try_load_from_file(config)

oneview_client = OneViewClient(config)
time_and_locales = oneview_client.appliance_time_and_locale_configuration

# Lists the appliance time and locale configuration
time_and_locale = oneview_client.appliance_time_and_locale_configuration.get()
print("\n## Got appliance time and locale configurations successfully!")
pprint(time_and_locale)
time_and_locale = time_and_locales.get_all()
if time_and_locale:
print("\n## Got appliance time and locale configurations successfully!")
pprint(time_and_locale)
else:
# Create a time and locale with the options provided
time_and_locale = time_and_locales.create(data=options)
print("\n## Created appliance time and locale configurations successfully!")
pprint(time_and_locale.data)

# Backup original values
bkp = {}
bkp['ntpServers'] = time_and_locale['ntpServers']
bkp['locale'] = time_and_locale['locale']

# Update NTP servers and locale
time_and_locale = time_and_locale.data
# Set to use appliance local time and date server
time_and_locale['ntpServers'] = ['127.0.0.1']
# Set locale to Chinese (China) with charset UTF-8
time_and_locale['locale'] = 'zh_CN.UTF-8'
# Remove the date and time, we do not want to update it manually
time_and_locale.pop('dateTime')
time_and_locale = oneview_client.appliance_time_and_locale_configuration.update(time_and_locale)
print("\n## Updated appliance time and locale configurations successfully!")
pprint(time_and_locale)

time_and_locale = time_and_locales.create(data=time_and_locale)
print("\n## Created appliance time and locale configurations successfully!")
pprint(time_and_locale.data)
# Note: Changing the locale will only be fully effective after resetting the appliance

# Revert the changes made
time_and_locale['ntpServers'] = bkp['ntpServers']
time_and_locale['locale'] = bkp['locale']
time_and_locale.pop('dateTime')
time_and_locale = oneview_client.appliance_time_and_locale_configuration.update(time_and_locale)
time_and_locale = time_and_locales.create(data=options)
print("\n## Reverted appliance time and locale configurations successfully!")
pprint(time_and_locale)
pprint(time_and_locale.data)
4 changes: 1 addition & 3 deletions hpeOneView/oneview_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,9 +1128,7 @@ def appliance_time_and_locale_configuration(self):
Returns:
ApplianceTimeAndLocaleConfiguration:
"""
if not self.__appliance_time_and_locale_configuration:
self.__appliance_time_and_locale_configuration = ApplianceTimeAndLocaleConfiguration(self.__connection)
return self.__appliance_time_and_locale_configuration
return ApplianceTimeAndLocaleConfiguration(self.__connection)

@property
def versions(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2019] Hewlett Packard Enterprise Development LP
# (C) Copyright [2021] Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -24,45 +24,18 @@

standard_library.install_aliases()

from hpeOneView.resources.resource import ResourceClient
from hpeOneView.resources.resource import Resource


class ApplianceTimeAndLocaleConfiguration(object):
class ApplianceTimeAndLocaleConfiguration(Resource):
"""
ApplianceTimeAndLocaleConfiguration API client.

"""
URI = '/rest/appliance/configuration/time-locale'

DEFAULT_VALUES = {
'200': {"type": "TimeAndLocale"},
'300': {"type": "TimeAndLocale"}
}

def __init__(self, con):
self._client = ResourceClient(con, self.URI)

def get(self):
"""
Gets the appliance time and locale configuration.

Returns:
dict: ApplianceTimeAndLocaleConfiguration
"""
return self._client.get(self.URI)

def update(self, resource, timeout=-1):
"""
Updates the appliance time and locale configuration.

Args:
resource (dict): Object to update.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView, just stop waiting for its completion.

Returns:
dict: Updated appliance time and locale configuration.

"""
return self._client.create(resource, timeout=timeout, default_values=self.DEFAULT_VALUES)
def __init__(self, connection, data=None):
super(ApplianceTimeAndLocaleConfiguration, self).__init__(connection, data)
self.__default_values = {
"type": "TimeAndLocale"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2020] Hewlett Packard Enterprise Development LP
# (C) Copyright [2021] Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,21 +21,23 @@

from hpeOneView.connection import connection
from hpeOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration
from hpeOneView.resources.resource import ResourceClient
from hpeOneView.resources.resource import Resource


class ApplianceTimeAndLocaleConfigurationTest(unittest.TestCase):
def setUp(self):
self.host = '127.0.0.1'
self.connection = connection(self.host, 800)
self._time_and_locale = ApplianceTimeAndLocaleConfiguration(self.connection)
self.uri = "/rest/appliance/configuration/time-locale"
self._time_and_locale.data = {"uri": self.uri}

@mock.patch.object(ResourceClient, 'get')
@mock.patch.object(Resource, 'get_all')
def test_get_called_once(self, mock_get):
self._time_and_locale.get()
mock_get.assert_called_once_with('/rest/appliance/configuration/time-locale')
self._time_and_locale.get_all()
mock_get.assert_called_once_with()

@mock.patch.object(ResourceClient, 'create')
@mock.patch.object(Resource, 'create')
def test_update_called_once(self, mock_create):
resource = {
'dateTime': '2020-02-27T7:55:00.000Z',
Expand All @@ -45,5 +47,5 @@ def test_update_called_once(self, mock_create):
'timezone': 'UTC',
'uri': None
}
self._time_and_locale.update(resource)
mock_create.assert_called_once_with(resource, timeout=-1, default_values=self._time_and_locale.DEFAULT_VALUES)
self._time_and_locale.create(resource, timeout=-1)
mock_create.assert_called_once_with(resource, timeout=-1)
4 changes: 2 additions & 2 deletions tests/unit/test_oneview_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,9 @@ def test_appliance_time_and_locale_configuration_has_right_type(self):
self.assertIsInstance(self._oneview.appliance_time_and_locale_configuration,
ApplianceTimeAndLocaleConfiguration)

def test_lazy_loading_appliance_time_and_locale_configuration(self):
def test_appliance_time_and_locale_configuration_client(self):
appliance_time_and_locale_configuration = self._oneview.appliance_time_and_locale_configuration
self.assertEqual(appliance_time_and_locale_configuration, self._oneview.appliance_time_and_locale_configuration)
self.assertNotEqual(appliance_time_and_locale_configuration, self._oneview.appliance_time_and_locale_configuration)

def test_should_get_appliance_current_version_and_minimum_version(self):
self.assertIsInstance(self._oneview.versions,
Expand Down