-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #497 from HewlettPackard/HypervisorClusterProfile
Added hypervisor cluster profile resource for API 800, 1000 and 1200
- Loading branch information
Showing
11 changed files
with
964 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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,78 @@ | ||
### | ||
# 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" | ||
cluster_profile_name: 'Test-1' | ||
tasks: | ||
- name: Create a Hypervisor Cluster Profile | ||
oneview_hypervisor_cluster_profile: | ||
config: "{{ config }}" | ||
state: present | ||
data: | ||
type: "HypervisorClusterProfileV3" | ||
name: "{{ cluster_profile_name }}" | ||
hypervisorManagerUri: '/rest/hypervisor-managers/ee73af7a-1775-44ba-8a66-d0479ec85678' | ||
path: 'DC1' | ||
hypervisorType: 'Vmware' | ||
hypervisorHostProfileTemplate: | ||
serverProfileTemplateUri: '/rest/server-profile-templates/f8e56c43-cfd7-436c-9812-394ecdbd32ed' | ||
hostprefix: 'Test-cluster-host' | ||
delegate_to: localhost | ||
register: hyp_cp | ||
|
||
- name: Do nothing with the Hypervisor Cluster Profile when no changes are provided | ||
oneview_hypervisor_cluster_profile: | ||
config: "{{ config }}" | ||
state: present | ||
data: | ||
name: "{{ cluster_profile_name }}" | ||
hypervisorManagerUri: '/rest/hypervisor-managers/ee73af7a-1775-44ba-8a66-d0479ec85678' | ||
path: 'DC1' | ||
hypervisorType: 'Vmware' | ||
delegate_to: localhost | ||
|
||
- name: Update the Hypervisor Cluster Profile changing the attribute name | ||
oneview_hypervisor_cluster_profile: | ||
config: "{{ config }}" | ||
state: present | ||
data: | ||
name: "{{ cluster_profile_name }}" | ||
newName: "HCP-renamed" | ||
hypervisorManagerUri: '/rest/hypervisor-managers/ee73af7a-1775-44ba-8a66-d0479ec85678' | ||
path: 'DC1' | ||
hypervisorType: 'Vmware' | ||
delegate_to: localhost | ||
register: hyp_cp | ||
|
||
- name: Delete the Hypervisor Cluster Profile | ||
oneview_hypervisor_cluster_profile: | ||
config: "{{ config }}" | ||
state: absent | ||
params: | ||
force: True | ||
data: "{{ hyp_cp.ansible_facts.hypervisor_cluster_profile }}" | ||
delegate_to: localhost | ||
register: deleted | ||
|
||
- name: Do nothing when Hypervisor Cluster Profile is absent | ||
oneview_hypervisor_cluster_profile: | ||
config: "{{ config }}" | ||
state: absent | ||
data: "{{ hyp_cp.ansible_facts.hypervisor_cluster_profile }}" | ||
delegate_to: localhost | ||
register: deleted |
This file contains 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,63 @@ | ||
### | ||
# 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 Cluster Profiles | ||
oneview_hypervisor_cluster_profile_facts: | ||
config: "{{ config }}" | ||
delegate_to: localhost | ||
|
||
- debug: var=hypervisor_cluster_profiles | ||
|
||
- name: Gather paginated, filtered and sorted facts about Hypervisor Cluster Profiles | ||
oneview_hypervisor_cluster_profile_facts: | ||
config: "{{ config }}" | ||
params: | ||
start: 0 | ||
count: 3 | ||
sort: 'name:descending' | ||
filter: 'hypervisorType=Vmware' | ||
- debug: msg="{{ hypervisor_cluster_profiles | map(attribute='name') | list }}" | ||
|
||
- name: Gather facts about a Hypervisor Cluster Profile by name | ||
oneview_hypervisor_cluster_profile_facts: | ||
config: "{{ config }}" | ||
name: "ClusterProfile" | ||
delegate_to: localhost | ||
|
||
- debug: var=hypervisor_cluster_profiles | ||
|
||
- name: Gather facts about a Hypervisor Cluster Profile by uri | ||
oneview_hypervisor_cluster_profile_facts: | ||
config: "{{ config }}" | ||
uri: "{{hypervisor_cluster_profiles[0]['uri']}}" | ||
delegate_to: localhost | ||
|
||
- debug: var=hypervisor_cluster_profiles | ||
|
||
- name: Gather all facts about a Hypervisor Cluster Profile | ||
oneview_hypervisor_cluster_profile_facts: | ||
config: "{{ config }}" | ||
name: "ClusterProfile" | ||
options: | ||
- compliancePreview | ||
delegate_to: localhost | ||
|
||
- debug: var=hypervisor_cluster_profiles | ||
- debug: var=hypervisor_cluster_profile_compliance_preview |
This file contains 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,176 @@ | ||
#!/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_cluster_profile | ||
short_description: Manage OneView Hypervisor Cluster Profiles resources. | ||
description: | ||
- Provides an interface to manage Hypervisor Cluster Profiles resources. Can create, update, and delete. | ||
version_added: "2.4" | ||
requirements: | ||
- "python >= 3.4.2" | ||
- "hpOneView >= 5.1.0" | ||
author: "Venkatesh Ravula (@VenkateshRavula)" | ||
options: | ||
state: | ||
description: | ||
- Indicates the desired state for the Hypervisor Cluster Profiles 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 Cluster Profiles properties. | ||
required: true | ||
extends_documentation_fragment: | ||
- oneview | ||
- oneview.validateetag | ||
''' | ||
|
||
EXAMPLES = ''' | ||
- name: Create a Hypervisor Cluster Profile | ||
oneview_hypervisor_cluster_profile: | ||
hostname: 172.16.101.48 | ||
username: administrator | ||
password: my_password | ||
api_version: 1200 | ||
state: present | ||
data: | ||
name: 'hcp' | ||
path: 'DC1' | ||
hypervisorType: 'Vmware' | ||
hypervisorManagerUri: '/rest/hypervisor-manager/rdy-dfdf12' | ||
hypervisorHostProfileTemplate: | ||
serverProfileTemplateUri: '/rest/server-profile-template/2323-32323' | ||
hostprefix: 'test-host' | ||
- name: Update the Hypervisor Cluster Profile name to 'hcp Renamed' | ||
oneview_hypervisor_cluster_profile: | ||
hostname: 172.16.101.48 | ||
username: administrator | ||
password: my_password | ||
api_version: 1200 | ||
state: present | ||
data: | ||
name: 'hcp Renamed' | ||
path: 'DC1' | ||
hypervisorType: 'Vmware' | ||
hypervisorManagerUri: '/rest/hypervisor-manager/rdy-dfdf12' | ||
params: | ||
force: True | ||
- name: Ensure that the Hypervisor Cluster Profile is absent | ||
oneview_hypervisor_cluster_profile: | ||
hostname: 172.16.101.48 | ||
username: administrator | ||
password: my_password | ||
api_version: 1200 | ||
state: absent | ||
data: | ||
name: 'hcp' | ||
''' | ||
|
||
RETURN = ''' | ||
hypervisor_cluster_profile: | ||
description: Has the facts about the managed OneView Hypervisor Cluster Profile. | ||
returned: On state 'present'. Can be null. | ||
type: dict | ||
''' | ||
|
||
from ansible.module_utils.oneview import OneViewModule, compare | ||
|
||
|
||
class HypervisorClusterProfileModule(OneViewModule): | ||
MSG_CREATED = 'Hypervisor Cluster Profile created successfully.' | ||
MSG_UPDATED = 'Hypervisor Cluster Profile updated successfully.' | ||
MSG_DELETED = 'Hypervisor Cluster Profile deleted successfully.' | ||
MSG_ALREADY_PRESENT = 'Hypervisor Cluster Profile is already present.' | ||
MSG_ALREADY_ABSENT = 'Hypervisor Cluster Profile is already absent.' | ||
|
||
def __init__(self): | ||
additional_arg_spec = dict(data=dict(required=True, type='dict'), | ||
params=dict(type='dict', required=False), | ||
state=dict( | ||
required=True, | ||
choices=['present', 'absent'])) | ||
|
||
super(HypervisorClusterProfileModule, self).__init__(additional_arg_spec=additional_arg_spec, validate_etag_support=True) | ||
self.set_resource_object(self.oneview_client.hypervisor_cluster_profiles) | ||
|
||
def execute_module(self): | ||
changed, msg, ansible_facts = False, '', {} | ||
params = self.module.params.get("params") | ||
self.params = params if params else {} | ||
|
||
if self.state == 'present': | ||
changed, msg, ansible_facts = self.__present() | ||
elif self.state == 'absent': | ||
changed, msg, ansible_facts = self.__absent() | ||
|
||
return dict(changed=changed, | ||
msg=msg, | ||
ansible_facts=ansible_facts) | ||
|
||
def __present(self): | ||
if self.current_resource: | ||
response = self.__update() | ||
else: | ||
response = self.__create(self.data) | ||
return response | ||
|
||
def __create(self, data): | ||
self.current_resource = self.resource_client.create(data) | ||
return True, self.MSG_CREATED, dict(hypervisor_cluster_profile=self.current_resource.data) | ||
|
||
def __absent(self): | ||
if self.current_resource: | ||
changed = True | ||
msg = self.MSG_DELETED | ||
self.current_resource.delete(**self.params) | ||
else: | ||
changed = False | ||
msg = self.MSG_ALREADY_ABSENT | ||
return changed, msg, dict(hypervisor_cluster_profile=None) | ||
|
||
def __update(self): | ||
if "newName" in self.data: | ||
self.data["name"] = self.data.pop("newName") | ||
|
||
merged_data = self.current_resource.data.copy() | ||
merged_data.update(self.data, **self.params) | ||
|
||
if not compare(self.current_resource.data, merged_data): | ||
self.current_resource.update(merged_data) | ||
return True, self.MSG_UPDATED, dict(hypervisor_cluster_profile=self.current_resource.data) | ||
else: | ||
return False, self.MSG_ALREADY_PRESENT, dict(hypervisor_cluster_profile=self.current_resource.data) | ||
|
||
|
||
def main(): | ||
HypervisorClusterProfileModule().run() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.