Skip to content
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 5.1.0 (unreleased version)
#### Notes
Extends support of the SDK to OneView REST API version 800, 1000 and 1200.

#### Features supported
- Hypervisor Managers

# 5.0.0
#### Notes
Extends support of the SDK to OneView REST API version 1200 (OneView v5.00).
Expand Down
7 changes: 6 additions & 1 deletion endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
|<sub>/rest/fcoe-networks/{id}</sub> | PATCH | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: |
|<sub>/rest/fcoe-networks/{id}</sub> | PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/fcoe-networks/{id}</sub> | DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Hypervisor Managers**
|<sub>/rest/hypervisor-managers</sub> |POST | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> |PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> |DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Interconnects**
|<sub>/rest/interconnects</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/interconnects/{id}</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down Expand Up @@ -307,7 +313,6 @@
|<sub>/rest/storage-volumes/{id}/snapshots/{snapshotId}</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/storage-volumes/{id}/snapshots/{snapshotId}</sub> | DELETE | :white_check_mark: | :white_check_mark: | :white_check_mark: |


## HPE Synergy Image Streamer

| Endpoints | Verb | V800 | V1000 | V1020
Expand Down
93 changes: 93 additions & 0 deletions examples/hypervisor_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2020] 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

from pprint import pprint

from config_loader import try_load_from_file
from hpOneView.oneview_client import OneViewClient

config = {
"ip": "",
"credentials": {
"userName": "",
"password": ""
}
}

options = {
"type": "HypervisorManagerV2",
"name": "172.18.13.11",
"displayName": "vcenter",
"hypervisorType": "Vmware",
"username": "dcs",
"password": "dcs",
"initialScopeUris": []
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient.config()
hypervisor_managers = oneview_client.hypervisor_managers

# Find recently created hypervisor manager by name
print("\nGet Hypervisor Manager by name")
hypervisor_manager = hypervisor_managers.get_by_name(options['name'])

if hypervisor_manager:
print("\nFound hypervisor-manager by name: {}.\n uri = {}".format(hypervisor_manager.data['name'], hypervisor_manager.data['uri']))
else:
# Create a HypervisorManager with the options provided
hypervisor_manager = hypervisor_managers.create(data=options)
print("\nCreated a hypervisor-manager with name: {}.\n uri = {}".format(hypervisor_manager.data['name'], hypervisor_manager.data['uri']))

# Get all, with defaults
print("\nGet all hypervisor managers")
hyp_managers_all = hypervisor_managers.get_all()
for hyp in hyp_managers_all:
print(' - {}'.format(hyp['name']))

# Get the first 10 records
print("\nGet the first ten hypervisor managers")
hyp_mgrs_top_ten = hypervisor_managers.get_all(0, 10)
for hyp in hyp_mgrs_top_ten:
print(' - {}'.format(hyp['name']))

# Filter by hypervisor type
print("\nGet all hypervisor managers filtering by hypervisor type")
hyp_mgrs_filtered = hypervisor_managers.get_all(filter="\"'hypervisorType'='Vmware'\"")
for hyp in hyp_mgrs_filtered:
print("Hypervisor with type 'Vmware' - {}".format(hyp['name']))

# Get all sorting by name descending
print("\nGet all hypervisor managers sorting by name")
hyp_mgrs_sorted = hypervisor_managers.get_all(sort='name:descending')
pprint(hyp_mgrs_sorted)

# Get by uri
print("\nGet a hypervisor managers by uri")
hyp_mgrs_by_uri = hypervisor_managers.get_by_uri(hypervisor_manager.data['uri'])
pprint(hyp_mgrs_by_uri.data)

# Update display name of recently created hypervisor manager
data_to_update = {'displayName': 'Updated vcenter'}
hypervisor_manager.update(data=data_to_update)
print("\nUpdated hypervisor manager {} successfully.\n uri = {}".format(hypervisor_manager.data['name'], hypervisor_manager.data['uri']))
print(" with attribute 'displayName': {}".format(hypervisor_manager.data['displayName']))

# Delete the created hypervisor manager
hypervisor_manager.delete()
print("\nSuccessfully deleted hypervisor manager")
6 changes: 5 additions & 1 deletion hpOneView/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,11 @@ def disable_etag_validation(self):
# ------------------------------------
# Uncategorized
# ------------------------------------
'unmanaged-devices': '/rest/unmanaged-devices'
'unmanaged-devices': '/rest/unmanaged-devices',
# ------------------------------------
# Hypervisors
# ------------------------------------
'hypervisor-managers': '/rest/hypervisor-managers'
}

