# Atualiza o painel depois do corte. Rodar:
#   ssh CLOUDADMIN01 'sudo docker exec -i cloudaxadmin-web python manage.py shell' < painel-pos-corte.py
# EDITE o dicionario ALVOS antes de rodar. Ele so escreve o que voce listar.
from servers.models import Servers, Datacenter

DC = Datacenter.objects.get(slug="wci-br-sp2-02")

ALVOS = {
    # "IT590768-CORE-INSTANCE01": dict(ip_address="192.168.127.5", id_vm_hypervisor="<uuid>",
    #                                  vcpus=16, memory_mb=131072, disk_gb=530),
    # "IT228334-CORE-INSTANCE01": dict(ip_address="192.168.121.5", id_vm_hypervisor="<uuid>",
    #                                  vcpus=4, memory_mb=28672, disk_gb=218),
    # "IT995476-DB-SNK":  dict(ip_address="10.1.1.250", id_vm_hypervisor="<uuid>",
    #                          vcpus=4, memory_mb=16384, disk_gb=1050),
    # "IT995476-SNK-APP": dict(ip_address="10.1.1.254", id_vm_hypervisor="<uuid>",
    #                          vcpus=16, memory_mb=131072, disk_gb=200,
    #                          server_is_docker=True, management_ip="10.200.0.<x>"),
    # "IT995476-IAAS-INSTANCE01": dict(ip_address="10.1.1.117", id_vm_hypervisor="<uuid>",
    #                                  vcpus=2, memory_mb=4096, disk_gb=65),
}

if not ALVOS:
    print("ALVOS vazio - edite o script. Estado atual:")
    for c in ("IT995476", "IT590768", "IT228334"):
        for s in Servers.all_objects.filter(client_code=c):
            print(f"  {s.server_name:30s} dc={s.datacenter.slug if s.datacenter else None} "
                  f"ip={s.ip_address} vmid={s.id_vm_hypervisor} st={s.status_vm} docker={s.server_is_docker}")
else:
    for nome, campos in ALVOS.items():
        s = Servers.all_objects.get(server_name=nome)
        antes = (s.datacenter.slug if s.datacenter else None, s.ip_address, s.id_vm_hypervisor)
        s.datacenter = DC
        s.status_vm = "active"
        for k, v in campos.items():
            setattr(s, k, v)
        s.save()
        print(f"OK {nome}: {antes} -> ({DC.slug}, {s.ip_address}, {s.id_vm_hypervisor})")
