[Users] Register a disk image via oVirt REST api

--_000_16669B246DBC4D4EB043E6B646D51CEA2231D8mbx025w1ca8exch02_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I have a disk image (i.e. a file) that I want to register as a disk using t= he REST API. The REST API works with existing disks, but does the API work with disk ima= ges? --_000_16669B246DBC4D4EB043E6B646D51CEA2231D8mbx025w1ca8exch02_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr= osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:= //www.w3.org/TR/REC-html40"> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
<meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)"> <style><!-- /* Font Definitions */ @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:11.0pt; font-family:"Calibri","sans-serif";} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:"Calibri","sans-serif"; color:windowtext;} .MsoChpDefault {mso-style-type:export-only; font-family:"Calibri","sans-serif";} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.WordSection1 {page:WordSection1;} --></style><!--[if gte mso 9]><xml> <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext=3D"edit"> <o:idmap v:ext=3D"edit" data=3D"1" /> </o:shapelayout></xml><![endif]--> </head> <body lang=3D"EN-US" link=3D"blue" vlink=3D"purple"> <div class=3D"WordSection1"> <p class=3D"MsoNormal">I have a disk image (i.e. a file) that I want to reg= ister as a disk using the REST API. <o:p></o:p></p> <p class=3D"MsoNormal"><o:p> </o:p></p> <p class=3D"MsoNormal">The REST API works with existing disks, but does the= API work with disk images?<o:p></o:p></p> <p class=3D"MsoNormal"><o:p> </o:p></p> </div> </body> </html> --_000_16669B246DBC4D4EB043E6B646D51CEA2231D8mbx025w1ca8exch02_--

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?

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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_domain/dis... 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@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@internal:****** \ https://rhel.example.com/api/vms/the_id_of_the_vm/disks/the_id_of_the_disk/a... 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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

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. -----Original Message----- From: Juan Hernandez [mailto:jhernand@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_domain/dis... 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@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@internal:****** \ https://rhel.example.com/api/vms/the_id_of_the_vm/disks/the_id_of_the_disk/a... 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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_domain/dis...
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@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@internal:****** \ https://rhel.example.com/api/vms/the_id_of_the_vm/disks/the_id_of_the_disk/a...
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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

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. -----Original Message----- From: Itamar Heim [mailto:iheim@redhat.com] Sent: Monday, January 20, 2014 1:32 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_doma 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@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@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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

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@redhat.com] Sent: Monday, January 20, 2014 1:32 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_doma 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@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@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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

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. -----Original Message----- From: Itamar Heim [mailto:iheim@redhat.com] Sent: Monday, January 20, 2014 1:37 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Monday, January 20, 2014 1:32 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@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@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@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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

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@redhat.com] Sent: Monday, January 20, 2014 1:37 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Monday, January 20, 2014 1:32 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@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@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@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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

Yes, but to place it in the storage domain, first I need to create a disk on the storage domain and replace the disk image with my disk image. That seems a little hacky. If registering a disk image isn't possible today, should I file a bug/rfe to put it on the roadmap? -----Original Message----- From: Itamar Heim [mailto:iheim@redhat.com] Sent: Monday, January 20, 2014 1:46 PM To: Satya Vempati; Juan Hernandez; users@ovirt.org Subject: Re: [Users] Register a disk image via oVirt REST api 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@redhat.com] Sent: Monday, January 20, 2014 1:37 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Monday, January 20, 2014 1:32 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_do m 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@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@internal:****** \ https://rhel.example.com/api/vms/the_id_of_the_vm/disks/the_id_of_th e _ 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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

On 01/20/2014 11:56 PM, Satya Vempati wrote:
Yes, but to place it in the storage domain, first I need to create a disk on the storage domain and replace the disk image with my disk image. That seems a little hacky.
for block storage, true. for NFS, you can just copy the file over?
If registering a disk image isn't possible today, should I file a bug/rfe to put it on the roadmap?
for nfs, should be easy. for block storage, yes, to create a disk/LV not via the engine.
-----Original Message----- From: Itamar Heim [mailto:iheim@redhat.com] Sent: Monday, January 20, 2014 1:46 PM To: Satya Vempati; Juan Hernandez; users@ovirt.org Subject: Re: [Users] Register a disk image via oVirt REST api
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@redhat.com] Sent: Monday, January 20, 2014 1:37 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Monday, January 20, 2014 1:32 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_do m 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@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@internal:****** \ https://rhel.example.com/api/vms/the_id_of_the_vm/disks/the_id_of_th e _ 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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.

Luckily I am on NFS, so it is relatively easy to copy the file over. Which, by the way, is what I am doing now. But that means I rely on the internal knowledge of how the storage domain and the disks are laid out on the file system. Relying on the internals of the oVirt implementation is what I consider to be hacky/clumsy. That is why I was searching for a clean solution although the hacky way seems to be working. -----Original Message----- From: Itamar Heim [mailto:iheim@redhat.com] Sent: Monday, January 20, 2014 2:02 PM To: Satya Vempati; Juan Hernandez; users@ovirt.org Subject: Re: [Users] Register a disk image via oVirt REST api On 01/20/2014 11:56 PM, Satya Vempati wrote:
Yes, but to place it in the storage domain, first I need to create a disk on the storage domain and replace the disk image with my disk image. That seems a little hacky.
for block storage, true. for NFS, you can just copy the file over?
If registering a disk image isn't possible today, should I file a bug/rfe to put it on the roadmap?
for nfs, should be easy. for block storage, yes, to create a disk/LV not via the engine.
-----Original Message----- From: Itamar Heim [mailto:iheim@redhat.com] Sent: Monday, January 20, 2014 1:46 PM To: Satya Vempati; Juan Hernandez; users@ovirt.org Subject: Re: [Users] Register a disk image via oVirt REST api
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@redhat.com] Sent: Monday, January 20, 2014 1:37 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Monday, January 20, 2014 1:32 PM To: Satya Vempati; Juan Hernandez; users@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@redhat.com] Sent: Saturday, January 18, 2014 8:27 AM To: Satya Vempati; users@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@internal:****** \ https://rhel.example.com/api/storagedomains/the_id_of_the_storage_d o m 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@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@internal:****** \ https://rhel.example.com/api/vms/the_id_of_the_vm/disks/the_id_of_t h e _ 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@myvm 'cat > /dev/vdb' < myfile.img ssh root@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.
participants (3)
-
Itamar Heim
-
Juan Hernandez
-
Satya Vempati