Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
legacy free qcow2 images
#!/bin/bash
DATE=`date +%Y%m%d`
DATE='latest'
IMAGES_DIR='/var/lib/libvirt/images'
CLOUDIMAGE_FEDORA29='https://download.fedoraproject.org/pub/fedora/linux/releases/29/Cloud/x86_64/images/Fedora-Cloud-Base-29-1.2.x86_64.qcow2'
CLOUDIMAGE_UBUNTU1804='https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img'
CLOUDIMAGE_CENTOS7='https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2c'
CLOUDIMAGE_DEBIAN='http://cdimage.debian.org/cdimage/openstack/current-9/debian-9-openstack-amd64.qcow2'
dnf -qy install bridge-utils libvirt virt-install qemu-kvm libguestfs-tools cloud-utils python-glanceclient python-openstackclient jq
# Fedora Images
wget -O $IMAGES_DIR/fedora29-$DATE $CLOUDIMAGE_FEDORA29
virt-customize -v \
-a $IMAGES_DIR/fedora29-$DATE \
--update \
--install nano \
--selinux-relabel
virt-sparsify --compress --check-tmpdir=continue --tmp $IMAGES_DIR \
$IMAGES_DIR/fedora29-$DATE \
$IMAGES_DIR/fedora29-$DATE.qcow2
rm -rf $IMAGES_DIR/fedora29-$DATE
wget -O $IMAGES_DIR/centos7-$DATE $CLOUDIMAGE_CENTOS7
virt-customize -v \
-a $IMAGES_DIR/centos7-$DATE \
--update \
--install nano \
--selinux-relabel
virt-sparsify --compress --check-tmpdir=continue --tmp $IMAGES_DIR \
$IMAGES_DIR/centos7-$DATE \
$IMAGES_DIR/centos7-$DATE.qcow2
rm -rf $IMAGES_DIR/centos7-$DATE
# Debian Images
wget -O $IMAGES_DIR/ubuntu1804-$DATE $CLOUDIMAGE_UBUNTU1804
virt-customize -v \
-a $IMAGES_DIR/ubuntu1804-$DATE \
--update \
--install nano \
--run-command "echo 'datasource:\n OpenStack:\n apply_network_config: True' | tee /etc/cloud/cloud.cfg.d/98-openstack-network.cfg"
qemu-img convert -O qcow2 \
-c $IMAGES_DIR/ubuntu1804-$DATE \
$IMAGES_DIR/ubuntu1804-$DATE.qcow2
rm -rf $IMAGES_DIR/ubuntu1804-$DATE
wget -O $IMAGES_DIR/debian9-$DATE $CLOUDIMAGE_DEBIAN
virt-customize -v \
-a $IMAGES_DIR/debian9-$DATE \
--update \
--install nano
qemu-img convert -O qcow2 \
-c $IMAGES_DIR/debian9-$DATE \
$IMAGES_DIR/debian9-$DATE.qcow2
rm -rf $IMAGES_DIR/debian9-$DATE
# Deactivate old images
openstack image list -f json | jq -r '.[] | select(.Name | startswith("debian9-")) | .ID' | xargs -I id sh -c "openstack image set --deactivate id"
openstack image list -f json | jq -r '.[] | select(.Name | startswith("fedora29-")) | .ID' | xargs -I id sh -c "openstack image set --deactivate id"
openstack image list -f json | jq -r '.[] | select(.Name | startswith("ubuntu1804-")) | .ID' | xargs -I id sh -c "openstack image set --deactivate id"
openstack image list -f json | jq -r '.[] | select(.Name | startswith("centos7-")) | .ID' | xargs -I id sh -c "openstack image set --deactivate id"
# Opload images (use glance for --progress)
glance image-create \
--architecture amd64 \
--container-format bare \
--disk-format qcow2 \
--os-distro debian \
--progress \
--file $IMAGES_DIR/debian9-$DATE.qcow2 \
--name debian9-$DATE
glance image-create \
--architecture amd64 \
--container-format bare \
--disk-format qcow2 \
--os-distro fedora \
--progress \
--file $IMAGES_DIR/fedora29-$DATE.qcow2 \
--name fedora29-$DATE
glance image-create \
--architecture amd64 \
--container-format bare \
--disk-format qcow2 \
--os-distro ubuntu \
--progress \
--file $IMAGES_DIR/ubuntu1804-$DATE.qcow2 \
--name ubuntu1804-$DATE
glance image-create \
--architecture amd64 \
--container-format bare \
--disk-format qcow2 \
--os-distro centos \
--progress \
--file $IMAGES_DIR/centos7-$DATE.qcow2 \
--name centos7-$DATE
if ! openstack flavor list | grep -q m1.tiny; then
openstack flavor create --id 1 --ram 512 --disk 1 --vcpus 1 m1.tiny
openstack flavor create --id 2 --ram 2048 --disk 20 --vcpus 1 m1.small
openstack flavor create --id 3 --ram 4096 --disk 40 --vcpus 2 m1.medium
openstack flavor create --id 4 --ram 8192 --disk 80 --vcpus 4 m1.large
openstack flavor create --id 5 --ram 16384 --disk 160 --vcpus 8 m1.xlarge
openstack flavor create --id 10 --ram 1024 --disk 5 --vcpus 2 c1.tiny
openstack flavor create --id 11 --ram 1024 --disk 10 --vcpus 4 c1.small
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.