Skip to content

Instantly share code, notes, and snippets.

@sayan3296
Last active February 7, 2023 11:31
Show Gist options
  • Save sayan3296/61a4d3efc1ba6a2f817dc6bc94b0dc14 to your computer and use it in GitHub Desktop.
Save sayan3296/61a4d3efc1ba6a2f817dc6bc94b0dc14 to your computer and use it in GitHub Desktop.
Find package information from published version of the CVs across all environment
#!/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' .
"
@sayan3296
Copy link
Author

sayan3296 commented Feb 6, 2023

  • The script ( for now ) is limited to one specific ORG whose ID is hardcoded in the script and it's usage, execution, and result look something like this:
# ./cv_report.sh 

  Usage: ./cv_report.sh <package name>
  Example: ./cv_report.sh kernel
  
# ./cv_report.sh kernel
The search for kernel package has started in all the CV and CCV versions. Please be patient.

Script execution has been completed. Please refer to /tmp/cv_info.csv file for the result.
The data can be printed in a tabular format using this command as well without the quotes i.e. 'cat /tmp/cv_info.csv | column -s, -t' .

# cat /tmp/cv_info.csv

-------------------,----------,---------------
CV_Name_and_Version,Lifecycles,Package_Details
-------------------,----------,---------------
TestCV 3.0,Library,kernel_not_found
RH7-Containers-CCV 3.0,Library & Test,kernel-3.10.0-1160.76.1.el7.x86_64.rpm
Test 2.0,Library & Test,kernel_not_found
RHEL7 2.0,Library,kernel-3.10.0-1160.76.1.el7.x86_64.rpm
TestCV 2.0,Test,kernel_not_found
RH8-Containers-CCV 1.0,Library & Test,kernel-4.18.0-372.19.1.el8_6.x86_64.rpm
RHEL8_BASE 1.0,Library,kernel-4.18.0-372.19.1.el8_6.x86_64.rpm
Containers 1.0,Library,kernel_not_found




# cat /tmp/cv_info.csv | column -s, -t
-------------------     ----------      ---------------
CV_Name_and_Version     Lifecycles      Package_Details
-------------------     ----------      ---------------
TestCV 3.0              Library         kernel_not_found
RH7-Containers-CCV 3.0  Library & Test  kernel-3.10.0-1160.76.1.el7.x86_64.rpm
Test 2.0                Library & Test  kernel_not_found
RHEL7 2.0               Library         kernel-3.10.0-1160.76.1.el7.x86_64.rpm
TestCV 2.0              Test            kernel_not_found
RH8-Containers-CCV 1.0  Library & Test  kernel-4.18.0-372.19.1.el8_6.x86_64.rpm
RHEL8_BASE 1.0          Library         kernel-4.18.0-372.19.1.el8_6.x86_64.rpm

  • So if I take this line i.e.
RH7-Containers-CCV 3.0  Library & Test  kernel-3.10.0-1160.76.1.el7.x86_64.rpm

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.

@sayan3296
Copy link
Author

A Ruby\Rails based solution is also present but will work on the Katello shipped with Satellite 6.12 and above i.e.

https://gist.github.com/parthaa/4d03017a0f68ca69375f5d436d108025?permalink_comment_id=4461543#gistcomment-4461543

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment