feat: wait for vms to start
This commit is contained in:
parent
07fa191f48
commit
2e9bb05e94
32
main.py
32
main.py
@ -1,19 +1,23 @@
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
from typing import Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
|
import urllib3
|
||||||
from proxmoxer import ProxmoxAPI
|
from proxmoxer import ProxmoxAPI
|
||||||
|
|
||||||
|
|
||||||
|
urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
PROXMOX_HOST = 'pve.office.basealt.ru'
|
PROXMOX_HOST = 'pve.office.basealt.ru'
|
||||||
PROXMOX_USER = 'stepchenkoas@BaseALT'
|
PROXMOX_USER = 'stepchenkoas@BaseALT'
|
||||||
PROXMOX_PASSWORD = Path('pve_secret').read_text().strip()
|
PROXMOX_PASSWORD = Path('pve_secret').read_text().strip()
|
||||||
|
|
||||||
def create_vm(
|
def create_vm(
|
||||||
proxmox,
|
proxmox,
|
||||||
node: str = None,
|
node: Optional[str] = None,
|
||||||
vmid: int = None,
|
vmid: Optional[int] = None,
|
||||||
name: str = None,
|
name: Optional[str] = None,
|
||||||
prefix: str = 'stepchenkoas',
|
prefix: str = 'stepchenkoas',
|
||||||
cores: int = 2,
|
cores: int = 2,
|
||||||
memory: int = 2048,
|
memory: int = 2048,
|
||||||
@ -68,8 +72,8 @@ def clone_template(
|
|||||||
proxmox,
|
proxmox,
|
||||||
node: str,
|
node: str,
|
||||||
vmid: int,
|
vmid: int,
|
||||||
newid: int = None,
|
newid: Optional[int] = None,
|
||||||
name: str = None,
|
name: Optional[str] = None,
|
||||||
prefix: str ='stepchenkoas',
|
prefix: str ='stepchenkoas',
|
||||||
) -> int:
|
) -> int:
|
||||||
if newid is None:
|
if newid is None:
|
||||||
@ -78,7 +82,7 @@ def clone_template(
|
|||||||
if name is None:
|
if name is None:
|
||||||
name = f'{prefix}-{newid}'
|
name = f'{prefix}-{newid}'
|
||||||
|
|
||||||
proxmox.nodes(node).qemu(vmid).clone.post(
|
res = proxmox.nodes(node).qemu(vmid).clone.post(
|
||||||
newid=newid,
|
newid=newid,
|
||||||
node=node,
|
node=node,
|
||||||
vmid=vmid,
|
vmid=vmid,
|
||||||
@ -89,6 +93,7 @@ def clone_template(
|
|||||||
storage='rbd-storage',
|
storage='rbd-storage',
|
||||||
target=node,
|
target=node,
|
||||||
)
|
)
|
||||||
|
print(res)
|
||||||
print(f'VM {vmid} was cloned to {newid} successfully!')
|
print(f'VM {vmid} was cloned to {newid} successfully!')
|
||||||
|
|
||||||
return newid
|
return newid
|
||||||
@ -117,7 +122,7 @@ def main():
|
|||||||
nodes = proxmox.nodes.get()
|
nodes = proxmox.nodes.get()
|
||||||
nodes = list(filter(lambda node: node['status'] == 'online', nodes))
|
nodes = list(filter(lambda node: node['status'] == 'online', nodes))
|
||||||
node = min(nodes, key=lambda node: node['disk'])['node']
|
node = min(nodes, key=lambda node: node['disk'])['node']
|
||||||
template_id = 208
|
template_id = 374
|
||||||
prefix = 'stepchenkaos-test-k8s'
|
prefix = 'stepchenkaos-test-k8s'
|
||||||
|
|
||||||
vm_id_master = clone_template(
|
vm_id_master = clone_template(
|
||||||
@ -145,8 +150,15 @@ def main():
|
|||||||
proxmox.nodes(node).qemu(vm_id_worker2).status.start.post()
|
proxmox.nodes(node).qemu(vm_id_worker2).status.start.post()
|
||||||
|
|
||||||
vms_statuses = [False, False, False]
|
vms_statuses = [False, False, False]
|
||||||
while !all(vms_statuses)
|
print(vms_statuses)
|
||||||
proxmox.nodes(node).qemu(vm_id_master).status.current.get()
|
while not all(vms_statuses):
|
||||||
|
sleep(5)
|
||||||
|
vms_statuses[0] = proxmox.nodes(node).qemu(vm_id_master).status.current.get()['status'] == 'running'
|
||||||
|
vms_statuses[1] = proxmox.nodes(node).qemu(vm_id_worker1).status.current.get()['status'] == 'running'
|
||||||
|
vms_statuses[2] = proxmox.nodes(node).qemu(vm_id_worker2).status.current.get()['status'] == 'running'
|
||||||
|
print(vms_statuses)
|
||||||
|
|
||||||
|
sleep(60)
|
||||||
|
|
||||||
vm_ip_master = get_vm_ip(proxmox, node, vm_id_master)
|
vm_ip_master = get_vm_ip(proxmox, node, vm_id_master)
|
||||||
vm_ip_worker1 = get_vm_ip(proxmox, node, vm_id_worker1)
|
vm_ip_worker1 = get_vm_ip(proxmox, node, vm_id_worker1)
|
||||||
|
Loading…
Reference in New Issue
Block a user