Skip to content

Commit

Permalink
Merge pull request #18 from OndrejHome/develop
Browse files Browse the repository at this point in the history
1.0 Inclusion
  • Loading branch information
OndrejHome authored Nov 13, 2016
2 parents 2da98a0 + 089e81a commit c97d205
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ starting VM using the 'hack files'.
** you can use 'losetup' to create a loopback device with LVM
* preconfigured VM disk images and XML files (downloadable separately)
* 'dhcp_release' for proper DHCP static leases release
* 'flock' for image locking (prevent use of not fully imported images)
* (optional) 'bash-completion' for bash completion to work
* (optional) 'pv' to show import progress
* (optional) 'curl' to pass http(s) link for image_import
* (optional) OVMF EUFI image for UEFI support in images

====== Installation ======
=== From source
Expand Down
55 changes: 26 additions & 29 deletions fast-vm
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ fast-vm remove_image ImageName
fast-vm list_images [short]
fast-vm create ImageName <base |VmNumber> [PathToLibvirtXML] [PathToHacksFile]
fast-vm delete VmNumber
fast-vm edit_note [NoteText]
fast-vm edit_note VmNumber [NoteText]
fast-vm list [all|active|inactive [short]]
fast-vm start VmNumber [console|ssh [/path/to/custom/script]]
fast-vm stop VmNumber [graceful]
fast-vm console VmNumber
fast-vm ssh VmNumber [/path/to/custom/script]
== fast-vm version 0.9.5 <ofamera@redhat.com> ==
== fast-vm version 1.0 <ofamera@redhat.com> ==
EOF
;;
esac
Expand Down Expand Up @@ -323,9 +323,6 @@ case "$1" in
hack_file=$(download_file "$hack_file")
fi
fi
(
# beginning of locked section
flock -n 9 || exit 4
if [ -b "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" ]; then
pmsg $P_ERROR "base image for '$image_name' version already exists. To remove image use 'remove_image' parameter\n"
exit 1
Expand All @@ -339,8 +336,12 @@ case "$1" in
fi
fi

pmsg $P_DEBUG "importing image $image_path into /dev/$THINPOOL_VG/$VM_PREFIX$image_name\n"
# change group of LV so we can use it for locking
echo "chgrp" "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" | sudo -n $FASTVM_HELPER
(
# beginning of locked section
flock -x -n 9 || exit 4
pmsg $P_DEBUG "importing image $image_path into /dev/$THINPOOL_VG/$VM_PREFIX$image_name\n"

if [ "$image_path" = "empty" ]; then
if [ "$(whoami)" = 'root' ]; then
Expand Down Expand Up @@ -398,7 +399,7 @@ case "$1" in

pmsg $P_INFO "Image $image_name imported\n"
# end of locked section
) 9>/tmp/fast-vm.img.${image_name}.lock
) 9</dev/$THINPOOL_VG/$VM_PREFIX$image_name
if [ "$?" != "0" ]; then
pmsg $P_ERROR "It is not possible to import image $image_name now as it is being used by fast-vm or other process at the moment\n"
exit 1
Expand Down Expand Up @@ -433,11 +434,12 @@ case "$1" in
;;
esac

# change group of LV so we can use it for locking
echo "chgrp" "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" | sudo -n $FASTVM_HELPER
(
# beginning of locked section
flock -n 9 || exit 4
flock -s -n 9 || exit 4
if [ -b "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" ]; then
echo "chgrp" "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" | sudo -n $FASTVM_HELPER
pmsg $P_DEBUG "compressing the image $image_name into $(pwd)/${image_name}.img.${image_format}\n"
$compress_cmd /dev/$THINPOOL_VG/$VM_PREFIX$image_name > $(pwd)/${image_name}.img.${image_format}
if [ "$?" -eq "0" ]; then
Expand All @@ -450,7 +452,7 @@ case "$1" in
usage export_image
fi
# end of locked section
) 9>/tmp/fast-vm.img.${image_name}.lock
) 9</dev/$THINPOOL_VG/$VM_PREFIX$image_name
if [ "$?" != "0" ]; then
pmsg $P_ERROR "It is not possible to export image $image_name now as it is being used by fast-vm or other process at the moment\n"
exit 1
Expand All @@ -462,13 +464,10 @@ case "$1" in
image_name="$2"
if [ -z "$image_name" ]; then pmsg $P_ERROR "missing image name\n"; usage remove_image; fi

