Skip to content

Commit

Permalink
Added hypervisor managers resource for API 800, 1000 and 1200
Browse files Browse the repository at this point in the history
  • Loading branch information
VenkateshRavula committed Apr 23, 2020
1 parent f4f0706 commit e13a0ed
Show file tree
Hide file tree
Showing 11 changed files with 818 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Ansible Modules for HPE OneView Change Log

## v5.5.0 (Unreleased)
This release extends the planned support of the modules to OneView REST API version 800 (OneView v4.1), 1000 (OneView v4.2) and 1200 (OneView v5.0).

#### Major changes
1. Extended support of planned modules to API800/1000/1200.
2. Modules implemented in this release requires hpOneView version 5.1.0.

#### Modules supported in this release
- oneview_hypervisor_manager
- oneview_hypervisor_manager_facts

## v5.4.0
This release extends the planned support of the modules to OneView REST API version 800 (OneView v4.1), 1000 (OneView v4.2) and 1200 (OneView v5.0).

Expand Down
6 changes: 6 additions & 0 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@
|<sub>/rest/firmware-drivers</sub> | POST | :white_check_mark: |
|<sub>/rest/firmware-drivers/{id}</sub> | GET | :white_check_mark: |
|<sub>/rest/firmware-drivers/{id}</sub> | DELETE | :white_check_mark: |
| **Hypervisor Managers**
|<sub>/rest/hypervisor-managers</sub> |POST | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers</sub> |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> |PUT | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/hypervisor-managers/{id}</sub> |DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **Interconnect Link Topologies** |
|<sub>/rest/interconnect-link-topologies</sub> | GET | :white_check_mark: |
|<sub>/rest/interconnect-link-topologies/{id}</sub> | GET | :white_check_mark: |
Expand Down
73 changes: 73 additions & 0 deletions examples/oneview_hypervisor_manager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
###
# Copyright (2016-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.
###
---
- hosts: all
vars:
config: "{{ playbook_dir }}/oneview_config.json"
hypervisor_manager_name: '172.18.13.11'
tasks:
- name: Create a Hypervisor Manager
oneview_hypervisor_manager:
config: "{{ config }}"
state: present
data:
name: "{{ hypervisor_manager_name }}"
displayName: 'vcenter'
hypervisorType: 'Vmware'
username: 'dcs'
password: 'dcs'
delegate_to: localhost
register: hyp_mgr_1

- name: Do nothing with the Hypervisor Manager when no changes are provided
oneview_hypervisor_manager:
config: "{{ config }}"
state: present
data:
name: "{{ hypervisor_manager_name }}"
displayName: 'vcenter'
hypervisorType: 'Vmware'
username: 'dcs'
password: 'dcs'
delegate_to: localhost

- name: Update the Hypervisor Manager changing the attribute displayName
oneview_hypervisor_manager:
config: "{{ config }}"
state: present
data:
name: "{{ hypervisor_manager_name }}"
displayName: 'vcenter renamed'
hypervisorType: 'Vmware'
username: 'dcs'
password: 'dcs'
delegate_to: localhost

- name: Delete the Hypervisor Manager
oneview_hypervisor_manager:
config: "{{ config }}"
state: absent
data: "{{ hyp_mgr_1.ansible_facts.hypervisor_manager }}"
delegate_to: localhost
register: deleted

- name: Do nothing when Hypervisor Manager is absent
oneview_hypervisor_manager:
config: "{{ config }}"
state: absent
data: "{{ hyp_mgr_1.ansible_facts.hypervisor_manager }}"
delegate_to: localhost
register: deleted
44 changes: 44 additions & 0 deletions examples/oneview_hypervisor_manager_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
###
# Copyright (2016-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.
###
---
- hosts: all
vars:
- config: "{{ playbook_dir }}/oneview_config.json"
tasks:
- name: Gather facts about all Hypervisor Managers
oneview_hypervisor_manager_facts:
config: "{{ config }}"
delegate_to: localhost

- debug: var=hypervisor_managers

