Skip to content

Commit

Permalink
[Integration] - omevv_firmware_compliance_info (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamSh3 authored Nov 22, 2024
1 parent ecf3929 commit fd4de94
Show file tree
Hide file tree
Showing 13 changed files with 757 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
testcase: '[^_].*'
test_items: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
- ' 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.'
- ''
- 'ADDED IN: version 9.9.0 of dellemc.openmanage'
- ''
- 'OPTIONS (= is mandatory):'
- ''
- '- ca_path'
- ' The Privacy Enhanced Mail (PEM) file that contains a CA'
- ' certificate to be used for the validation.'
- ' default: null'
- ' type: path'
- ''
- '- clusters'
- ' Cluster details to retrieve the firmware compliance report.'
- ' default: null'
- ' elements: dict'
- ' type: list'
- ''
- ' SUBOPTIONS:'
- ''
- ' = cluster_name'
- ' Cluster name of the hosts for which the firmware'
- ' compliance report should be retrieved.'
- ' If `servicetags'' or `hosts'' is provided, then the firmware'
- ' compliance report of only the specified hosts is retrieved'
- ' and displayed.'
- ' type: str'
- ''
- ' - hosts'
- ' The IP address or hostname of the hosts for which the'
- ' firmware compliance reports must be retrieved.'
- ' default: null'
- ' elements: str'
- ' type: list'
- ''
- ' - servicetags'
- ' The service tag of the hosts for which the firmware'
- ' compliance reports must be retrieved.'
- ' default: null'
- ' elements: str'
- ' type: list'
- ''
- = hostname
- ' IP address or hostname of the OpenManage Enterprise Modular.'
- ' type: str'
- ''
- '- port'
- ' OpenManage Enterprise HTTPS port.'
- ' default: 443'
- ' type: int'
- ''
- '- timeout'
- ' The socket level timeout in seconds.'
- ' default: 30'
- ' type: int'
- ''
- '- validate_certs'
- ' Whether to check SSL certificate. - If `true'', the SSL'
- ' certificates will be validated. - If `false'', the SSL'
- ' certificates will not be validated.'
- ' default: true'
- ' type: bool'
- ''
- '- vcenter_password'
- ' Password for OpenManage Enterprise Integration for VMware'
- ' vCenter (OMEVV).'
- ' If the password is not provided, then the environment variable'
- ' `OMEVV_VCENTER_PASSWORD'' is used.'
- ' Example: export OMEVV_VCENTER_PASSWORD=password'
- ' default: null'
- ' type: str'
- ''
- '- vcenter_username'
- ' Username for OpenManage Enterprise Integration for VMware'
- ' vCenter (OMEVV).'
- ' If the username is not provided, then the environment variable'
- ' `OMEVV_VCENTER_USERNAME'' is used.'
- ' Example: export OMEVV_VCENTER_USERNAME=username'
- ' default: null'
- ' type: str'
- ''
- '- vcenter_uuid'
- ' Universally Unique Identifier (UUID) of vCenter.'
- ' vCenter UUID details can be retrieved using'
- ' [dellemc.openmanage.omevv_vcenter_info] module.'
- ' If UUID is not provided, then the environment variable'
- ' `OMEVV_VCENTER_UUID'' is used.'
- ' Example: export OMEVV_VCENTER_UUID=uuid'
- ' default: null'
- ' type: str'
- ''
- ''
- 'ATTRIBUTES:'
- ''
- ' check_mode:'
- ' description: Runs task to validate without performing action on the target
machine.'
- ' support: full'
- ' diff_mode:'
- ' description: Runs the task to report the changes that are made or the
changes that'
- ' must be applied.'
- ' support: full'
- ''
- 'NOTES:'
- ' * Run this module from a system that has direct access to'
- ' Dell OpenManage Enterprise.'
- ''
- ''
- 'REQUIREMENTS: python >= 3.9.6'
- ''
- 'AUTHOR: Abhishek Sinha(@ABHISHEK-SINHA10)'
- ''
- 'EXAMPLES:'
- ''
- '---'
- '- 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'
- ''
- '- 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:'
- '- firmware_compliance_info'
- ' Details of the compliance report.'
- ' elements: dict'
- ' returned: on HTTP error'
- ' sample: [{cluster: cluster_a, complianceStatus: NonCompliant, hostComplianceReports:
[{complianceStatus: WARNING,'
- ' componentCompliances: [{baselineValue: 4303A19, complianceStatus:
WARNING,'
- ' componentName: Enterprise UEFI Diagnostics, criticality: Optional,
currentValue: 4303A15,'
- ' driftStatus: NonCompliant, rebootRequired: false, sourceName:
''DCIM:INSTALLED#802__Diagnostics.Embedded.1:LC.Embedded.1'','
- ' updateAction: UPGRADE}], deviceModel: PowerEdge R660xs, hostAddress:
XX.XX.XX.XX,'
- ' hostId: 1002, serviceTag: SVCTAG}]}]'
- ' type: list'
- ''
- '- msg'
- ' Retrive the firmware compliance report.'
- ' returned: always'
- ' sample: Successfully fetched the firmware compliance report.'
- ' type: str'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- prepare_omevv_registration
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Collect all test cases
ansible.builtin.find:
paths: '{{ role_path }}/tests'
patterns: '{{ testcase }}.yaml'
use_regex: true
register: test_cases
delegate_to: localhost

- name: Set test_items
ansible.builtin.set_fact:
test_items: "{{ test_cases.files | map(attribute='path') | list }}"

- name: Fail if no test cases are found as per pattern.
ansible.builtin.fail:
msg: "Could not find test cases to run!!!"
when: not test_items|length > 0

- name: Run test case
ansible.builtin.include_tasks: '{{ test_case_to_run }}'
with_items: '{{ test_items }}'
loop_control:
loop_var: test_case_to_run
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Post-requisite - Delete a baseline profile
dellemc.openmanage.omevv_baseline_profile:
hostname: "{{ hostname }}"
vcenter_uuid: "{{ uuid }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
name: "AnsibleTest"
state: "absent"
validate_certs: false
register: delete_result
no_log: true
ignore_errors: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Pre-requisite - Create a baseline profile
dellemc.openmanage.omevv_baseline_profile:
hostname: "{{ hostname }}"
vcenter_uuid: "{{ uuid }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
name: "AnsibleTest"
repository_profile: "Dell Default Catalog"
validate_certs: false
description: "Firmware repository profile created by Module"
cluster:
- "{{ cluster_name }}"
days:
- "sunday"
time: "03:59"
register: create_result
no_log: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
- name: Get all clusters by uri.
ansible.builtin.uri: &uri_param
url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port
}}/omevv/GatewayService/v1/Consoles/{{ uuid }}/Clusters
user: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
force_basic_auth: true
status_code: 200
headers:
x_omivv-api-vcenter-identifier: "{{ uuid }}"
register: all_clusters_resp

- name: Extract entityIds
ansible.builtin.set_fact:
entity_ids: "{{ entity_ids | default([]) + [item.entityId] }}"
loop: "{{ all_clusters_resp.json }}"

- name: Extract cluster names
ansible.builtin.set_fact:
cluster_names: "{{ cluster_names | default([]) + [item.name] }}"
loop: "{{ all_clusters_resp.json }}"

- name: Create payload
ansible.builtin.set_fact:
payload:
clustIds: "{{ entity_ids }}"

- name: Get list of groupIDs for given cluster IDs.
ansible.builtin.uri:
url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port
}}/omevv/GatewayService/v1/Consoles/{{ uuid
}}/Groups/getGroupsForClusters
method: POST
body: "{{ payload | to_json }}"
body_format: json
<<: *uri_param
register: group_ids_resp

