Initial commit
This commit is contained in:
commit
b9717e173c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
pve_secret
|
85
main.py
Normal file
85
main.py
Normal file
@ -0,0 +1,85 @@
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
|
||||
from proxmoxer import ProxmoxAPI
|
||||
|
||||
|
||||
PROXMOX_HOST = 'pve.office.basealt.ru'
|
||||
PROXMOX_USER = 'stepchenkoas@BaseALT'
|
||||
PROXMOX_PASSWORD = Path('pve_secret').read_text().strip()
|
||||
|
||||
def create_vm(
|
||||
proxmox,
|
||||
node=None,
|
||||
vmid=None,
|
||||
name=None,
|
||||
prefix='stepchenkoas',
|
||||
cores=2,
|
||||
memory=2048,
|
||||
disk_size=16,
|
||||
):
|
||||
if node is None:
|
||||
nodes = proxmox.nodes.get()
|
||||
nodes = list(filter(lambda node: node['status'] == 'online', nodes))
|
||||
node = min(nodes, key=lambda node: node['disk'])['node']
|
||||
|
||||
if vmid is None:
|
||||
vmid = proxmox.cluster.get('nextid')
|
||||
|
||||
if name is None:
|
||||
name = f'{prefix}-{vmid}'
|
||||
|
||||
proxmox.nodes(node).qemu.post(
|
||||
node=node,
|
||||
vmid=vmid,
|
||||
description='This VM was created automatically through Proxmox VE API',
|
||||
cores=cores,
|
||||
cpu='host',
|
||||
memory=memory,
|
||||
name=name,
|
||||
net0='virtio,bridge=vmbr0,tag=103,firewall=1',
|
||||
ostype='l26',
|
||||
pool='Virt_LAB',
|
||||
#alt-server-v-10.1-rc3-x86_64.iso
|
||||
sata2='templates:iso/alt-server-v-10.1-rc3-x86_64.iso,media=cdrom',
|
||||
scsi0=f'rbd-storage:{disk_size},discard=on',
|
||||
scsihw='virtio-scsi-pci',
|
||||
sockets=1,
|
||||
)
|
||||
print(f'VM {vmid} was created successfully!')
|
||||
|
||||
|
||||
def delete_vm(
|
||||
proxmox,
|
||||
node,
|
||||
vmid,
|
||||
):
|
||||
proxmox.nodes(node).qemu(vmid).delete(
|
||||
node=node,
|
||||
vmid=vmid,
|
||||
)
|
||||
print(f'VM {vmid} was deleted successfully!')
|
||||
|
||||
|
||||
def clone_template(
|
||||
proxmox,
|
||||
node,
|
||||
vmid,
|
||||
newid=None,
|
||||
):
|
||||
if newid is None:
|
||||
newid = proxmox.cluster.get('nextid')
|
||||
|
||||
|
||||
def main():
|
||||
proxmox = ProxmoxAPI(
|
||||
PROXMOX_HOST, user=PROXMOX_USER, password=PROXMOX_PASSWORD, verify_ssl=False
|
||||
)
|
||||
|
||||
|
||||
|
||||
proxmox.logout()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user