mdmxenctrl.sh stage 1

This commit is contained in:
Mike D'Morto 2024-01-30 01:15:27 +07:00
parent 122485144a
commit 4a83a56447

141
mdmxen/bin/mdmxenctrl.sh Executable file
View File

@ -0,0 +1,141 @@
#!/bin/bash -x
# mdmxen project - helper for configuration
# author mikedmorto 2024 year
VERSION="0.0.1-dev"
XE="/opt/xensource/bin/xe"
##### PARAMETERS#####
METRIC="$1"
ITEM="$2"
export LC_ALL=""
export LANG="en_US.UTF-8"
# include this host config
. /root/bin/mdmxen/etc/host.cfg
# include libraries for work
. /root/bin/mdmxen/lib/libsys.sh
. /root/bin/mdmxen/lib/librotation.sh
. /root/bin/mdmxen/lib/libxen.sh
#functions
# 1 uuid
# ret = vm_name
fn.xen.vm.exist_by_uuid(){
RET=`${XE} vm-param-get param-name=name-label uuid=$1 | wc -l`
echo ${RET}
}
fn.xen.vm.get_vmname_by_uuid(){
RET=`${XE} vm-param-get param-name=name-label uuid=$1`
echo ${RET}
}
fn.xen.vm.exist_by_vmname(){
RET=`${XE} vm-list is-control-domain=false is-a-snapshot=false params=uuid name-label=$1 | awk -F: '/^[^#]/ { print $2 }' | tr -d ' ' | tr ';' '\n' | wc -l`
echo ${RET}
}
fn.xen.vm.get_uuid_by_vmname(){
RET=`${XE} vm-list is-control-domain=false is-a-snapshot=false params=uuid name-label=$1 | awk -F: '/^[^#]/ { print $2 }' | tr -d ' ' | tr ';' '\n'`
echo ${RET}
}
fn.xen.pool.autostart.get(){
POOL_UUID=`${XE} pool-list params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"`
RET=`${XE} pool-param-get param-name=other-config uuid=${POOL_UUID} param-key=auto_poweron`
echo "xen.pool.autostart = ${RET}"
}
fn.xen.vm.list.autostart.get(){
XVM_LIST=`${XE} vm-list is-control-domain=false is-a-snapshot=false params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"`
for VM_UUID in ${XVM_LIST}; do
# VM_NAME=`${XE} vm-param-get param-name=name-label uuid=${VM_UUID}`
VM_NAME=$( fn.xen.vm.get_vmname_by_uuid ${VM_UUID} )
RET=`${XE} vm-param-get param-name=other-config param-key=auto_poweron uuid=${VM_UUID}`
echo "${VM_UUID} = ${VM_NAME} = ${RET}"
done
}
#main
##### PARAMETERS#####
METRIC="$1"
ITEM="$2"
case "$METRIC" in
xen.version)
RET=`cat "/etc/xensource-inventory" | awk -F"=" '{if($1=="PRODUCT_VERSION"){print $2} }' | tr -d "'" `
echo ${RET}
exit 0
;;
script.version)
echo ${VERSION}
;;
xen.pool.autostart.get)
fn.xen.pool.autostart.get
;;
xen.pool.autostart.set.true)
POOL_UUID=`${XE} pool-list params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"`
RET=`${XE} pool-param-set other-config:auto_poweron=true uuid=${POOL_UUID}`
fn.xen.pool.autostart.get
;;
xen.pool.autostart.set.false)
POOL_UUID=`${XE} pool-list params=uuid | egrep -o "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"`
RET=`${XE} pool-param-set other-config:auto_poweron=false uuid=${POOL_UUID}`
fn.xen.pool.autostart.get
;;
xen.vm.list.autostart.get)
fn.xen.vm.list.autostart.get
;;
xen.mv.autostart.get)
VM_NAME=$2
EXIST=$( fn.xen.vm.exist_by_vmname ${VM_NAME} )
if [[ $EXIST = 0 ]]
then
echo "vmname is not exist"
exit 1
fi
VM_UUID=$( fn.xen.vm.get_uuid_by_vmname ${VM_NAME} )
RET=`${XE} vm-param-get param-name=other-config param-key=auto_poweron uuid=${VM_UUID}`
echo "${VM_UUID} = ${VM_NAME} = ${RET}"
;;
help)
echo "please use these params
{
xen.version
script.version
xen.pool.autostart.get
xen.pool.autostart.set.true
xen.pool.autostart.set.false
xen.vm.list.autostart.get
xen.mv.autostart.get
NEED:
xen.mv.autostart.set.true
xen.mv.autostart.set.false
}"
;;
*)
echo ""
;;
esac