Last active
February 7, 2023 11:31
-
-
Save sayan3296/61a4d3efc1ba6a2f817dc6bc94b0dc14 to your computer and use it in GitHub Desktop.
Find package information from published version of the CVs across all environment
This file contains hidden or 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
#!/bin/bash | |
# Criteria: | |
# Expected Column of the report: | |
# | |
# CV, CV Version, Lifecycle, Latest Kernel Package in the version | |
# | |
# Considerations: | |
# | |
# We will only choose those CV versions that have any lifecycle promoted to it. | |
# If a version of CV does not have kernel package at all, The result will be blank or NIL | |
## Setting basic vars | |
ORG_ID='1' | |
TMPFILE='/tmp/basic_info' | |
REPORT_OUT='/tmp/cv_info.csv' | |
LOOKUP=$1 | |
if [ -z $LOOKUP ] | |
then | |
echo -e " | |
Usage: $0 <package name> | |
Example: $0 kernel | |
" | |
exit 1 | |
fi | |
## Collecting the primary data | |
hammer --csv --csv-separator="|" --no-headers content-view version list --organization-id=$ORG_ID | awk -F'|' '$5 != "\"\""{print}' > $TMPFILE | |
## Setting up report headers | |
echo -e "\n-------------------,----------,---------------" > $REPORT_OUT | |
echo "CV_Name_and_Version,Lifecycles,Package_Details" >> $REPORT_OUT | |
echo "-------------------,----------,---------------" >> $REPORT_OUT | |
## Package search and report data processing starts here | |
echo "The search for $LOOKUP package has started in all the CV and CCV versions. Please be patient." | |
IFS=$'\n\b' | |
for i in $(cat $TMPFILE) | |
do | |
CV=$(echo $i | awk -F'|' '$2 !~ "Export-" && $2 !~ "Default Organization View"{print $2}') | |
CVV_ID=$(echo $i | awk -F'|' '$2 !~ "Export-" && $2 !~ "Default Organization View"{print $1}') | |
LCE=$(echo $i | awk -F'|' '$2 !~ "Export-" && $2 !~ "Default Organization View"{print $5}' | sed 's/,/ \&/g') | |
if [ ! -z $CVV_ID ] | |
then | |
PKG=$(hammer --no-headers package list --search "name = $LOOKUP" --content-view-version-id=$CVV_ID --packages-restrict-latest true --organization-id=$ORG_ID --fields filename) | |
if [ -z "$PKG" ] | |
then | |
PKG="`echo $LOOKUP`_not_found" | |
fi | |
echo -e "$CV,$LCE,$PKG" >> $REPORT_OUT | |
fi | |
done | |
## Creating a blank line at the end | |
echo -e "\n" >> $REPORT_OUT | |
## Information sent to user | |
echo -e " | |
Script execution has been completed. Please refer to $REPORT_OUT file for the result. | |
The data can be printed in a tabular format using this command as well without the quotes i.e. 'cat $REPORT_OUT | column -s, -t' . | |
" |
A Ruby\Rails based solution is also present but will work on the Katello shipped with Satellite 6.12 and above i.e.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it would imply
On RH7-Containers-CCV CV, version 2.0 is promoted to Library and Test lifecycle and that version 3.0 have kernel-3.10.0-1160.76.1.el7.x86_64.rpm as the latest kernel package.