Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --force flag when removing snapshots #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion proxmox-autosnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DATE_ISO_FORMAT = False
DATE_TRUENAS_FORMAT = False
INCLUDE_VM_STATE = False
FORCE = False

# Name of the currently running node
NODE_NAME = socket.gethostname().split('.')[0]
Expand Down Expand Up @@ -236,6 +237,8 @@ def remove_snapshot(vmid: str, virtualization: str, label: str = 'daily', keep:
if old_snapshots:
for old_snapshot in old_snapshots:
params = [virtualization, 'delsnapshot', vmid, old_snapshot]
if FORCE:
params.extend(["--force", "true"])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! The general code style uses single quotes. Could you replace the double quotes in --force and true with single quotes to keep it consistent? Thanks!

if DRY_RUN:
params.insert(0, 'sudo') if USE_SUDO else None
print(' '.join(params))
Expand Down Expand Up @@ -294,19 +297,21 @@ def main():
parser.add_argument('-d', '--dryrun', action='store_true',
help='Do not create or delete snapshots, just print the commands.')
parser.add_argument('--sudo', action='store_true', help='Launch commands through sudo.')
parser.add_argument('--force', action='store_true', help='Force removal from config file, even if disk snapshot deletion fails.')
argp = parser.parse_args()

if not argp.vmid and not argp.tags and not argp.exclude_tags:
parser.error('At least one of --vmid or --tags or --exclude-tags is required.')

global MUTE, DRY_RUN, USE_SUDO, ONLY_ON_RUNNING, INCLUDE_VM_STATE, DATE_ISO_FORMAT, DATE_TRUENAS_FORMAT
global MUTE, DRY_RUN, USE_SUDO, ONLY_ON_RUNNING, INCLUDE_VM_STATE, DATE_ISO_FORMAT, DATE_TRUENAS_FORMAT, FORCE
MUTE = argp.mute
DRY_RUN = argp.dryrun
USE_SUDO = argp.sudo
ONLY_ON_RUNNING = argp.running
DATE_ISO_FORMAT = argp.date_iso_format
DATE_TRUENAS_FORMAT = argp.date_truenas_format
INCLUDE_VM_STATE = argp.includevmstate
FORCE = argp.force

picked_vmid = get_filtered_vmids(vmids=argp.vmid, exclude=argp.exclude, tags=argp.tags,
exclude_tags=argp.exclude_tags)
Expand Down