(
# beginning of locked section
flock -n 9 || exit 4
if [ -b "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" ]; then
pmsg $P_DEBUG "stopping and undefining the base VM of $image_name\n"
virsh --connect qemu:///system destroy $VM_PREFIX$image_name 2>&1|$DEBUG_LOG_CMD
virsh --connect qemu:///system undefine $VM_PREFIX$image_name 2>&1|$DEBUG_LOG_CMD
virsh --connect qemu:///system undefine $VM_PREFIX$image_name --nvram 2>&1|$DEBUG_LOG_CMD
pmsg $P_DEBUG "removing LV $VM_PREFIX$image_name ...\n"
echo "lvremove" "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" | sudo -n $FASTVM_HELPER
pmsg $P_DEBUG "removing XML and hack file of $image_name...\n"
Expand All @@ -484,14 +483,6 @@ case "$1" in
pmsg $P_ERROR "image "$image_name" not found\n"
usage remove_image
fi
# end of locked section
) 9>/tmp/fast-vm.img.${image_name}.lock
if [ "$?" != "0" ]; then
pmsg $P_ERROR "It is not possible to remove image $image_name now as it is being used by fast-vm or other process at the moment\n"
exit 1
else
rm -f /tmp/fast-vm.img.${image_name}.lock
fi
;;
create)
image_name="$2"
Expand Down Expand Up @@ -531,9 +522,6 @@ case "$1" in
fi
done

(
# beginning of locked section
flock -n 9 || exit 4
if [ ! -b "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" ]; then
pmsg $P_ERROR "Missing image for ${image_name}.\n/dev/$THINPOOL_VG/$VM_PREFIX$image_name not found.\nFirst import image using 'fast-vm image_import $image_name'\n"
exit 2
Expand Down Expand Up @@ -561,6 +549,11 @@ case "$1" in
fi
fi

# change group of LV so we can use it for locking
echo "chgrp" "/dev/$THINPOOL_VG/$VM_PREFIX$image_name" | sudo -n $FASTVM_HELPER
(
# beginning of locked section - FIXME: maybe only part with 'lvcreate' should be protected by lock
flock -s -n 9 || exit 4
# special case for creating only base image
if [ "$vm_number" = "base" ]; then
VM_NAME="$VM_PREFIX$image_name"
Expand Down Expand Up @@ -631,7 +624,7 @@ case "$1" in

pmsg $P_INFO "VM '$VM_NAME' created\n"
# end of locked section
) 9>/tmp/fast-vm.img.${image_name}.lock
) 9</dev/$THINPOOL_VG/$VM_PREFIX$image_name
if [ "$?" != "0" ]; then
pmsg $P_ERROR "It is not possible to use image $image_name for creating VM now as it is being used by fast-vm or other process at the moment\n"
exit 1
Expand Down Expand Up @@ -747,9 +740,13 @@ case "$1" in
fi

if [ "$FASTVM_OWNER_ONLY_DELETE" == "yes" ]; then
owner=$(stat --format="%U" "$FASTVM_NOTES_DIR/$vm_number")
owner=$(stat --format="%U" "$FASTVM_NOTES_DIR/$vm_number" 2>/dev/null)
if [ $(whoami) != "root" ] && [ $(whoami) != "$owner" ]; then
pmsg $P_ERROR "only 'root' and '$owner' are allowed to delete this VM\n"
if [ -z "$owner" ]; then
pmsg $P_ERROR "only 'root' is allowed to delete this VM\n"
else
pmsg $P_ERROR "only 'root' and '$owner' are allowed to delete this VM\n"
fi
exit 1
fi
fi
Expand Down Expand Up @@ -786,7 +783,7 @@ case "$1" in
if [ -f "$FASTVM_NOTES_DIR/$vm_number" ]; then rm "$FASTVM_NOTES_DIR/$vm_number"; fi

