[ovirt-devel] Hello and a question about adding an extra disk for a VM in oVirt.

Juan Hernández jhernand at redhat.com
Tue Nov 3 14:10:30 UTC 2015


On 11/03/2015 02:07 PM, zhukaijie wrote:
> I'm doing an experiment in which I need to attack an extra 512MB disk for a VM. But from oVirt open virtualization manager it seems that the smallest disk can be added to VM in oVirt is 1GB? So does it exist any means to easily add an 512MB disk for an VM in oVirt?
>

You may want to try the RESTAPI, for example with a simple shell script:

---8<---
#!/bin/sh -ex

url="https://engine.example.com/ovirt-engine/api"
user="admin at internal"
password="..."
vm_id="bdbb5dcf-8a60-481d-8705-93b3dbbead55"
disk_size="$((512 * 2**20))"

curl \
--verbose \
--cacert /etc/pki/ovirt-engine/ca.pem \
--request POST \
--user "${user}:${password}" \
--header "Accept: application/xml" \
--header "Content-Type: application/xml" \
--data "
<disk>
  <interface>virtio</interface>
  <format>raw</format>
  <provisioned_size>${disk_size}</provisioned_size>
  <storage_domains>
    <storage_domain>
      <name>mydata</name>
    </storage_domain>
  </storage_domains>
</disk>
" \
"${url}/vms/${vm_id}/disks"
--->8---

Or if you prefer Python:

---8<---
#!/usr/bin/python

from ovirtsdk.api import API
from ovirtsdk.xml import params

# Connect to the server:
api = API(
    url="https://engine.example.com/ovirt-engine/api",
    username="admin at internal",
    password="...",
    ca_file="/etc/pki/ovirt-engine/ca.pem",
    debug=False
)

# Find the VMs:
vm = api.vms.get(name="myvm")

# Add the disk:
api.disks.add(
    params.Disk(
        interface="virtio",
        format="raw",
        provisioned_size=512 * 2**20,
        storage_domains=params.StorageDomains(
            storage_domain=[
                params.StorageDomain(
                    name="mydata"
                )
            ]
        )
    )
)

# Close the connection:
api.disconnect()
--->8---

-- 
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.



More information about the Devel mailing list