xen xcp-ng – how to start, startall, stop, stopall VMs

  linux, xcp-ng

how to start a VM by passing the VM name

#!/bin/bash

if [ -z "$1" ]; then
  echo "syntax: startVm.sh VM_NAME"
  exit 1
fi

VMNAME=$1

echo "starting vm: $VMNAME now"
xe vm-start vm="$VMNAME" 2>&1

How to start all available VMs

#!/bin/bash

ALL=`xe vm-list power-state=halted --minimal`

for UUID in $(echo $ALL | sed "s/,/ /g")
do
   VMNAME=`xe vm-list params=name-label uuid=$UUID --minimal`
   echo "Now starting up vm: $VMNAME "
   xe vm-start uuid=$UUID
done

how to shut down a VM by passing the VM name

#!/bin/bash

if [ -z "$1" ]; then
  echo "syntax: stopVm.sh VM_NAME"
  exit 1
fi

VMNAME=$1

echo "shutting down vm: $VMNAME now"
xe vm-shutdown vm="$VMNAME" 2>&1

How to shut down ALL running VMs

#!/bin/bash

ALL=`xe vm-list is-control-domain=false power-state=running --minimal`

for UUID in $(echo $ALL | sed "s/,/ /g")
do
   VMNAME=`xe vm-list params=name-label uuid=$UUID --minimal`
   echo "Now shutting down vm: $VMNAME "
#   xe vm-shutdown uuid=$UUID
done