Attach/detach hdd to vm via API

Discussion in 'Proxmox VE: Installation and configuration' started by Aleksej, Nov 7, 2018.

  1. Aleksej

    Aleksej New Member

    Joined:
    Feb 25, 2018
    Messages:
    7
    Likes Received:
    0
    hi all.

    can anyone help me with this?
    i tried to use /config with params ide[2] (ide[3]...) to attach disk to vm. it works, but how to detach it? ide[2]='' returns "error parsing params"
     
  2. t.lamprecht

    t.lamprecht Proxmox Staff Member
    Staff Member

    Joined:
    Jul 28, 2015
    Messages:
    893
    Likes Received:
    87
    Hi!

    use the '-delete <property>' mechanism to delete a property, or in this case make it unused.

    A relative easy way to check what WebUI feature maps to which API call is by using your Browsers web/developer console's network tab, there you see the call in it's full form :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Aleksej

    Aleksej New Member

    Joined:
    Feb 25, 2018
    Messages:
    7
    Likes Received:
    0
    there is empty in console while doing anything in web interface.

    did you mean use it in monitor? according to https://pve.proxmox.com/pve-docs/api-viewer/index.html i can't find any similar command...
     
  4. t.lamprecht

    t.lamprecht Proxmox Staff Member
    Staff Member

    Joined:
    Jul 28, 2015
    Messages:
    893
    Likes Received:
    87
    The delete property is described in your linked article just fine, navigate to "/nodes/{node}/qemu/{vmid}/config" and select the PUT tab.

    A pvesh example would be:
    Code:
    pvesh set /nodes/nina/qemu/101/config -delete unused0
    update VM 101: -delete unused0
      Logical volume "vm-101-disk-0" successfully removed
    
    which equals an API call like:
    Code:
    PUT /nodes/nina/qemu/101/config?delete=unused0
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. t.lamprecht

    t.lamprecht Proxmox Staff Member
    Staff Member

    Joined:
    Jul 28, 2015
    Messages:
    893
    Likes Received:
    87
    Or explicitly for your case:
    Code:
    pvesh set /nodes/NODE/qemu/VMID/config -delete ide2
    
    This will first mark it unused, you then can delete it finally by deleting the respective unusedX entry.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Aleksej

    Aleksej New Member

    Joined:
    Feb 25, 2018
    Messages:
    7
    Likes Received:
    0
    thank you a lot.
    it works great.

    But now i have a different problem. i'm doing it to make users to do "clean" OS install. OS images i don't want to do unattended.

    So i need to remove all data in vm image, maybe format it and then start OS install.
    Tried to use virtio0=stor:vm-111-disk-2,size=10G (i'm using LVM) but it won't to create LV.
    So, it is nececarry to use POST on /nodes/node/storage/stor/content to create new image. If using simple storage it's ok. but in LVM what filename to use?

    i don't want to post new thread about this, as i think, very simple question. but search not return anything.
     
  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