############################################################################
Expand Down
12 changes: 12 additions & 0 deletions hpOneView/oneview_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation
from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration
from hpOneView.resources.settings.versions import Versions
from hpOneView.resources.hypervisors.hypervisor_managers import HypervisorManagers

ONEVIEW_CLIENT_INVALID_PROXY = 'Invalid Proxy format'

Expand Down Expand Up @@ -198,6 +199,7 @@ def __init__(self, config):
self.__backups = None
self.__login_details = None
self.__licenses = None
self.__hypervisor_managers = None

@classmethod
def from_json_file(cls, file_name):
Expand Down Expand Up @@ -1171,3 +1173,13 @@ def licenses(self):
if not self.__licenses:
self.__licenses = Licenses(self.__connection)
return self.__licenses

@property
def hypervisor_managers(self):
"""
Gets the Hypervisor Managers API client.

Returns:
HypervisorManagers
"""
return HypervisorManagers(self.__connection)
Empty file.
75 changes: 75 additions & 0 deletions hpOneView/resources/hypervisors/hypervisor_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2020] 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

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 Resource


class HypervisorManagers(Resource):
"""
Hypervisor Managers API client.

"""
URI = '/rest/hypervisor-managers'

DEFAULT_VALUES = {
'800': {"type": "HypervisorManagerV2"},
'1000': {"type": "HypervisorManagerV2"},
'1200': {"type": "HypervisorManagerV2"}
}

def __init__(self, connection, data=None):
super(HypervisorManagers, self).__init__(connection, data)

def get_all(self, start=0, count=-1, filter='', sort='', query='', scope_uris=''):
"""
Gets a list of Hypervisor Managers based on optional sorting and filtering, and constrained by start and count
parameters.

Args:
start:
The first item to return, using 0-based indexing.
If not specified, the default is 0 - start with the first available item.
count:
The number of resources to return. A count of -1 requests all items.
The actual number of items in the response might differ from the requested
count if the sum of start and count exceeds the total number of items.
filter (list or str):
A general filter/query string to narrow the list of items returned. The
default is no filter; all resources are returned.
sort:
The sort order of the returned data set. By default, the sort order is based
on create time with the oldest entry first.
query:
A general query string to narrow the list of resources returned. The default
is no query - all resources are returned.
scope_uris:
An expression to restrict the resources returned according to the scopes to
which they are assigned.

Returns:
list: List of Hypervisor Managers
"""
return self._helper.get_all(start, count, filter=filter, sort=sort, query=query, scope_uris=scope_uris)
Empty file.
137 changes: 137 additions & 0 deletions tests/unit/resources/hypervisors/test_hypervisor_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2020] 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###

from unittest import TestCase

import mock

from hpOneView.connection import connection
from hpOneView.resources.hypervisors.hypervisor_managers import HypervisorManagers
from hpOneView.resources.resource import Resource, ResourceHelper


class HypervisorManagersTest(TestCase):

def setUp(self):
self.host = '127.0.0.1'
self.connection = connection(self.host)
self._hypervisor_managers = HypervisorManagers(self.connection)
self.uri = "/rest/hypervisor-managers/f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
self._hypervisor_managers.data = {"uri": self.uri}

@mock.patch.object(Resource, 'create')
def test_create_called_once(self, mock_create):
resource = dict(
type="HypervisorManagerV2",
name="172.18.13.11",
displayName="vcenter",
hypervisorType="Vmware",
username="dcs",
password="dcs",
initialScopeUris=[],
)

