Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to additional APIs in SH #186

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docutils<0.18
sphinx==1.8.5
11 changes: 9 additions & 2 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

## HPE OneView

| Endpoints | Verb | V800 | V1000 | V1200 | V1600 | V1800 | V2000 | V2200 | V2400 | V2600 | V2800 | V3000 | V3200 |
| --------------------------------------------------------------------------------------- | ------------------ | :------------------: | :------------------:| :------------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: |
| Endpoints | Verb | V800 | V1000 | V1200 | V1600 | V1800 | V2000 | V2200 | V2400 | V2600 | V2800 | V3000 | V3200 | V3400 |
| --------------------------------------------------------------------------------------- | ------------------ | :------------------: | :------------------:| :------------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: | :-----------------: |
| **Appliance Configuration Timeconfig**
|<sub>/rest/appliance/configuration/timeconfig/locales</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: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Appliance Node Information**
Expand Down Expand Up @@ -360,6 +360,13 @@
|<sub>/rest/server-hardware/{id}/firmware</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: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/server-hardware/discovery</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: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/server-hardware/{id}/localStorageV2</sub> | POST | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :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/server-hardware/{id}/chassis</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :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/server-hardware/{id}/firmwareInventory</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :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/server-hardware/{id}/networkAdapters</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :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/server-hardware/{id}/powerSupplies</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :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/server-hardware/{id}/processors</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :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/server-hardware/{id}/softwareInventory</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :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/server-hardware/{id}/thermal</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: |
| **Server Hardware Types**
|<sub>/rest/server-hardware-types</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: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/server-hardware-types/{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: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down
70 changes: 70 additions & 0 deletions examples/server_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,73 @@
print("Server removed successfully")
except HPEOneViewException as e:
print(e.msg)

# This operation works from Oneview API Version 3400.
if oneview_client.api_version >= 3400 and server:
try:
# Gets the settings that describe about chasis configuration of server.
print("Get the settings that describe the chasis configuration of server")
server_chasisConf = server.get_chasis_configuration()
pprint(server_chasisConf)
except HPEOneViewException as e:
print(e.msg)

# This operation works from Oneview API Version 3400.
if oneview_client.api_version >= 3400 and server:
try:
# Gets the settings that describe about firmwareInventory configuration of server.
print("Get the settings that describe the firmwareInventory configuration of server")
server_firmwareConf = server.get_firmware_configuration()
pprint(server_firmwareConf)
except HPEOneViewException as e:
print(e.msg)

# This operation works from Oneview API Version 3400.
if oneview_client.api_version >= 3400 and server:
try:
# Gets the settings that describe about networkAdapters configuration of server.
print("Get the settings that describe the networkAdapters configuration of server")
server_networkAdaptersConf = server.get_network_adapters_configuration()
pprint(server_networkAdaptersConf)
except HPEOneViewException as e:
print(e.msg)

# This operation works from Oneview API Version 3400.
if oneview_client.api_version >= 3400 and server:
try:
# Gets the settings that describe about powerSupplies configuration of server.
print("Get the settings that describe the powerSupplies configuration of server")
server_powerSuppliesConf = server.get_power_supplies_configuration()
pprint(server_powerSuppliesConf)
except HPEOneViewException as e:
print(e.msg)

# This operation works from Oneview API Version 3400.
if oneview_client.api_version >= 3400 and server:
try:
# Gets the settings that describe about processors configuration of server.
print("Get the settings that describe the processors configuration of server")
server_processorsConf = server.get_processors_configuration()
pprint(server_processorsConf)
except HPEOneViewException as e:
print(e.msg)

# This operation works from Oneview API Version 3400.
if oneview_client.api_version >= 3400 and server:
try:
# Gets the settings that describe about softwareInventory configuration of server.
print("Get the settings that describe the softwareInventory configuration of server")
server_softwareInventoryConf = server.get_software_inventory_configuration()
pprint(server_softwareInventoryConf)
except HPEOneViewException as e:
print(e.msg)

# This operation works from Oneview API Version 3400.
if oneview_client.api_version >= 3400 and server:
try:
# Gets the settings that describe about thermal configuration of server.
print("Get the settings that describe the thermal configuration of server")
server_thermalConf = server.get_thermal_configuration()
pprint(server_thermalConf)
except HPEOneViewException as e:
print(e.msg)
36 changes: 24 additions & 12 deletions hpeOneView/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def create(self, data=None, uri=None, timeout=-1, custom_headers=None, force=Fal
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
custom_headers: Allows set specific HTTP headers.

Returns:
Created resource.
"""
Expand Down Expand Up @@ -202,11 +203,15 @@ def update(self, data=None, timeout=-1, custom_headers=None, force=False):
"""Makes a PUT request to update a resource when a request body is required.

Args:
data: Data to update the resource.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
data:
Data to update the resource.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
custom_headers: Allows to add custom HTTP headers.
force: Force the update operation.
custom_headers:
Allows to add custom HTTP headers.
force:
Force the update operation.

Returns:
A dict with the updated resource data.
Expand Down Expand Up @@ -451,6 +456,7 @@ def create(self, data=None, uri=None, timeout=-1, custom_headers=None, force=Fal
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
custom_headers: Allows set specific HTTP headers.

Returns:
Created resource.
"""
Expand Down Expand Up @@ -491,13 +497,18 @@ def update(self, resource, uri=None, force=False, timeout=-1, custom_headers=Non
"""Makes a PUT request to update a resource when a request body is required.

Args:
resource: Data to update the resource.
uri: Resource uri
force: If set to true, the operation completes despite any problems
resource:
Data to update the resource.
uri:
Resource uri
force:
If set to true, the operation completes despite any problems
with network connectivity or errors on the resource itself. The default is false.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
custom_headers: Allows to add custom HTTP headers.
custom_headers:
Allows to add custom HTTP headers.

Returns:
A dict with the updated resource data.
Expand Down Expand Up @@ -1364,8 +1375,7 @@ def update(self, resource, uri=None, force=False, timeout=-1, custom_headers=Non
'300': {"type": "logical-switch-groupV300"}
}

Returns:
Updated resource.
Returns: Updated resource.
"""
if not resource:
logger.exception(RESOURCE_CLIENT_RESOURCE_WAS_NOT_PROVIDED)
Expand Down Expand Up @@ -1849,9 +1859,11 @@ def merge_item(resource):

def transform_list_to_dict(list):
"""
Transforms a list into a dictionary, putting values as keys
Transforms a list into a dictionary, putting values as keys

Args:
id:

Returns:
dict: dictionary built
"""
Expand Down
79 changes: 78 additions & 1 deletion hpeOneView/resources/servers/server_hardware.py
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 Down Expand Up @@ -326,3 +326,80 @@ def get_local_storage(self, ip=None):
uri = "{}?ip={}".format(uri, ip)

return self._helper.do_get(uri)

@ensure_resource_client
def get_chassis(self):
"""
Gets the list of chassis values currently set on the physical server.

Returns:
dict: Dictionary of chassis values.
"""
uri = "{}/chassis".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_firmware_inventory(self):
"""
Gets the list of firmwareInventory values currently set on the physical server.

Returns:
dict: Dictionary of firmwareInventory values.
"""
uri = "{}/firmwareInventory".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_network_adapters(self):
"""
Gets the list of networkAdapters values currently set on the physical server.

Returns:
dict: Dictionary of networkAdapters values.
"""
uri = "{}/networkAdapters".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_power_supplies(self):
"""
Gets the list of powerSupplies values currently set on the physical server.

Returns:
dict: Dictionary of powerSupplies values.
"""
uri = "{}/powerSupplies".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_processors(self):
"""
Gets the list of processors values currently set on the physical server.

Returns:
dict: Dictionary of processors values.
"""
uri = "{}/processors".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_software_inventory(self):
"""
Gets the list of softwareInventory values currently set on the physical server.

Returns:
dict: Dictionary of softwareInventory values.
"""
uri = "{}/softwareInventory".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_thermal(self):
"""
Gets the list of thermal values currently set on the physical server.

Returns:
dict: Dictionary of thermal values.
"""
uri = "{}/thermal".format(self.data["uri"])
return self._helper.do_get(uri)
58 changes: 57 additions & 1 deletion tests/unit/resources/servers/test_server_hardware.py
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 Down Expand Up @@ -281,3 +281,59 @@ def test_get_local_storage_with_ip(self, mock_get):
self._server_hardware.get_local_storage(ip='172.16.8.4')

mock_get.assert_called_once_with(uri_rest_call)

@mock.patch.object(ResourceHelper, 'do_get')
def test_get_chassis(self, mock_get):
uri_rest_call = '{}/chassis'.format(self.uri)

self._server_hardware.get_chassis()

mock_get.assert_called_once_with(uri_rest_call)

@mock.patch.object(ResourceHelper, 'do_get')
def test_get_firmwareInventory(self, mock_get):
uri_rest_call = '{}/firmwareInventory'.format(self.uri)

self._server_hardware.get_firmware_inventory()

mock_get.assert_called_once_with(uri_rest_call)

@mock.patch.object(ResourceHelper, 'do_get')
def test_get_networkAdapters(self, mock_get):
uri_rest_call = '{}/networkAdapters'.format(self.uri)

self._server_hardware.get_network_adapters()

mock_get.assert_called_once_with(uri_rest_call)

@mock.patch.object(ResourceHelper, 'do_get')
def test_get_powerSupplies(self, mock_get):
uri_rest_call = '{}/powerSupplies'.format(self.uri)

self._server_hardware.get_power_supplies()

mock_get.assert_called_once_with(uri_rest_call)

@mock.patch.object(ResourceHelper, 'do_get')
def test_get_processors(self, mock_get):
uri_rest_call = '{}/processors'.format(self.uri)

self._server_hardware.get_processors()

mock_get.assert_called_once_with(uri_rest_call)

@mock.patch.object(ResourceHelper, 'do_get')
def test_get_thermal(self, mock_get):
uri_rest_call = '{}/thermal'.format(self.uri)

self._server_hardware.get_thermal()

mock_get.assert_called_once_with(uri_rest_call)

@mock.patch.object(ResourceHelper, 'do_get')
def test_get_softwareInventory(self, mock_get):
uri_rest_call = '{}/softwareInventory'.format(self.uri)

self._server_hardware.get_software_inventory()

mock_get.assert_called_once_with(uri_rest_call)