- name: Gather paginated, filtered and sorted facts about Hypervisor Managers
oneview_hypervisor_manager_facts:
config: "{{ config }}"
params:
start: 0
count: 3
sort: 'name:descending'
filter: 'hypervisorType=Vmware'
- debug: var=hypervisor_managers

- name: Gather facts about a Hypervisor Manager by name
oneview_hypervisor_manager_facts:
config: "{{ config }}"
name: "172.18.13.11"
delegate_to: localhost

- debug: var=hypervisor_managers
149 changes: 149 additions & 0 deletions library/oneview_hypervisor_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-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.
###

ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}

DOCUMENTATION = '''
---
module: oneview_hypervisor_manager
short_description: Manage OneView Hypervisor Managers resources.
description:
- Provides an interface to manage Hypervisor Managers resources. Can create, update, and delete.
version_added: "2.4"
requirements:
- "python >= 2.7.9"
- "hpOneView >= 5.1.0"
author: "Venkatesh Ravula (@VenkateshRavula)"
options:
state:
description:
- Indicates the desired state for the Hypervisor Managers resource.
C(present) will ensure data properties are compliant with OneView.
C(absent) will remove the resource from OneView, if it exists.
choices: ['present', 'absent']
data:
description:
- List with the Hypervisor Managers properties.
required: true
extends_documentation_fragment:
- oneview
- oneview.validateetag
'''

EXAMPLES = '''
- name: Create a Hypervisor Manager
oneview_hypervisor_manager:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 1200
state: present
data:
name: '172.18.13.11'
displayName: 'vcenter'
hypervisorType: 'Vmware'
username: 'dcs'
password: 'dcs'
- name: Update the Hypervisor Manager display name to 'vcenter Renamed'
oneview_hypervisor_manager:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 1200
state: present
data:
name: '172.18.13.11'
displayName: 'vcenter Renamed'
hypervisorType: 'Vmware'
username: 'dcs'
password: 'dcs'
- name: Ensure that the Hypervisor Manager is present with hypervisorType 'Vmware'
oneview_hypervisor_manager:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 1200
state: present
data:
name: '172.18.13.11'
hypervisorType: 'Vmware'
- name: Ensure that the Hypervisor Manager is absent
oneview_hypervisor_manager:
hostname: 172.16.101.48
username: administrator
password: my_password
api_version: 1200
state: absent
data:
displayName: 'New hypervisor manager'
'''

RETURN = '''
hypervisor_manager:
description: Has the facts about the managed OneView Hypervisor Manager.
returned: On state 'present'. Can be null.
type: dict
'''

from ansible.module_utils.oneview import OneViewModule


class HypervisorManagerModule(OneViewModule):
MSG_CREATED = 'Hypervisor Manager created successfully.'
MSG_UPDATED = 'Hypervisor Manager updated successfully.'
MSG_DELETED = 'Hypervisor Manager deleted successfully.'
MSG_ALREADY_PRESENT = 'Hypervisor Manager is already present.'
MSG_ALREADY_ABSENT = 'Hypervisor Manager is already absent.'
RESOURCE_FACT_NAME = 'hypervisor_manager'

def __init__(self):
additional_arg_spec = dict(data=dict(required=True, type='dict'),
state=dict(
required=True,
choices=['present', 'absent']))

super(HypervisorManagerModule, self).__init__(additional_arg_spec=additional_arg_spec, validate_etag_support=True)
self.set_resource_object(self.oneview_client.hypervisor_managers)

def execute_module(self):
if self.state == 'present':
return self._present()
elif self.state == 'absent':
return self.resource_absent()

def _present(self):
scope_uris = self.data.pop('scopeUris', None)
result = self.resource_present(self.RESOURCE_FACT_NAME)

if scope_uris is not None:
result = self.resource_scopes_set(result, self.RESOURCE_FACT_NAME, scope_uris)
return result


def main():
HypervisorManagerModule().run()


if __name__ == '__main__':
main()

0 comments on commit e13a0ed

Please sign in to comment.