resource_rest_call = resource.copy()
mock_create.return_value = {}

self._hypervisor_managers.create(resource, timeout=70)
mock_create.assert_called_once_with(resource_rest_call, timeout=70)

@mock.patch.object(Resource, 'create')
def test_add_called_once_with_defaults(self, mock_create):
resource = dict(
type="HypervisorManagerV2",
name="172.18.13.11",
displayName="vcenter",
hypervisorType="Vmware",
username="dcs",
password="dcs",
initialScopeUris=[],
)

resource_rest_call = resource.copy()
mock_create.return_value = {}

self._hypervisor_managers.create(resource)
mock_create.assert_called_once_with(resource_rest_call)

@mock.patch.object(ResourceHelper, 'get_all')
def test_get_all_called_once(self, mock_get_all):
filter = 'name=TestName'
sort = 'name:ascending'
query = 'query'
scope_uris = 'rest/scopes/cd237b60-09e2-45c4-829e-082e318a6d2a'

self._hypervisor_managers.get_all(2, 500, filter=filter, sort=sort, query=query, scope_uris=scope_uris)
mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort, query=query, scope_uris=scope_uris)

@mock.patch.object(ResourceHelper, 'get_all')
def test_get_all_called_once_with_default(self, mock_get_all):
self._hypervisor_managers.get_all()
mock_get_all.assert_called_once_with(0, -1, filter='', sort='', query='', scope_uris='')

@mock.patch.object(Resource, 'get_by_uri')
def test_get_by_uri_called_once(self, mock_get_by_uri):
uri = "/rest/hypervisor-managers/f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
self._hypervisor_managers.get_by_uri(uri)
mock_get_by_uri.assert_called_once_with(uri)

@mock.patch.object(Resource, 'get_by')
def test_get_by_called_once(self, mock_get_by):
hypervisor_managers = [{'name': 'name1', 'displayName': 'display1'}, {'name': 'name2', 'displayName': 'display2'}]
mock_get_by.return_value = hypervisor_managers
result = self._hypervisor_managers.get_by("displayName", "display1")
mock_get_by.assert_called_once_with("displayName", "display1")
self.assertEqual(result, hypervisor_managers)

@mock.patch.object(Resource, 'get_by')
def test_get_by_name_called_once(self, mock_get_by):
hypervisor_managers = [{'name': 'test name1', 'id': 1}, {'name': 'test name2', 'id': 2}]
mock_get_by.return_value = hypervisor_managers
result = self._hypervisor_managers.get_by_name("test name1")
mock_get_by.assert_called_once_with("name", "test name1")
self.assertEqual(result.data['id'], 1)

@mock.patch.object(Resource, 'ensure_resource_data')
@mock.patch.object(ResourceHelper, 'update')
def test_update_called_once_with_default(self, mock_update, mock_ensure_client):
resource = {
"name": "HypervisorManagerNew",
"uri": self.uri
}
self._hypervisor_managers.update(resource)
mock_update.assert_called_once_with(resource, self.uri, False, -1, None)

@mock.patch.object(Resource, 'ensure_resource_data')
@mock.patch.object(ResourceHelper, 'update')
def test_update_called_once(self, mock_update, mock_ensure_client):
resource = {
"uri": self.uri,
"name": "NewHypervisorManager"
}
self._hypervisor_managers.update(resource, 70)
mock_update.assert_called_once_with(resource, self.uri, False, 70, None)

@mock.patch.object(ResourceHelper, 'delete')
def test_delete_called_once(self, mock_delete):
self._hypervisor_managers.delete(force=False)
mock_delete.assert_called_once_with(self.uri, custom_headers=None, force=False, timeout=-1)

@mock.patch.object(ResourceHelper, 'delete')
def test_delete_called_once_with_force(self, mock_delete):
self._hypervisor_managers.delete(force=True)
mock_delete.assert_called_once_with(self.uri, custom_headers=None, force=True, timeout=-1)
Loading