File: empty-incus.sh

package info (click to toggle)
incus 6.0.5-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,092 kB
  • sloc: sh: 16,313; ansic: 3,121; python: 457; makefile: 337; ruby: 51; sql: 50; lisp: 6
file content (59 lines) | stat: -rwxr-xr-x 2,373 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh -eu
if ! command -v jq >/dev/null 2>&1; then
    echo "This tool requires: jq"
    exit 1
fi

## Delete anything that's tied to a project
for project in $(incus query "/1.0/projects?recursion=1" | jq .[].name -r); do
    echo "==> Deleting all instances for project: ${project}"
    for instance in $(incus query "/1.0/instances?recursion=1&project=${project}" | jq .[].name -r); do
        incus delete --project "${project}" -f "${instance}"
    done

    echo "==> Deleting all images for project: ${project}"
    for image in $(incus query "/1.0/images?recursion=1&project=${project}" | jq .[].fingerprint -r); do
        incus image delete --project "${project}" "${image}"
    done
done

for project in $(incus query "/1.0/projects?recursion=1" | jq .[].name -r); do
    echo "==> Deleting all profiles for project: ${project}"
    for profile in $(incus query "/1.0/profiles?recursion=1&project=${project}" | jq .[].name -r); do
        if [ "${profile}" = "default" ]; then
            printf 'config: {}\ndevices: {}' | incus profile edit --project "${project}" default
            continue
        fi
        incus profile delete --project "${project}" "${profile}"
    done

    if [ "${project}" != "default" ]; then
        echo "==> Deleting project: ${project}"
        incus project delete "${project}"
    fi
done

## Delete the networks
echo "==> Deleting all networks"
for network in $(incus query "/1.0/networks?recursion=1" | jq '.[] | select(.managed) | .name' -r); do
    incus network delete "${network}"
done

## Delete the storage pools
echo "==> Deleting all storage pools"
for storage_pool in $(incus query "/1.0/storage-pools?recursion=1" | jq .[].name -r); do
    # Delete the storage volumes.
    for volume in $(incus query "/1.0/storage-pools/${storage_pool}/volumes/custom?recursion=1" | jq .[].name -r); do
        echo "==> Deleting storage volume ${volume} on ${storage_pool}"
        incus storage volume delete "${storage_pool}" "${volume}"
    done

    # Delete the storage buckets.
    for bucket in $(incus query "/1.0/storage-pools/${storage_pool}/buckets?recursion=1" | jq .[].name -r); do
        echo "==> Deleting storage bucket ${bucket} on ${storage_pool}"
        incus storage volume delete "${storage_pool}" "${bucket}"
    done

    ## Delete the storage pool.
    incus storage delete "${storage_pool}"
done