[Users] Register a disk image via oVirt REST api

Itamar Heim iheim at redhat.com
Mon Jan 20 21:46:22 UTC 2014


On 01/20/2014 11:39 PM, Satya Vempati wrote:
> It is a disk image (could be raw/cow, preallocated/thin provisioned). But is just a file. The REST API doesn't take a file path to convert the disk image into a system disk.

you need to place it in the storage domain according to the naming 
convention the storage domain has, then you can simply register it.

>
> -----Original Message-----
> From: Itamar Heim [mailto:iheim at redhat.com]
> Sent: Monday, January 20, 2014 1:37 PM
> To: Satya Vempati; Juan Hernandez; users at ovirt.org
> Subject: Re: [Users] Register a disk image via oVirt REST api
>
> On 01/20/2014 11:36 PM, Satya Vempati wrote:
>> Well, the crux of the problem is that there doesn't seem to be a way to convert the disk image I have into a disk that the system will recognize.
>
> why, which format is it?
>
>>
>> -----Original Message-----
>> From: Itamar Heim [mailto:iheim at redhat.com]
>> Sent: Monday, January 20, 2014 1:32 PM
>> To: Satya Vempati; Juan Hernandez; users at ovirt.org
>> Subject: Re: [Users] Register a disk image via oVirt REST api
>>
>> On 01/20/2014 11:30 PM, Satya Vempati wrote:
>>> Thanks Juan and Itamar.
>>>
>>> As Juan said, I am trying take a file that I have that contains the
>>> image of a disk and create a disk in the system with the same content
>>>
>>>     I am taking a similar approach to the one Juan described. I am creating a VM and then creating a new disk with the same size and attributes as my disk image. Then I am replacing the disk image of the new disk with the file that contains the image of the disk I want.  That seems to work but seemed too hacky/clumsy. I was hoping there is a more straightforward/clean way to do this.
>>
>> you can just place the disk on the storage, register the disk, and attach it to a VM?
>>
>>>
>>> -----Original Message-----
>>> From: Juan Hernandez [mailto:jhernand at redhat.com]
>>> Sent: Saturday, January 18, 2014 8:27 AM
>>> To: Satya Vempati; users at ovirt.org
>>> Cc: Itamar Heim
>>> Subject: Re: [Users] Register a disk image via oVirt REST api
>>>
>>> On 01/17/2014 11:28 PM, Itamar Heim wrote:
>>>> On 01/16/2014 07:21 PM, Satya Vempati wrote:
>>>>> I have a disk image (i.e. a file) that I want to register as a disk
>>>>> using the REST API.
>>>>>
>>>>> The REST API works with existing disks, but does the API work with
>>>>> disk images?
>>>>
>>>> can you pleas explain what do you mean by an image compared to a disk?
>>>>
>>>
>>> I think that what you want is to take a file that you have that contains the image of a disk and create a disk in the system with the same content.
>>>
>>> As far as I know we don't have any direct way to do this. You will need to create an empty disk in oVirt, and then attach it to a virtual machine. Once it is attached to that virtual machine then you can write to it, but always via the virtual machine. For example, you can use the API as follows to create a new disk that isn't attached to any VM:
>>>
>>> curl \
>>> -k \
>>> -X POST \
>>> -H "Accept: application/xml" \
>>> -H "Content-Type: application/xml" \
>>> -d "
>>> <disk>
>>>      <name>newdisk</name>
>>>      <size>1073741824</size>
>>>      <format>raw</format>
>>>      <interface>virtio</interface>
>>> </disk>
>>> " \
>>> -u admin at internal:****** \
>>> https://rhel.example.com/api/storagedomains/the_id_of_the_storage_dom
>>> a
>>> in/disks
>>>
>>> Then prepare a VM that you will use to copy the contents of your file to the new disk, and use the API to attach the new disk to this VM (you can preserve this VM, and use multiple times for this purpose):
>>>
>>> curl \
>>> -k \
>>> -X POST \
>>> -H "Accept: application/xml" \
>>> -H "Content-Type: application/xml" \
>>> -d "
>>> <disk id='the_id_of_the_disk'/>
>>> " \
>>> -u admin at internal:****** \
>>> https://rhel.example.com/api/vms/the_id_of_the_vm/disks
>>>
>>> (Note that in order to attach the disk you have to provide the disk
>>> id returned by the API when you created it.)
>>>
>>> Then activate the disk, so that the VM can see it:
>>>
>>> curl \
>>> -k \
>>> -X POST \
>>> -H "Accept: application/xml" \
>>> -H "Content-Type: application/xml" \
>>> -d "
>>> <action/>
>>> " \
>>> -u admin at internal:****** \
>>> https://rhel.example.com/api/vms/the_id_of_the_vm/disks/the_id_of_the
>>> _
>>> disk/activate
>>>
>>> Now you will have to copy the contents of the file to the disk via the VM. For example, assuming that you have SSH enabled on that VM and that the disk device inside the VM is /dev/vdb (it won't allways be this, depends on the number and order of attached disks) you can do something like this:
>>>
>>> ssh root at myvm 'cat > /dev/vdb' < myfile.img ssh root at myvm 'sync'
>>>
>>> Once the contents of the file have been copied you can deactivate the disk and detach it from this intermediate VM, and maybe attach it to another one.
>>>
>>> Take into account that all these operations are lengthy ones, specially the operation to create the disk, and that the RESTAPI will usually return once the operation is initiated, so you will need to wait till they are finished. For example, when creating the disk you should poll the state of the VM till it is "ok".
>>>
>>> --
>>> 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 Users mailing list