aboutsummaryrefslogtreecommitdiff
path: root/kvm-creator
diff options
context:
space:
mode:
authorJamie McClelland <jm@mayfirst.org>2009-10-09 11:39:57 -0400
committerJamie McClelland <jm@mayfirst.org>2009-10-09 11:39:57 -0400
commit7263c76ad7cee5d0d4b9f5ee299f399e3816196e (patch)
tree9381215440bd3ee4a8d5aa2dee02bdd89a06ac38 /kvm-creator
parent5f598ad250bcd1edaab175fde6c971e0bf3c7192 (diff)
downloadkvm-manager-7263c76ad7cee5d0d4b9f5ee299f399e3816196e.tar.gz
kvm-manager-7263c76ad7cee5d0d4b9f5ee299f399e3816196e.tar.bz2
tests to ensure elements don't already exist before creating them.
Diffstat (limited to 'kvm-creator')
-rwxr-xr-xkvm-creator23
1 files changed, 16 insertions, 7 deletions
diff --git a/kvm-creator b/kvm-creator
index c19830b..2a7bb2d 100755
--- a/kvm-creator
+++ b/kvm-creator
@@ -21,7 +21,7 @@ if [ "$?" -eq 0 ]; then
MAC="${6:-$(cat /etc/sv/kvm/*/env/MAC | head -n1 | cut -f 1-5 -d: ):$(( $( cat /etc/sv/kvm/*/env/MAC | cut -f 6 -d: | sort -n | tail -n 1 ) + 1 ))}"
else
TAP=tap0
- MAC=:1
+ MAC=00:00:00:00:00:00
fi
die() {
@@ -41,13 +41,22 @@ destroy() {
}
+validate() {
+ # Make sure none of the pieces already exist.
+ [ -z "$NAME" ] && die "Please pass the name of the virtual server to create"
+ [ -z "$VG" ] && die "Please pass the name of the volume group to use"
+ getent passwd "$NAME" > /dev/null
+ [ "$?" -eq "0" ] && die "The username '$NAME' already exists."
+ getent group "$NAME" > /dev/null
+ [ "$?" -eq 0 ] && die "The group '$NAME' already exists."
+ [ -d /home/"$NAME" ] && die "The directory '/home/$NAME' already exists."
+ [ -d /etc/sv/kvm/"$NAME" ] && die "The directory '/etc/sv/kvm/$NAME' already exists."
+ [ -d /dev/mapper/${VG}-${NAME} ] && die "The logical volume $NAME already exists."
+}
+
create() {
set -e
-
-# FIXME: check that this stuff doesn't exist yet:
-
- [ -z "$NAME" ] && die "Please pass the name of the virtual server to create"
- [ -z "$VG" ] && die "Please pass the name of the volume group to use"
+ validate
adduser "$NAME" --disabled-password --gecos "$NAME KVM user,,,"
addgroup "$NAME" kvm
for dir in .ssh vms "vms/$NAME"; do
@@ -86,7 +95,7 @@ EOF
}
demo() {
-
+ validate
for foo in NAME VG TAP RAM MAC SIZE ; do
echo "$foo : ${!foo}"
done