- name: Set fact for groupIds
ansible.builtin.set_fact:
group_ids: "{{ group_ids_resp.json | map(attribute='groupId') | list }}"

- name: Get cluster drift info.
ansible.builtin.uri:
url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port
}}/omevv/GatewayService/v1/Consoles/{{ uuid
}}/Groups/{{ item }}/FirmwareDriftReport
<<: *uri_param
loop: "{{ group_ids }}"
register: cluster_drift_info
ignore_errors: true

- name: Initialize all_cluster_drift_info
ansible.builtin.set_fact:
all_cluster_drift_info: []

- name: Set fact to store all drift info
ansible.builtin.set_fact:
all_cluster_drift_info: "{{ all_cluster_drift_info + [item.json] }}"
loop: "{{ cluster_drift_info.results }}"
when: item.json is defined

- name: Remove error and message from all_cluster_drift_info response
ansible.builtin.set_fact:
all_cluster_drift_info: "{{ all_cluster_drift_info | ansible.utils.
remove_keys(target=['errorCode', 'message'],
matching_parameter='regex') }}"

- name: Remove cluster key from module response
ansible.builtin.set_fact:
modified_response: "{{ info_result.firmware_compliance_info |
ansible.utils.remove_keys(target=['cluster', 'error_code', 'message'],
matching_parameter='regex') }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: Get group details
ansible.builtin.uri: &uri_params
url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port
}}/omevv/GatewayService/v1/Consoles/{{ uuid }}/Groups
user: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
force_basic_auth: true
status_code: 200
headers:
x_omivv-api-vcenter-identifier: "{{ uuid }}"
register: group_details

- name: Find the CLUSTER group
ansible.builtin.set_fact:
cluster_name: "{{ item.consoleEntityName }}"
group_id: "{{ item.groupId }}"
loop: "{{ group_details.json }}"
when: item.groupType == "CLUSTER"
register: cluster_result
until: cluster_result is defined
retries: 1
delay: 0

- name: Find hosts details
ansible.builtin.uri:
url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port
}}/omevv/GatewayService/v1/Consoles/{{ uuid }}/ManagedHosts
<<: *uri_params
register: host_details

- name: Find the host and its servicetag
ansible.builtin.set_fact:
host: "{{ item.hostName }}"
servicetag: "{{ item.serviceTag }}"
loop: "{{ host_details.json }}"
when: item.omevvpGroupId|string == group_id
register: host_result
until: host_result is defined
retries: 1
delay: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Get cluster drift info.
ansible.builtin.uri:
url: https://{{ hostname | ansible.utils.ipwrap }}:{{ port
}}/omevv/GatewayService/v1/Consoles/{{ uuid
}}/Groups/{{ group_id }}/FirmwareDriftReport
user: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
method: GET
force_basic_auth: true
status_code: 200
headers:
x_omivv-api-vcenter-identifier: "{{ uuid }}"
register: specific_cluster_drift_info
ignore_errors: true

- name: Initialize cluster_drift_info
ansible.builtin.set_fact:
cluster_drift_info: "{{ specific_cluster_drift_info.json }}"

- name: Remove cluster key from module response
ansible.builtin.set_fact:
modified_response: "{{ info_result.firmware_compliance_info |
ansible.utils.remove_keys(target=['cluster', 'error_code', 'message'],
matching_parameter='regex') }}"
Loading

0 comments on commit fd4de94

Please sign in to comment.