Skip to content

Commit

Permalink
added virt-(boot,vol)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsks committed Dec 4, 2014
1 parent 363c9b6 commit 3ce4e6e
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
75 changes: 75 additions & 0 deletions virt-boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/sh

ARGS=$(getopt -o 67b:c:u: --long base-image:,config:,user-data: -n virt-boot -- "$@")

if [ $? -ne 0 ]; then
echo "usage: $myname --base-image <baseimage> <name>"
exit 2
fi

eval set -- "$ARGS"

while :; do
case "$1" in
-6)
shift
base_image_arg="-6"
;;
-7)
shift
base_image_arg="-7"
;;
-b|--base-image)
base_image_arg="-b $2"
shift 2
;;
-c|--config)
config_dir="$2"
shift 2
;;
-u|--user-data)
user_data="$2"
shift 2
;;
--) shift
break
;;
esac
done

dom_name=$1
shift

(
virsh destroy $dom_name
virsh undefine $dom_name
) > /dev/null 2>&1

boot_vol=$(virt-vol $base_image_arg $dom_name.qcow2)

if [ "$user_data" ] && [ -f "$user_data" ]; then
config_dir=$(mktemp -t -d configXXXXXX)
clean_config_dir=1
mkdir -p $config_dir/openstack/latest
cp $user_data $config_dir/openstack/latest/user_data
cat > $config_dir/openstack/latest/meta_data.json <<-EOF
{
"uuid": "$(uuidgen)",
"hostname": "$dom_name",
"name": "$dom_name"
}
EOF
fi

if [ "$config_dir" ] && [ -d "$config_dir" ]; then
config_image=$(mktemp -t configXXXXXX.iso)
mkisofs -o $config_image -r -J $config_dir
chmod a+r $config_image
fi

virt-install -n $dom_name \
--disk vol=$boot_vol,bus=virtio --import \
--vnc --noautoconsole \
${config_image:+--disk path=$config_image,device=cdrom} \
"$@"

54 changes: 54 additions & 0 deletions virt-vol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

ARGS=$(getopt -o r:67b: --long base-image: -n virt-boot -- "$@")

if [ $? -ne 0 ]; then
echo "usage: $myname --base-image <baseimage> <name>"
exit 2
fi

eval set -- "$ARGS"

while :; do
case "$1" in
-6)
shift
base_image=default/rhel-guest-image-6.6.qcow2
;;
-7)
shift
base_image=default/rhel-guest-image-7.0.qcow2
;;
-b|--base-image)
base_image=$2
shift 2
;;
-r)
dom_mem=$2
shift 2
;;
--) shift
break
;;
esac
done

vol_name=$1
shift

base_image_pool=${base_image%/*}
base_image_name=${base_image#*/}
base_image_cap=$(virsh vol-info $base_image_name $base_image_pool |
awk '$1 == "Capacity:" {print $2}' |
cut -f1 -d.)

(
virsh vol-delete $vol_name $base_image_pool
) > /dev/null 2>&1

virsh vol-create-as $base_image_pool $vol_name ${base_image_cap}G \
--format qcow2 \
--backing-vol $base_image_name \
--backing-vol-format qcow2 >&2

echo $base_image_pool/$vol_name

0 comments on commit 3ce4e6e

Please sign in to comment.