-
Notifications
You must be signed in to change notification settings - Fork 27
Adding hypervisor managers for API 800, 1000 and 1200 #28
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b19e5a4
Adding hypervisor managers for API 800, 1000 and 1200
VenkateshRavula dd424cb
Added Unit Test for oneview client
VenkateshRavula d9b4f84
Refactored Hypervisor Manager code with latest changes
VenkateshRavula 9e62750
Resolved build check errors
VenkateshRavula 02a0cce
Merge branch 'master' into HypervisorManagers
VenkateshRavula 6f6361d
modified change log file
VenkateshRavula 5d11e03
Re-arranged endpoints in alphabetical order
VenkateshRavula a454648
Modified the oneview release version
VenkateshRavula df62e13
corrected oneview release version
VenkateshRavula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
137
tests/unit/resources/hypervisors/test_hypervisor_managers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.