Proxmox api problem

JeanBro

New Member
Jan 9, 2023
25
1
3
Hello,
I have created a client area to automatically create a vm when a client order one. The code is written in php and I am using the zzantares proxmox php library.
Here is the code of the creation in the proxmox side of my vm :
PHP:
public function createVM(string $id_service, int $userid, int $image, string $cores, string $ram, string $space, string $address_ip, int $server_id){
        $this->ConnectProxmox($server_id);
        $this->password = $this->RootVPS();
        
        $vm_id = $this->proxmox->get('/cluster/nextid');
        $vm_id = $vm_id['data'];
        
        $this->user->userInfo($userid);

        if($image == '8000'){
            $this->template = '8000';
        } else if($image =='9000'){
            $this->template == '9000';
        } else {
            $this->template = '8000';
        }

        if($vm_id != 'null'){
            $this->deleteVM($vm_id, $server_id);
        }

        $this->PVEIPs->getIPs($id_service, $address_ip);

        $this->nextId($server_id);
        $info = [
            'newid' => $this->vmid,
            'full' => '1',
            'storage' => 'local-lvm',
            'description' => 'Client : '.$this->user->mail,
            'vmid' => $this->template
        ];
        $this->createInstance = $this->proxmox->create('/nodes/'.$this->proxmoxkey->name_api.'/qemu/'.$this->template.'/clone', $info);
        
        

        $resize = [
            'vmid' => $this->vmid,
            'disk' => 'scsi0',
            'size' => $space.'G'
        ];

        $this->update = $this->proxmox->set('/nodes/'.$this->proxmoxkey->name_api.'/qemu/'.$this->vmid.'/resize', $resize);       
        sleep(10);
        
        $update = [
            'node' => $server_id,
            'vmid' => $this->vmid,
            'cipassword' => '123456',
            'ciuser' => 'root',
            'sockets' => '1',
            'cores' => $cores,
            'memory' => $ram,
            'agent' => '1',
            'nameserver' => $this->PVEIPs->dns,
            'name' => $id_service,
            'ipconfig0' => 'ip='.$this->PVEIPs->address_ip.'/'.$this->PVEIPs->subnet_mask.',gw='.$this->PVEIPs->gateway.'',
            'net0' => 'virtio,bridge=vmbr0,firewall=0,macaddr='.$this->PVEIPs->mac.',tag='.$this->PVEIPs->vlan_tag.''
        ];

        $this->update = $this->proxmox->create('/nodes/'.$this->proxmoxkey->name_api.'/qemu/'.$this->vmid.'/config', $update);
        $this->cloudTable->updateInstall($id_service, $this->vmid, $userid, $this->template, $this->PVEIPs->address_ip, $this->password);
    }

And my problem is in the 3rd part of the vm creation when it is updatting the vm. I don't why it isn't working ; the cloning of the vm then the resizing it's also working but the updat it's not working.
If you could find the error I will be very happy.
Thank you very much.
Jean B.
 
Hi @JeanBro , welcome to the forum.

We know that Proxmox API works in general. Proxmox GUI and CLI use it, many other people use it both directly and via 3rd party libraries.
You need to add some debug code to find your issue. For example, print out variables and final API calls. Check the pveproxy log. Confirm that what you are trying to do works via "pvesh".

Reaching out to the creator of your library would be a wise step as well.

It's unlikely that anyone can help based on the information provided. We don't even know if the error you are receiving is from Proxmox backend or something from PHP.

Good luck


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
  • Like
Reactions: justinclift
Hi,
Thank you for your reply. I think you do not understand very well the problem or I wasn't clear but I am not having any error as well on the php application side, and on the proxmox. But when the vm is created I can see on proxmox that the vm correct name haven't been setup correctly same as the password, ip adress...
You can find in the attachment an extract of the logs when a vm is created.
We know that Proxmox API works in general. Proxmox GUI and CLI use it, many other people use it both directly and via 3rd party libraries.
You need to add some debug code to find your issue. For example, print out variables and final API calls. Check the pveproxy log. Confirm that what you are trying to do works via "pvesh".
I am sorry but I can't understand what you mean by final API calls and what type of "debug code" would you add ?
Again thank you very much.
Jean B.
 
I think you do not understand very well the problem or I wasn't clear but I am not having any error as well on the php application side, and on the proxmox.
Hi @JeanBro, you mentioned in your original post that the update was not working, but did not mention any steps you took to troubleshoot it. You did provide the code you are using, but your code makes calls to some external functions (ie getting IPs) and we have no idea whether the values it receives are valid. There is simply no way for anyone to say what could be wrong.

You can try:
a) reducing the number of things you are trying to update to one. If that works, keep adding until things break.
b) adding PHP code to print out the variables before they are sent to Proxmox
c) adding PHP code to print the API string before it is sent to Proxmox
d) reaching out to the library developer

I am sorry but I can't understand what you mean by final API calls and what type of "debug code" would you add ?
I haven't touched PHP in many many many years. A quick search on how to print the array you generated in your sample code led me to: https://stackoverflow.com/questions/9816889/how-can-i-echo-or-print-an-array-in-php


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Last edited:
Hi,
I have followed your idea of reducing the number of things that I am trying to update and I 've found that the problem are comming from the $server_id , $cores , $ram and $id_service . And I don't know where is the error because they are comming from here :
PHP:
$this->insert = $this->pdo->prepare('INSERT INTO `cloud_servers` SET idservice = :idservice, userid = :userid, server = :server, status = :status, image = :image, password = :password, address_ip = :address_ip, plan_name = :plan_name, space = :space, ram = :ram, cores = :cores, hdd_model = :hdd_model, date_created = :date_created, date_updated = :date_updated');
    $this->insert->bindValue(':idservice', $id_service, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':userid', $userid, $this->pdo::PARAM_INT);
    $this->insert->bindValue(':server', $server, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':status', 'pending', $this->pdo::PARAM_STR);
    $this->insert->bindValue(':image', $image, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':password', '123456', $this->pdo::PARAM_STR);
    $this->insert->bindValue(':address_ip', 'null', $this->pdo::PARAM_STR);
    $this->insert->bindValue(':plan_name', $plan_name, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':space', $space, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':ram', $ram, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':cores', $cores, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':hdd_model', $hdd_model, $this->pdo::PARAM_STR);
    $this->insert->bindValue(':date_created', date('Y-m-d H:i:s'), $this->pdo::PARAM_STR);
    $this->insert->bindValue(':date_updated', date('Y-m-d H:i:s'), $this->pdo::PARAM_STR);
    $this->insert->execute();
    $this->PVECloud = new PVECloud();
    $this->PVECloud->createVM($id_service, $userid, $server, $image, 'null', $space, $ram, $cores);
}
and the variables are save on the database so I can't find the error.
Thank you for your help.
Jean B.
 
Hi Jean,
Without knowing the database structure/context, strings, and variables that are being fed, and without access to the entire code base and infrastructure - it's impossible to find the cause.

I think you'd agree that this discussion is well outside of the topic of this forum: "Proxmox VE: Installation and configuration".
Perhaps, the most optimal approach for you is to hire a short-term PHP developer/consultant for assistance.

PS if you want to troubleshoot this on your own, then start adding "print $var" type things, it may help.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!