mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Implement ynh_lxc_snapshot_exists
This commit is contained in:
parent
d3883f6b69
commit
72a3afd02b
3 changed files with 20 additions and 9 deletions
|
@ -126,7 +126,7 @@ _LOAD_SNAPSHOT_OR_INSTALL_APP () {
|
||||||
local _install_type="$(path_to_install_type $check_path)"
|
local _install_type="$(path_to_install_type $check_path)"
|
||||||
local snapname="snap_${_install_type}install"
|
local snapname="snap_${_install_type}install"
|
||||||
|
|
||||||
if ! ynh_lxc_snapshot_exists $snapname
|
if ! ynh_lxc_snapshot_exists --name=$LXC_NAME --snapname=$snapname
|
||||||
then
|
then
|
||||||
log_warning "Expected to find an existing snapshot $snapname but it doesn't exist yet .. will attempt to create it"
|
log_warning "Expected to find an existing snapshot $snapname but it doesn't exist yet .. will attempt to create it"
|
||||||
ynh_lxc_snapshot_load snap0 \
|
ynh_lxc_snapshot_load snap0 \
|
||||||
|
@ -370,7 +370,7 @@ TEST_INSTALL () {
|
||||||
|
|
||||||
# Create the snapshot that'll be used by other tests later
|
# Create the snapshot that'll be used by other tests later
|
||||||
[ "$install_type" != "private" ] \
|
[ "$install_type" != "private" ] \
|
||||||
&& ! ynh_lxc_snapshot_exists $snapname \
|
&& ! ynh_lxc_snapshot_exists --name=$LXC_NAME --snapname=$snapname \
|
||||||
&& log_debug "Create a snapshot after app install" \
|
&& log_debug "Create a snapshot after app install" \
|
||||||
&& ynh_lxc_pc_snapshot_create --name=LXC_NAME --snapname=$snapname
|
&& ynh_lxc_pc_snapshot_create --name=LXC_NAME --snapname=$snapname
|
||||||
|
|
||||||
|
|
23
lib/ynh_lxd
23
lib/ynh_lxd
|
@ -161,12 +161,23 @@ ynh_lxc_swapfiles_clean () {
|
||||||
lxc exec $name -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done'
|
lxc exec $name -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done'
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_lxc_snapshot_exists () {
|
# Check if a snapshot exist for an LXC container
|
||||||
local snapname=$1
|
#
|
||||||
lxc list --format json \
|
# usage: ynh_lxc_snapshot_exists --name=$LXC_NAME --snapname=--name=name --snapname=snapname
|
||||||
| jq -e --arg LXC_NAME $LXC_NAME --arg snapname $snapname \
|
# | arg: -n, --name= - name of the LXC
|
||||||
'.[] | select(.name==$LXC_NAME) | .snapshots[] | select(.name==$snapname)' \
|
# | arg: -s, --snapname= - name of the snapshot
|
||||||
>/dev/null
|
#
|
||||||
|
# Requires YunoHost version *.*.* or higher.
|
||||||
|
ynh_lxc_snapshot_exists --name=$LXC_NAME --snapname=() {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=ns
|
||||||
|
local -A args_array=([n]=name= [s]=snapname=)
|
||||||
|
local name
|
||||||
|
local snapname
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
|
lxc list --format json | jq -e --arg name $name --arg snapname $snapname '.[] | select(.name==$name) | .snapshots[] | select(.name==$snapname)' >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_lxc_snapshot_load () {
|
ynh_lxc_snapshot_load () {
|
||||||
|
|
|
@ -260,7 +260,7 @@ ynh_lxc_pc_snapshot_create () {
|
||||||
ynh_lxc_stop --name=$name
|
ynh_lxc_stop --name=$name
|
||||||
|
|
||||||
# Check if the snapshot already exist
|
# Check if the snapshot already exist
|
||||||
if ! ynh_lxc_snapshot_exists "$snapname"
|
if ! ynh_lxc_snapshot_exists --name=$name --snapname="$snapname"
|
||||||
then
|
then
|
||||||
log_info "(Creating snapshot $snapname ...)"
|
log_info "(Creating snapshot $snapname ...)"
|
||||||
lxc snapshot $name $snapname
|
lxc snapshot $name $snapname
|
||||||
|
|
Loading…
Add table
Reference in a new issue