pmsg $P_DEBUG "undefining VM $vm_name from libvirt\n"
virsh --connect qemu:///system undefine $vm_name
virsh --connect qemu:///system undefine $vm_name --nvram
if [ "$?" != '0' ]; then
pmsg $P_ERROR "failed to undefine VM $vm_name, check syslog for more information\n"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion man/configure-fast-vm.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH FAST-VM 8 "configure-fast-vm 0.9.5 (2016-06-25)" "fast-vm" "configure-fast-vm" \" -*- nroff -*-
.TH FAST-VM 8 "configure-fast-vm 1.0 (2016-06-25)" "fast-vm" "configure-fast-vm" \" -*- nroff -*-
.SH NAME
configure-fast-vm \(em script for (re)configuring fast-vm
.SH SYNOPSIS
Expand Down
7 changes: 6 additions & 1 deletion man/fast-vm.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH FAST-VM 8 "fast-vm 0.9.5 (2016-08-09)" "fast-vm" "fast-vm" \" -*- nroff -*-
.TH FAST-VM 8 "fast-vm 1.0 (2016-11-13)" "fast-vm" "fast-vm" \" -*- nroff -*-
.SH NAME
fast-vm \(em script for defining VMs from images provided in thin LVM pool
.SH SYNOPSIS
Expand Down Expand Up @@ -219,6 +219,11 @@ to VM by other means that through network to figure out its IP address.
It is save to alter imported image after you have created fast-vm VMs that are based on it. The changes you do to the imported image will be present only
in the newly created VMs. It's strongly discouraged to create VMs based on imported image when the base VM is running.

.SH UEFI SUPPORT (from fast-vm-1.0)
To use virtual machines with UEFI you will need a UEFI firmware for qemu which is most probably distributed separately from qemu.
When creating the custom image you will have to specify location of UEFI firmware and provide the location of UEFI variable files in
.RI " " "/etc/libvirt/qemu.conf" " file so the libvirt can automaticaly take care of UEFI vars creation and deletion."

.SH EXAMPLES
Import local image into fast-vm
.sp
Expand Down
2 changes: 1 addition & 1 deletion man/fast-vm.conf.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH FAST-VM.CONF 5 "fast-vm 0.9.5 (2016-10-07)" "fast-vm" "/etc/fast-vm.conf" \" -*- nroff -*-
.TH FAST-VM.CONF 5 "fast-vm 1.0 (2016-10-07)" "fast-vm" "/etc/fast-vm.conf" \" -*- nroff -*-
.SH NAME
.IR /etc/fast-vm.conf " \(em global configuration file for fast-vm"

Expand Down
9 changes: 8 additions & 1 deletion rpm/fast-vm-centos7.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: fast-vm
Version: 0.9.5
Version: 1.0
Release: 1%{?dist}
Summary: Script for defining VMs from images provided in thin LVM pool

Expand All @@ -19,6 +19,7 @@ Requires: ncurses
Requires: openssh-clients
Requires: sed
Requires: sudo
Requires: util-linux
Requires: qemu-kvm
Requires: libvirt-daemon-driver-storage
Requires: libvirt-daemon-driver-lxc
Expand Down Expand Up @@ -56,6 +57,12 @@ drive of new machine before starting VM using the 'hack files'.
%config(noreplace) %{_sysconfdir}/sudoers.d/%{name}-sudoers

%changelog
* Sun Now 13 2016 Ondrej Famera <ofamera@redhat.com> 1.0-1
- added support for handling machines with UEFI firmware
- improve error messages and documentation
- fix locking and make it dependent on image block device
(= no need for lock files and shared read lock for images)

* Sun Oct 09 2016 Ondrej Famera <ofamera@redhat.com> 0.9.5-1
- ability to have VM notes (also indicates the owners of VM)
- fix issue with DHCP lease when last VM was deleted
Expand Down
9 changes: 8 additions & 1 deletion rpm/fast-vm.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: fast-vm
Version: 0.9.5
Version: 1.0
Release: 1%{?dist}
Summary: Script for defining VMs from images provided in thin LVM pool

Expand All @@ -19,6 +19,7 @@ Requires: ncurses
Requires: openssh-clients
Requires: sed
Requires: sudo
Requires: util-linux
Requires: qemu-kvm
Requires: libvirt-daemon-driver-storage
Requires: libvirt-daemon-driver-lxc
Expand Down Expand Up @@ -62,6 +63,12 @@ drive of new machine before starting VM using the 'hack files'.
%config(noreplace) %{_sysconfdir}/sudoers.d/%{name}-sudoers

%changelog
* Sun Now 13 2016 Ondrej Famera <ofamera@redhat.com> 1.0-1
- added support for handling machines with UEFI firmware
- improve error messages and documentation
- fix locking and make it dependent on image block device
(= no need for lock files and shared read lock for images)

* Sun Oct 09 2016 Ondrej Famera <ofamera@redhat.com> 0.9.5-1
- ability to have VM notes (also indicates the owners of VM)
- fix issue with DHCP lease when last VM was deleted
Expand Down

0 comments on commit c97d205

Please sign in to comment.