VM Create/Edit/Delete with API

Discussion in 'Proxmox VE: Installation and configuration' started by Editor, Oct 28, 2017.

Tags:
  1. Editor

    Editor Member

    Joined:
    Apr 26, 2017
    Messages:
    80
    Likes Received:
    1
    Hello

    How I can create/edit/delete VM with API way? I reviewed the API Documentation but I couldnt find it.
    Is this possible? If yes, what is the API call to do it?

    Thank you.
     
  2. wolfgang

    wolfgang Proxmox Staff Member
    Staff Member

    Joined:
    Oct 1, 2014
    Messages:
    4,598
    Likes Received:
    306
    Hi,
    Yes it is.
    Post on path /nodes/<Nodename>/qemu
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Editor

    Editor Member

    Joined:
    Apr 26, 2017
    Messages:
    80
    Likes Received:
    1
    Thank you for your answer.
    How do I send specific values via API?
    For example;

    PHP:
    $url 'https://101.101.101.101:8006/api2/json/nodes/<NODE>/qemu/';
    $fields = array(
       
    'vmid' => urlencode($_POST['vmid']),
       
    'cores' => urlencode($_POST['cores']),
       
    'sockets' => urlencode($_POST['sockets']),
       
    'name' => urlencode($_POST['name']),
       
    'memory' => urlencode($_POST['memory']),
       
    'onboot' => urlencode($_POST['onboot'])
    );
    foreach(
    $fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string'&');
    $ch curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL$url);
    curl_setopt($ch,CURLOPT_POSTcount($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS$fields_string);
    Could it be a correct CURL?
     
  4. Editor

    Editor Member

    Joined:
    Apr 26, 2017
    Messages:
    80
    Likes Received:
    1
    I'm still waiting for help :)
     
  5. wolfgang

    wolfgang Proxmox Staff Member
    Staff Member

    Joined:
    Oct 1, 2014
    Messages:
    4,598
    Likes Received:
    306
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Editor

    Editor Member

    Joined:
    Apr 26, 2017
    Messages:
    80
    Likes Received:
    1
    Can you give me an example for create VM/tempalte with PHP? I would like vm create code
    I'm looking for a sample VM create code from last week but I can not find.

    The codes on GitHub are not working
     
  7. Editor

    Editor Member

    Joined:
    Apr 26, 2017
    Messages:
    80
    Likes Received:
    1
    Why does nobody want to help?
     
  8. tom

    tom Proxmox Staff Member
    Staff Member

    Joined:
    Aug 29, 2006
    Messages:
    13,449
    Likes Received:
    391
    Main purpose of this forum is helping in installation and configuration.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Editor

    Editor Member

    Joined:
    Apr 26, 2017
    Messages:
    80
    Likes Received:
    1
    Thank you for your answer, really
    I understand. Could you tell me that? Can I create or clone VM with API?
     
  10. udo

    udo Well-Known Member
    Proxmox Subscriber

    Joined:
    Apr 22, 2009
    Messages:
    5,829
    Likes Received:
    158
    Hi,
    found your post during an search.

    So you can create an vm with pvesh (you must adapt that for php):
    Code:
    pvesh create /nodes/pve01/qemu -name special-vm -vmid 123 \
                 -scsi0 local-lvm:32 \
                 -memory 4096 -cpu host -socket 2 -cores 2 \
                 -net0 virtio,bridge=vmbr0 \
                 -cdrom backup:iso/debian9.iso
    
    Udo
     
  11. Editor

    Editor Member

    Joined:
    Apr 26, 2017
    Messages:
    80
    Likes Received:
    1
    Thank you Udo!
     
  12. hocine kheddadji

    hocine kheddadji New Member

    Joined:
    Apr 17, 2019
    Messages:
    1
    Likes Received:
    0
    proxmoxer.core.ProxmoxResource object at 0x0000018545A45FD0

    i was get this result but i don't have a VM !!!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice