# - pvmove all the LVs to the temporary PV
+yamlkeys () {
+ python -c 'if 1:
+ import yaml, sys
+ mm = yaml.load(sys.stdin.read())
+ for m in sorted(mm.iterkeys()): print m'
+}
+
+lvsleft () {
+ lvs -o name,devices xenvg \
+ | perl -lane "print \$F[0] if (\$F[1] =~ m|$DISK|)"
+}
+
+vmstolvs () {
+ perl -pe 's/^/d_/;s/$/_hda/'
+}
+
+totalsize () {
+ # handy for estimating time; output in GiB; pipe in a list of LVs
+ perl -pe 's.^.xenvg/.' \
+ | xargs lvs -o size --units=g \
+ | perl -lne '$total += $_; END { print $total; }'
+}
+
movelv () {
echo pvmoving $1...
- lvchange -an $1
pvmove -i 10 -n $1 $2
- lvchange -ay $1
}
+ssh root@xvm remctl remote web listvms \
+ | yamlkeys
+ > runningvms
+LVM_SYSTEM_DIR=/root/lvm lvsleft \
+ | grep '^d_.*_hda$' \
+ | grep -v -xf <(vmstolvs <runningvms) \
+ > offvmlvs
+for lv in $(offvmlvs); do
+ LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
+done
#FOREACH host:
-for lv in $(lvs -o lv_name --noheadings $VG); do
- movelv $VG/$lv $DISK
+for lv in $(invirt-listvms | yamlkeys | vmstolvs); do
+ LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
done
#done
-# hopefully empty:
-lvs $VG -o lv_name,devices | grep $DISK
-# if not, do some more movelv
+ssh root@xvm remctl remote web listvms \
+ | perl -lne 'print if (s/^ cdrom: //)' \
+ > usedcdroms
+LVM_SYSTEM_DIR=/root/lvm lvsleft \
+ | grep ^image_ \
+ | grep -v -xf <(perl -pe "s|/dev/$VG/||" usedcdroms) \
+ > offcdlvs
+for lv in $(offcdlvs); do
+ LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
+done
+
+# deal with $(cat usedcdroms)
+# deal with s_* LVs
+# deal with any remaining $(lvsleft)
-# This is possible if some LVs were used on more than one host during
-# migration.
+[ -z $(lvsleft) ]
# - pvremove the old PV