Last active
January 17, 2022 16:56
-
-
Save wnn/800151cdb7957891e806fccb1e289d9a to your computer and use it in GitHub Desktop.
find next avaliable proxmox vm id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from proxmoxer import ProxmoxAPI | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='find next available vm id') | |
parser.add_argument('-s', '--server', required=True, help="proxmox host") | |
parser.add_argument('-u', '--user', required=True, help="proxmox user name") | |
parser.add_argument('-p', '--password', required=True, help="proxmox user password") | |
args = parser.parse_args() | |
if "@" not in args.user: | |
args.user += "@pve" | |
proxmox = ProxmoxAPI(args.server, user=args.user, password=args.password, verify_ssl=False) | |
vm_ids = [x['vmid'] for x in proxmox.cluster.resources.get(type='vm')] | |
vm_ids.sort() | |
current_id = vm_ids[0] | |
available_id = [] | |
while True: | |
if current_id not in vm_ids: | |
available_id.append(str(current_id)) | |
if current_id == vm_ids[-1]: | |
break | |
current_id += 1 | |
print(f'{", ".join(available_id)}, {vm_ids[-1]+1}+') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment