-listimages2 creates a .csv and lists only use images
-master.list useful for seeing which labs are using a particular image -still needs work
This commit is contained in:
55
listimages2
Executable file
55
listimages2
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
#get all used images and their backing files
|
||||
#list all unused qemu images in eve-ng
|
||||
#will not include "wiped" nodes
|
||||
#there cannot be any running nodes
|
||||
#
|
||||
#very "hacky"
|
||||
#
|
||||
#find /opt/unetlab/tmp -type f -name \*.qcow2 -exec qemu-img info {} \; > test
|
||||
#set record delimiter to blank line
|
||||
#sed -i s/\ \ \ \ corrupt:\ false// test
|
||||
#sed -i s/\ \ \ \ corrupt:\ true// test
|
||||
#parse w/ blank line for record separateor and newline for field separator
|
||||
# 1 is image file (provisioned device)
|
||||
# 2 is for the source
|
||||
#awk 'BEGIN {FS="\n"; RS=""} {print $1 $6}' test > test2
|
||||
#awk 'BEGIN {FS="\n"; RS=""} {print $6}' test > test2
|
||||
#clean up leaving two files
|
||||
#sed -i 's/image: //' test2
|
||||
#sed -i 's/backing file://' test2
|
||||
# list of all used images
|
||||
#cat test2 | sort -k 2 -u
|
||||
#cat test2 | sort -u
|
||||
#
|
||||
#get just the directory names for qemu (lists only used versions)
|
||||
#cat test2 | cut -f 6 -d '/'
|
||||
#
|
||||
#cat test2 | sort -u | cut -f 6 -d '/' > test3
|
||||
#
|
||||
#list installed qemu versions
|
||||
#ls -l /opt/unetlab/addons/qemu/ | cut -b 42- > test4
|
||||
#grep -Fxv `ls -l /opt/unetlab/addons/qemu/ | cut -b 42-` test3
|
||||
#grep -Fxv -f test3 test4
|
||||
echo "Please enter username"
|
||||
read USERNAME
|
||||
echo "Please enter password"
|
||||
read -s PASSWORD
|
||||
rm /list.json
|
||||
rm master.list
|
||||
curl -k -s -b /tmp/cookie -c /tmp/cookie -X POST -d '{"username":"'"$USERNAME"'","password":"'"$PASSWORD"'"}' https://127.0.0.1/api/auth/login
|
||||
ls -R /opt/unetlab/labs/*.unl > labs_list
|
||||
sed -i 's/\ /%20/g' labs_list
|
||||
sed -i 's/\/opt\/unetlab//g' labs_list
|
||||
while read i; do
|
||||
curl -k -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' https://127.0.0.1/api$i/nodes | jq -r '.[] | .. | objects.image' > images.list
|
||||
echo >> images.list
|
||||
sed ':a;N;$!ba;s~\n~,"'"$i"'"\n~g' images.list >> master.list
|
||||
|
||||
#echo "$i";
|
||||
|
||||
done < labs_list
|
||||
# list used images
|
||||
grep -v null master.list | cut -f1 -d ',' | sort -u
|
||||
echo
|
||||
echo master.list contains a .csv of images and corresponding labs
|
||||
Reference in New Issue
Block a user