Skip to content
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

[omevv compliance info]: Fetch the firmware compliance info of a cluster or host in a cluster #762

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions docs/modules/omevv_firmware_compliance_info.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
.. _omevv_firmware_compliance_info_module:


omevv_firmware_compliance_info -- Retrieve firmware compliance report.
======================================================================

.. contents::
:local:
:depth: 1


Synopsis
--------

This module allows you to retrieve firmware compliance reports of all the hosts of the cluster, a specific host of the cluster, or multiple clusters.



Requirements
------------
The below requirements are needed on the host that executes this module.

- python \>= 3.9.6



Parameters
----------

clusters (optional, list, None)
Cluster details to retrieve the firmware compliance report.


cluster_name (True, str, None)
Cluster name of the hosts for which the firmware compliance report should be retrieved.

If \ :emphasis:`servicetags`\ or \ :emphasis:`hosts`\ is provided, then the firmware compliance report of only the specified hosts is retrieved and displayed.


servicetags (optional, list, None)
The service tag of the hosts for which the firmware compliance reports must be retrieved.


hosts (optional, list, None)
The IP address or hostname of the hosts for which the firmware compliance reports must be retrieved.



hostname (True, str, None)
IP address or hostname of the OpenManage Enterprise Modular.


vcenter_username (False, str, None)
Username for OpenManage Enterprise Integration for VMware vCenter (OMEVV).

If the username is not provided, then the environment variable \ :envvar:`OMEVV\_VCENTER\_USERNAME`\ is used.

Example: export OMEVV\_VCENTER\_USERNAME=username


vcenter_password (False, str, None)
Password for OpenManage Enterprise Integration for VMware vCenter (OMEVV).

If the password is not provided, then the environment variable \ :envvar:`OMEVV\_VCENTER\_PASSWORD`\ is used.

Example: export OMEVV\_VCENTER\_PASSWORD=password


vcenter_uuid (False, str, None)
Universally Unique Identifier (UUID) of vCenter.

vCenter UUID details can be retrieved using \ :ref:`dellemc.openmanage.omevv\_vcenter\_info <ansible_collections.dellemc.openmanage.omevv_vcenter_info_module>`\ module.

If UUID is not provided, then the environment variable \ :envvar:`OMEVV\_VCENTER\_UUID`\ is used.

Example: export OMEVV\_VCENTER\_UUID=uuid


port (optional, int, 443)
OpenManage Enterprise HTTPS port.


validate_certs (optional, bool, True)
Whether to check SSL certificate. - If \ :literal:`true`\ , the SSL certificates will be validated. - If \ :literal:`false`\ , the SSL certificates will not be validated.


ca_path (optional, path, None)
The Privacy Enhanced Mail (PEM) file that contains a CA certificate to be used for the validation.


timeout (optional, int, 30)
The socket level timeout in seconds.





Notes
-----

.. note::
- Run this module from a system that has direct access to Dell OpenManage Enterprise.




Examples
--------

.. code-block:: yaml+jinja


---
- name: Retrieve a firmware compliance report of all the clusters
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"

- name: Retrieve a firmware compliance report of all the hosts in a specific cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a

- name: Retrieve a firmware compliance report of specific hosts in the cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a
servicetags:
- SVCTAG1
- SVCTAG2
hosts:
- host1
- xx.xx.xx.xx
ABHISHEK-SINHA10 marked this conversation as resolved.
Show resolved Hide resolved

- name: Retrieve a firmware compliance report of multiple clusters
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "192.168.0.1"
vcenter_uuid: "xxxxx"
vcenter_username: "username"
vcenter_password: "password"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a
- cluster_name: cluster_b



Return Values
-------------

msg (always, str, Successfully fetched the firmware compliance report.)
Retrive the firmware compliance report.


firmware_compliance_info (on HTTP error, list, [{'complianceStatus': 'NonCompliant', 'cluster': 'cluster_a', 'hostComplianceReports': [{'hostId': 1002, 'hostAddress': 'XX.XX.XX.XX', 'serviceTag': 'SVCTAG', 'deviceModel': 'PowerEdge R660xs', 'complianceStatus': 'WARNING', 'componentCompliances': [{'driftStatus': 'NonCompliant', 'componentName': 'Enterprise UEFI Diagnostics', 'currentValue': '4303A15', 'baselineValue': '4303A19', 'criticality': 'Optional', 'updateAction': 'UPGRADE', 'sourceName': 'DCIM:INSTALLED#802__Diagnostics.Embedded.1:LC.Embedded.1', 'complianceStatus': 'WARNING', 'rebootRequired': False}]}]}])
Details of the compliance report.





Status
------





Authors
~~~~~~~

- Abhishek Sinha(@ABHISHEK-SINHA10)

75 changes: 75 additions & 0 deletions playbooks/omevv/omevv_firmware_compliance_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
- name: Firmware compliance report
hosts: omevv
gather_facts: false
tasks:
- name: Fetch firmware compliance report of all the cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "{{ hostname }}"
vcenter_uuid: "{{ vcenter_uuid }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
ca_path: "path/to/ca_file"

- name: Fetch firmware compliance report of all the hosts in the specific
cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "{{ hostname }}"
vcenter_uuid: "{{ vcenter_uuid }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a

- name: Fetch firmware compliance report of a specific hosts in the
specific cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "{{ hostname }}"
vcenter_uuid: "{{ vcenter_uuid }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a
servicetags:
- SVCTAG1
- SVCTAG2
hosts:
- host1
- xx.xx.xx.xx

