转换虚机镜像格式以及上传下载

320 阅读1分钟

创建 导出目录


# 创建 1 t 目录 

img_path='volumes/images'

rbd create ${volumes/images} --size  $[1024*1024]

rbd info ${volumes/images}

rbd device map  ${volumes/images}
-->out
/dev/rbd0

mkdir -p  /images

echo -e '\n/dev/rbd0 /images xfs defaults 0 0' >>  /etc/fstab

mount -a


根据 虚机 名称 导出镜像

 nova list --all-tenants 1
+--------------------------------------+-----------------+----------------------------------+---------+------------+-------------+-----------------------+
| ID                                   | Name            | Tenant ID                        | Status  | Task State | Power State | Networks              |
+--------------------------------------+-----------------+----------------------------------+---------+------------+-------------+-----------------------+
| e266a4fe-6b85-4128-b2ba-0d34f45b399b | Show03          | 91094a59edab496a8dca7e25196e41cd | ACTIVE  | -          | Running     | test1=192.168.170.205 |
| 8cdc840b-f636-4f33-a26b-7816f6a58dff | Show_1          | 91094a59edab496a8dca7e25196e41cd | ACTIVE  | -          | Running     | test1=192.168.170.13  |
| 20fa1c19-fc02-4b57-afa8-54ef8c472768 | Show_2          | 91094a59edab496a8dca7e25196e41cd | ACTIVE  | -          | Running     | test1=192.168.170.19  |
| 3b031d7e-75eb-40ca-86dc-a830da40ee92 | kk开发          | 91094a59edab496a8dca7e25196e41cd | ACTIVE  | -          | Running     | test1=192.168.170.201 |

vm_name='kk开发'
vm_id=$(nova list --all-tenants 1 | grep "${vm_name}" | awk '{print $2}')

volume_id=volume_$(cinder list --all-tenants 1 | grep "${vm_id}"  | awk '{print $2}')
echo $volume_id

windows0325


glance image-download --file /root/isos/win10GPU0325.qcow2  --progress c791f7db-0cf2-44a8-8b2e-62f3c9195f2e

qemu-img convert rbd:volumes/49c6ecb8-7ae3-4ae5-bd07-ed778d2d7851 -c -p -O qcow2 /images/win10GPU0325.qcow2 

nohup qemu-img convert rbd:volumes/49c6ecb8-7ae3-4ae5-bd07-ed778d2d7851 -c -p -O qcow2 /images/win10GPU0325.qcow2  2>&1 > /images/revert.log &

检查 导出 是否完成
 ps  -aux  | grep "qemu-img convert" | grep -v grep
root     2463333  7.1  0.0 761140 49336 pts/2    Sl   19:12   0:27 qemu-img convert rbd:volumes/49c6ecb8-7ae3-4ae5-bd07-ed778d2d7851 -c -p -O qcow2 /images/win10GPU0325.qcow2



f_path="/images/win10GPU032.qcow2"
f_name=${f_path##*/}
inner_ip='192.168.63.100'
curl  --progress-bar -o ./progress.log -u admin:brysjhhrhl356126155165352237656123565615 -T ${f_path} "http://${inner_ip}:50000/remote.php/dav/files/admin/iso/${f_name}"


转换镜像格式


 rbd list fastpool
volume-da192ea3-259d-41df-8e11-d6b98435122c

qemu-img convert rbd:volumes/87eaaa5a-644e-4f3f-b0ee-dbae1a941247 -c -p -O qcow2 win2016-datacenter.qcow2

qemu-img convert rbd:fastpool/volume-c86f67b5-e45e-4146-9ea7-1ccbd217df2f -c -p -O qcow2 zcloud31_210325.qcow2



mkdir -p /root/isos/
cd /root/isos/

glance image-download --file /root/isos/win10GPU0325.qcow2  --progress c791f7db-0cf2-44a8-8b2e-62f3c9195f2e

mkdir -p /images/isos
glance image-download --file /images/win10GPU0325.qcow2  --progress c791f7db-0cf2-44a8-8b2e-62f3c9195f2e

导出 zcloud 镜像

 rbd list fastpool
volume-da192ea3-259d-41df-8e11-d6b98435122c

nohup qemu-img convert rbd:fastpool/volume-da192ea3-259d-41df-8e11-d6b98435122c -c -p -O qcow2 zcloud31_210325.qcow2 &

上传下载


. ~/admin-openrc
glance image-list

glance help image-download

glance image-download [--file <FILE>] [--progress] <IMAGE_ID>

glance image-download --file ~/kiki/zettakit_IOS.iso  --progress 49483dbb-d2c8-4062-8d61-b54129290212

glance image-download --file ~/isos/leifeng.iso  --progress  baa50a36-aace-4474-bb2a-aa783cdd94ad

iso_name="leifeng.iso"

iso_name='zcloud_v30_05_07.qcow2'

curl  --progress-bar -o ./progress.log -u admin:brysjhhrhl356126155165352237656123565615 -T ${iso_name} "http://192.168.63.100:50000/remote.php/dav/files/admin/iso/${iso_name}"





help


<subcommand>
  explain             Describe a specific model.
  image-create        Create a new image.
  image-deactivate    Deactivate specified image.
  image-delete        Delete specified image.
  image-download      Download a specific image.
  image-list          List images you can access.
  image-reactivate    Reactivate specified image.
  image-show          Describe a specific image.
  image-tag-delete    Delete the tag associated with the given image.
  image-tag-update    Update an image with the given tag.
  image-update        Update an existing image.
  image-upload        Upload data for a specific image.
  location-add        Add a location (and related metadata) to an image.
  location-delete     Remove locations (and related metadata) from an image.
  location-update     Update metadata of an image's location.