[Kimchi-devel] [PATCH] Add image probe function

Sheldon shaohef at linux.vnet.ibm.com
Fri Jun 27 01:00:14 UTC 2014


On 06/27/2014 05:28 AM, Aline Manera wrote:
> On 06/18/2014 06:35 AM, lvroyce at linux.vnet.ibm.com wrote:
>> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>>
>> Image file probe will be used in identify image file os info and
>> generate reasonable configuration for it.
>> This will be useful when import image and create a vm from it.
>
> Do you mean to use libguestfs instead of our own code - isoinfo.py?
No.
The isoinfo.py can be replaced by linux shell command, such as "file" or 
"iso" related command.
But I think it is not necessary to replace it.
Not sure the libguestfs can also support the same function of 
isoinfo.py. If it can we can replace the
isoinfo.py


Here, I think
*/We should support create VM from an image. /*
*Create a VM from image is faster than ISO. *
So when we  create a image from image, we had better to know the OS 
distro and version.

There are several sources of an image.
1.  local image

2. remote image.  Same as Openstack glance.
Now all OS distro support both remote ISO and image.

3.  create one from a VM.
User may take several snapshots for a VM.
this way we had better to merge all snapshots to one.


Maybe we should support a image-template pool.
move the above type images to this pool.




>
>>
>> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
>> ---
>>   docs/README.md          |  9 ++++++---
>>   src/kimchi/exception.py |  2 ++
>>   src/kimchi/imageinfo.py | 42 
>> ++++++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 50 insertions(+), 3 deletions(-)
>>   create mode 100644 src/kimchi/imageinfo.py
>>
>> diff --git a/docs/README.md b/docs/README.md
>> index c658637..c341a5d 100644
>> --- a/docs/README.md
>> +++ b/docs/README.md
>> @@ -53,7 +53,8 @@ Install Dependencies
>>                           PyPAM m2crypto python-jsonschema rpm-build \
>>                           qemu-kvm python-psutil python-ethtool sos \
>>                           python-ipaddr python-lxml nfs-utils \
>> -                        iscsi-initiator-utils libxslt pyparted nginx
>> +                        iscsi-initiator-utils libxslt pyparted nginx \
>> +                        python-libguestfs libguestfs-tools
>>        # If using RHEL6, install the following additional packages:
>>        $ sudo yum install python-unittest2 python-ordereddict
>>        # Restart libvirt to allow configuration changes to take effect
>> @@ -75,7 +76,8 @@ for more information on how to configure your 
>> system to access this repository.
>>                              python-pam python-m2crypto 
>> python-jsonschema \
>>                              qemu-kvm libtool python-psutil 
>> python-ethtool \
>>                              sosreport python-ipaddr python-lxml 
>> nfs-common \
>> -                           open-iscsi lvm2 xsltproc python-parted nginx
>> +                           open-iscsi lvm2 xsltproc python-parted 
>> nginx \
>> +                           python-guestfs libguestfs-tools
>>
>>       Packages version requirement:
>>           python-jsonschema >= 1.3.0
>> @@ -89,7 +91,8 @@ for more information on how to configure your 
>> system to access this repository.
>>                             python-pam python-M2Crypto 
>> python-jsonschema \
>>                             rpm-build kvm python-psutil python-ethtool \
>>                             python-ipaddr python-lxml nfs-client 
>> open-iscsi \
>> -                          libxslt-tools python-xml python-parted
>> +                          libxslt-tools python-xml python-parted \
>> +                          python-libguestfs guestfs-tools
>>
>>       Packages version requirement:
>>           python-psutil >= 0.6.0
>> diff --git a/src/kimchi/exception.py b/src/kimchi/exception.py
>> index fcf60cc..a983d46 100644
>> --- a/src/kimchi/exception.py
>> +++ b/src/kimchi/exception.py
>> @@ -88,6 +88,8 @@ class InvalidOperation(KimchiException):
>>   class IsoFormatError(KimchiException):
>>       pass
>>
>> +class ImageFormatError(KimchiException):
>> +    pass
>>
>>   class TimeoutExpired(KimchiException):
>>       pass
>> diff --git a/src/kimchi/imageinfo.py b/src/kimchi/imageinfo.py
>> new file mode 100644
>> index 0000000..d57ecac
>> --- /dev/null
>> +++ b/src/kimchi/imageinfo.py
>> @@ -0,0 +1,42 @@
>> +#
>> +# Kimchi
>> +#
>> +# Copyright IBM Corp, 2013
>> +#
>> +# This library is free software; you can redistribute it and/or
>> +# modify it under the terms of the GNU Lesser General Public
>> +# License as published by the Free Software Foundation; either
>> +# version 2.1 of the License, or (at your option) any later version.
>> +#
>> +# This library is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> +# Lesser General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU Lesser General Public
>> +# License along with this library; if not, write to the Free Software
>> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
>> 02110-1301 USA
>> +
>> +import sys
>> +import guestfs
>> +
>> +
>> +def probe_image(image_path):
>> +    g = guestfs.GuestFS(python_return_dict=True)
>> +    g.add_drive_opts(image_path, readonly=1)
>> +    g.launch()
>> +
>> +    roots = g.inspect_os()
>> +    if len(roots) == 0:
>> +        raise ImageFormatError("No os found in given image.")
>> +
>> +    for root in roots:
>> +        version = "%d.%d" % (g.inspect_get_major_version(root),
>> +                             g.inspect_get_minor_version(root))
>> +        distro = "%s" % (g.inspect_get_distro(root))
>> +
>> +    return (distro, version)
>> +
>> +
>> +if __name__ == '__main__':
>> +    print probe_image(sys.argv[1])
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>
>
>


-- 
Thanks and best regards!

Sheldon Feng(???)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20140627/821d86fb/attachment.html>


More information about the Kimchi-devel mailing list