- name: Fetch firmware compliance report of a specific hosts in of
multiple cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "{{ hostname }}"
vcenter_uuid: "{{ vcenter_uuid }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a
servicetags:
- SVCTAG1
- SVCTAG2
hosts:
- host1
- xx.xx.xx.xx
- cluster_name: cluster_b
servicetags:
- SVCTAG3
- SVCTAG4
hosts:
- host2
- xx.xx.xx.yy

- name: Fetch firmware compliance report of multiple cluster
dellemc.openmanage.omevv_firmware_compliance_info:
hostname: "{{ hostname }}"
vcenter_uuid: "{{ vcenter_uuid }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
ca_path: "path/to/ca_file"
clusters:
- cluster_name: cluster_a
- cluster_name: cluster_b
118 changes: 102 additions & 16 deletions plugins/module_utils/omevv_utils/omevv_info_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,17 @@
__metaclass__ = type

VCENTER_INFO_URI = "/Consoles"
CLUSTER_INFO_URI = "/Consoles/{uuid}/Clusters"
GROUP_ID_CLUSTER_INFO_URI = "/Consoles/{uuid}/Groups/getGroupsForClusters"
MANAGED_HOST_INFO_URI = "/Consoles/{uuid}/ManagedHosts"
HOST_FIRMWARE_DRIFT_INFO_URI = "/Consoles/{uuid}/Groups/{groupId}/ManagedHosts/{hostId}/FirmwareDriftReport"
CLUSTER_FIRMWARE_DRIFT_INFO_URI = "/Consoles/{uuid}/Groups/{groupId}/FirmwareDriftReport"


class OMEVVInfo:
def __init__(self, omevv_obj):
self.omevv_obj = omevv_obj

def search_vcenter_hostname(self, vcenter_data, vcenter_id):
"""
Searches for a vCenter hostname in the given vcenter_data list.
Parameters:
vcenter_data (list): A list of vCenter data.
vcenter_id (str): The hostname of the vCenter to search for.
Returns:
dict: The vCenter data that matches the given vcenter_id. If no match is found, an empty dictionary is returned.
"""
for vcenter in vcenter_data:
if vcenter.get('consoleAddress') == vcenter_id:
return vcenter
return {}

def get_vcenter_info(self, vcenter_id=None):
"""
Retrieves the vCenter information.
Expand All @@ -64,6 +55,101 @@ def get_vcenter_info(self, vcenter_id=None):
vcenter_info = []
if resp.success:
vcenter_info = resp.json_data
if vcenter_id:
vcenter_info = self.search_vcenter_hostname(vcenter_info, vcenter_id)
if vcenter_id and vcenter_info:
for each_vcenter in vcenter_info:
if each_vcenter.get('consoleAddress') == vcenter_id:
return each_vcenter
return {}
return vcenter_info

def get_cluster_info(self, uuid, cluster_name=""):
uri = CLUSTER_INFO_URI.format(uuid=uuid)
resp = self.omevv_obj.invoke_request('GET', uri)
cluster_info = []
if resp.success:
cluster_info = resp.json_data
if cluster_name and cluster_info:
for each_cluster in cluster_info:
if each_cluster.get('name') == cluster_name:
return each_cluster
return {}
return cluster_info

def get_group_id_of_cluster(self, uuid, cluster_name):
group_id = -1
uri = GROUP_ID_CLUSTER_INFO_URI.format(uuid=uuid)
cluster_info = self.get_cluster_info(uuid, cluster_name)
if cluster_info:
entity_id = cluster_info.get('entityId')
payload = {"clustIds": [entity_id]}
resp = self.omevv_obj.invoke_request('POST', uri, data=payload)
if resp.success:
group_id = resp.json_data[0].get('groupId')
return group_id

def get_managed_host_details(self, uuid, servicetags=None, hostnames=None):
servicetags = [] if servicetags is None else servicetags
hostnames = [] if hostnames is None else hostnames
uri = MANAGED_HOST_INFO_URI.format(uuid=uuid)
resp = self.omevv_obj.invoke_request('GET', uri)
managed_hosts = resp.json_data
if not (servicetags or hostnames):
return managed_hosts, {}

if servicetags:
managed_hosts = [
host for host in managed_hosts
if host.get("serviceTag") in servicetags
]

if hostnames:
managed_hosts = [
host for host in managed_hosts
if host.get("hostName") in hostnames
]

invalid_result = {
"servicetags": [
tag for tag in servicetags
if not any(host.get("serviceTag") == tag for host in managed_hosts)
],
"hostnames": [
name for name in hostnames
if not any(host.get("hostName") == name for host in managed_hosts)
]
}
return managed_hosts, invalid_result

def get_firmware_drift_info_for_single_host(self, uuid, groupid, hostid):
result = []
uri = HOST_FIRMWARE_DRIFT_INFO_URI.format(uuid=uuid,
groupId=str(groupid),
hostId=str(hostid))
resp = self.omevv_obj.invoke_request('GET', uri)
if resp.success:
result = resp.json_data
return result

def get_firmware_drift_info_for_multiple_host(self, uuid, groupid, hostidlist):
result = []
for each_host in hostidlist:
output = self.get_firmware_drift_info_for_single_host(uuid, groupid, each_host)
result.append(output)
return result

def get_firmware_drift_info_for_single_cluster(self, uuid, groupid):
result = []
uri = CLUSTER_FIRMWARE_DRIFT_INFO_URI.format(uuid=uuid,
groupId=str(groupid))
resp = self.omevv_obj.invoke_request('GET', uri)
if resp.success:
result = resp.json_data
return result

def get_firmware_drift_info_for_multiple_cluster(self, uuid, groupidlist):
result = []
for each_group in groupidlist:
output = self.get_firmware_drift_info_for_single_cluster(uuid=uuid,
groupid=each_group)
result.append(output)
return result
Loading
Loading