create_image的逻辑流程是这样子地:
1. fetch_img from glance and save it to _base named to <cache_id>.part
2. if img format not raw then run: qemu-img convert -O raw /var/lib/nova/instances/_base/<cache_id>.part /var/lib/nova/instances/_base/<cache_id>.converted
3. rm <cache_id>.part
4. rename <cache_id>.converted to <cache_id>
5. copy_qcow2_img at _base: cp <cache_id> to <cache_id>_<root_disk_size>
6. disk.extend(<cache_id>_<root_disk_size>, root_disk_size)
7. create_cow_img: qemu-img create -f qcow2 -o backing_file=<cache_id>_<root_disk_size> /var/lib/nova/instances/instance-xxxxxxxx/disk
因为有这个cache的关系,所以修改了模板后需要做两件事情
1. 删除_base的下的cache,cache_id和image的对应关系如下:
root_fname = hashlib.sha1(image_id).hexdigest()
2. 修改数据库image对应的checksum,可以写个工作或者直接md5sum一下
glance image-update <uuid> --checksum=xxxxxxxx
基本上create_image的流程算是简单了解了一下,其实我感觉openstack的网络才是最复杂的,现在我们还是用的VlanManager,但是我对iptables不太了解,不太懂NAT,SNAT各种,所以碰上浮动IP的问题,我有点不知道怎么调试,只能各种猜测(arp, tcpdump, tracepath)。
this all, done!
Command parameters:
‘filename’ is a disk image filename
‘fmt’ is the disk image format. It is guessed automatically in most cases
‘cache’ is the cache mode used to write the output disk image, the valid options are: ‘none’, ‘writeback’ (default, except for convert), ‘writethrough’, ‘directsync’ and ‘unsafe’ (default for convert)
‘size’ is the disk image size in bytes. Optional suffixes ‘k’ or ‘K’ (kilobyte, 1024), ‘M’ (megabyte, 1024k), ‘G’ (gigabyte, 1024M) and T (terabyte, 1024G) are supported. ‘b’ is ignored.
‘output_filename’ is the destination disk image filename
‘output_fmt’ is the destination format
‘options’ is a comma separated list of format specific options in a name=value format. Use -o ? for an overview of the options supported by the used format
‘-c’ indicates that target image must be compressed (qcow format only)
‘-u’ enables unsafe rebasing. It is assumed that old and new backing file match exactly. The image doesn’t need a working backing file before rebasing in this case (useful for renaming the backing file)
‘-h’ with or without a command shows this help and lists the supported formats
‘-p’ show progress of command (only certain commands)
‘-S’ indicates the consecutive number of bytes that must contain only zeros for qemu-img to create a sparse image during conversion
‘–output’ takes the format in which the output must be done (human or json)
Parameters to check subcommand:
‘-r’ tries to repair any inconsistencies that are found during the check. ‘-r leaks’ repairs only cluster leaks, whereas ‘-r all’ fixes all kinds of errors, with a higher risk of choosing the wrong fix or hiding corruption that has already occurred.
Parameters to snapshot subcommand:
‘snapshot’ is the name of the snapshot to create, apply or delete
‘-a’ applies a snapshot (revert disk to saved state)
‘-c’ creates a snapshot
‘-d’ deletes a snapshot
‘-l’ lists all snapshots in the given image