Last active
February 6, 2023 13:34
-
-
Save parthaa/4d03017a0f68ca69375f5d436d108025 to your computer and use it in GitHub Desktop.
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
def report | |
rows = [] | |
Organization.all.each do |org| | |
org.kt_environments.each do |env| | |
env.content_view_versions.not_ignorable.each do |cvv| | |
nvra = Katello::Rpm.latest(::Katello::Rpm.where(name: "kernel", id: cvv.packages)).first&.nvra | |
if nvra | |
rows << { organization: org.title, | |
lifecycle_environment: env.label, | |
version: cvv.name, | |
nvra: nvra | |
} | |
end | |
end | |
end | |
end | |
rows | |
end |
- I did a little modification with how the data is being presented or stored i.e.
# cat package_report.rb
conf.echo=false
require 'csv'
file = "/tmp/host_raw_data.csv"
column_headers = ["Organization", "LifeCycle", "CV", "Package"]
CSV.open(file, 'w', write_headers: true, headers: column_headers) do |writer|
Organization.all.each do |org|
org.kt_environments.each do |env|
env.content_view_versions.not_ignorable.each do |cvv|
nvra = Katello::Rpm.latest(::Katello::Rpm.where(name: "kernel", id: cvv.packages)).first&.nvra
if nvra
writer <<[org.title, env.label, cvv.name, nvra]
end
end
end
end
end
And then I run it as cat package_report.rb | foreman-rake console
which gives me this inside /tmp/host_raw_data.csv
i.e.
# cat /tmp/host_raw_data.csv
Organization,LifeCycle,CV,Package
RedHat,Library,Default Organization View 1.0,kernel-4.18.0-372.32.1.el8_6.x86_64
RedHat,Library,RHEL7 2.0,kernel-3.10.0-1160.76.1.el7.x86_64
RedHat,Library,RH7-Containers-CCV 3.0,kernel-3.10.0-1160.76.1.el7.x86_64
RedHat,Library,RHEL8_BASE 1.0,kernel-4.18.0-372.19.1.el8_6.x86_64
RedHat,Library,RH8-Containers-CCV 1.0,kernel-4.18.0-372.19.1.el8_6.x86_64
RedHat,Test,RH7-Containers-CCV 3.0,kernel-3.10.0-1160.76.1.el7.x86_64
RedHat,Test,RH8-Containers-CCV 1.0,kernel-4.18.0-372.19.1.el8_6.x86_64
# cat /tmp/host_raw_data.csv | column -s, -t
Organization LifeCycle CV Package
RedHat Library Default Organization View 1.0 kernel-4.18.0-372.32.1.el8_6.x86_64
RedHat Library RHEL7 2.0 kernel-3.10.0-1160.76.1.el7.x86_64
RedHat Library RH7-Containers-CCV 3.0 kernel-3.10.0-1160.76.1.el7.x86_64
RedHat Library RHEL8_BASE 1.0 kernel-4.18.0-372.19.1.el8_6.x86_64
RedHat Library RH8-Containers-CCV 1.0 kernel-4.18.0-372.19.1.el8_6.x86_64
RedHat Test RH7-Containers-CCV 3.0 kernel-3.10.0-1160.76.1.el7.x86_64
RedHat Test RH8-Containers-CCV 1.0 kernel-4.18.0-372.19.1.el8_6.x86_64
FYI, the shell script i came up with for Sat 6.10 - 6.13 i.e. https://gist.github.com/sayan3296/61a4d3efc1ba6a2f817dc6bc94b0dc14
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@parthaa Hello.. First of all, thank you so much.. I was specifically struggling to find out this part while doing my own tests.
env.content_view_versions.not_ignorable.each do |cvv|
But I now understand why. I was trying to check on katello shipped with 6.10 and 6.11, but the not_ignorable scope for cvv and ignore_generated scope for cv was added in the Katello 4.7 ( or the version that ships with Sat 6.12 ).
The script runs fine on 6.12 and above but I will try to look into the code for cv and cvv to see if i can improve it a bit to make it usable on 6.10 or at least 6.11