If you put both of those through sort -u you could then just do a diff and see what uuids are known only to lxc, though you’d then need to go through and find the actual container names again.
Hey @jameinel! Just wanted to share my script that is based on your awesome answer. Basically force to be logged in as admin to see all models. And specify lxc remote and juju cloud. Since we have one cloud per lxc host. Thanks!
#!/bin/bash
# Check if there are instances on the LXD host that does not exist in Juju.
LXC_REMOTE=$1
JUJU_CLOUD=$2
user=$(juju whoami --format json | jq -r '.user')
if [ "$user" != "admin" ]; then
echo "You must be logged in as user 'admin'."
exit 1
fi
if [ "$1" == "-h" ] | [ -z "$LXC_REMOTE" ] | [ -z "$JUJU_CLOUD" ]; then
echo "Usage: ./orphaned-instances.sh <lxc-remote> <juju-cloud>"
exit 1
fi
juju models --all --uuid --format=json | jq -r --arg JUJU_CLOUD "$JUJU_CLOUD" '.["models"]|.[]| select(.cloud==$JUJU_CLOUD)|.["model-uuid"]' | cut -b 31- | sort -u > juju-uuids.txt
lxc list --all-projects --format json $LXC_REMOTE: | jq -r '.[].name' | grep ^juju > lxc-juju-containers.txt
cat lxc-juju-containers.txt | cut -d - -f 2 | sort -u > lxc-uuids.txt
for uuid in `comm -13 juju-uuids.txt lxc-uuids.txt` ; do # only lines in lxc-uuids.txt
grep $uuid lxc-juju-containers.txt;
done;
@joakimnyman might be good to also have some controller parameter in there since this would be returning models from a controller which might not be aware of the cloud+remote used in the call?