| 1 |
#!/usr/bin/python |
| 2 |
# Copyright (c) 2016-2017 Hewlett Packard Enterprise Development LP |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
DOCUMENTATION = r""" |
| 9 |
module: oneview_datacenter_info |
| 10 |
short_description: Retrieve information about the OneView Data Centers |
| 11 |
description: |
| 12 |
- Retrieve information about the OneView Data Centers. |
| 13 |
requirements: |
| 14 |
- "hpOneView >= 2.0.1" |
| 15 |
author: |
| 16 |
- Alex Monteiro (@aalexmonteiro) |
| 17 |
- Madhav Bharadwaj (@madhav-bharadwaj) |
| 18 |
- Priyanka Sood (@soodpr) |
| 19 |
- Ricardo Galeno (@ricardogpsf) |
| 20 |
attributes: |
| 21 |
check_mode: |
| 22 |
version_added: 3.3.0 |
| 23 |
# This was backported to 2.5.4 and 1.3.11 as well, since this was a bugfix |
| 24 |
options: |
| 25 |
name: |
| 26 |
description: |
| 27 |
- Data Center name. |
| 28 |
type: str |
| 29 |
options: |
| 30 |
description: |
| 31 |
- 'Retrieve additional information. Options available: V(visualContent).' |
| 32 |
type: list |
| 33 |
elements: str |
| 34 |
|
| 35 |
extends_documentation_fragment: |
| 36 |
- community.general._oneview |
| 37 |
- community.general._oneview.factsparams |
| 38 |
- community.general._attributes |
| 39 |
- community.general._attributes.info_module |
| 40 |
""" |
| 41 |
|
| 42 |
EXAMPLES = r""" |
| 43 |
- name: Gather information about all Data Centers |
| 44 |
community.general.oneview_datacenter_info: |
| 45 |
hostname: 172.16.101.48 |
| 46 |
username: administrator |
| 47 |
password: my_password |
| 48 |
api_version: 500 |
| 49 |
delegate_to: localhost |
| 50 |
register: result |
| 51 |
|
| 52 |
- name: Print fetched information about Data Centers |
| 53 |
ansible.builtin.debug: |
| 54 |
msg: "{{ result.datacenters }}" |
| 55 |
|
| 56 |
- name: Gather paginated, filtered and sorted information about Data Centers |
| 57 |
community.general.oneview_datacenter_info: |
| 58 |
hostname: 172.16.101.48 |
| 59 |
username: administrator |
| 60 |
password: my_password |
| 61 |
api_version: 500 |
| 62 |
params: |
| 63 |
start: 0 |
| 64 |
count: 3 |
| 65 |
sort: 'name:descending' |
| 66 |
filter: 'state=Unmanaged' |
| 67 |
register: result |
| 68 |
|
| 69 |
- name: Print fetched information about paginated, filtered and sorted list of Data Centers |
| 70 |
ansible.builtin.debug: |
| 71 |
msg: "{{ result.datacenters }}" |
| 72 |
|
| 73 |
- name: Gather information about a Data Center by name |
| 74 |
community.general.oneview_datacenter_info: |
| 75 |
hostname: 172.16.101.48 |
| 76 |
username: administrator |
| 77 |
password: my_password |
| 78 |
api_version: 500 |
| 79 |
name: "My Data Center" |
| 80 |
delegate_to: localhost |
| 81 |
register: result |
| 82 |
|
| 83 |
- name: Print fetched information about Data Center found by name |
| 84 |
ansible.builtin.debug: |
| 85 |
msg: "{{ result.datacenters }}" |
| 86 |
|
| 87 |
- name: Gather information about the Data Center Visual Content |
| 88 |
community.general.oneview_datacenter_info: |
| 89 |
hostname: 172.16.101.48 |
| 90 |
username: administrator |
| 91 |
password: my_password |
| 92 |
api_version: 500 |
| 93 |
name: "My Data Center" |
| 94 |
options: |
| 95 |
- visualContent |
| 96 |
delegate_to: localhost |
| 97 |
register: result |
| 98 |
|
| 99 |
- name: Print fetched information about Data Center found by name |
| 100 |
ansible.builtin.debug: |
| 101 |
msg: "{{ result.datacenters }}" |
| 102 |
|
| 103 |
- name: Print fetched information about Data Center Visual Content |
| 104 |
ansible.builtin.debug: |
| 105 |
msg: "{{ result.datacenter_visual_content }}" |
| 106 |
""" |
| 107 |
|
| 108 |
RETURN = r""" |
| 109 |
datacenters: |
| 110 |
description: Has all the OneView information about the Data Centers. |
| 111 |
returned: Always, but can be null. |
| 112 |
type: dict |
| 113 |
|
| 114 |
datacenter_visual_content: |
| 115 |
description: Has information about the Data Center Visual Content. |
| 116 |
returned: When requested, but can be null. |
| 117 |
type: dict |
| 118 |
""" |
| 119 |
|
| 120 |
from ansible_collections.community.general.plugins.module_utils._oneview import OneViewModuleBase |
| 121 |
|
| 122 |
|
| 123 |
class DatacenterInfoModule(OneViewModuleBase): |
| 124 |
argument_spec = dict(name=dict(type="str"), options=dict(type="list", elements="str"), params=dict(type="dict")) |
| 125 |
|
| 126 |
def __init__(self): |
| 127 |
super().__init__( |
| 128 |
additional_arg_spec=self.argument_spec, |
| 129 |
supports_check_mode=True, |
| 130 |
) |
| 131 |
|
| 132 |
def execute_module(self): |
| 133 |
client = self.oneview_client.datacenters |
| 134 |
info = {} |
| 135 |
|
| 136 |
if self.module.params.get("name"): |
| 137 |
datacenters = client.get_by("name", self.module.params["name"]) |
| 138 |
|
| 139 |
if self.options and "visualContent" in self.options: |
| 140 |
if datacenters: |
| 141 |
info["datacenter_visual_content"] = client.get_visual_content(datacenters[0]["uri"]) |
| 142 |
else: |
| 143 |
info["datacenter_visual_content"] = None |
| 144 |
|
| 145 |
info["datacenters"] = datacenters |
| 146 |
else: |
| 147 |
info["datacenters"] = client.get_all(**self.facts_params) |
| 148 |
|
| 149 |
return dict(changed=False, **info) |
| 150 |
|
| 151 |
|
| 152 |
def main(): |
| 153 |
DatacenterInfoModule().run() |
| 154 |
|
| 155 |
|
| 156 |
if __name__ == "__main__": |
| 157 |
main() |