xenapi: Set VM memory before starting it

If someone was re-using an existing template, for a memory change, he
needed to re-install the vm. This change sets the osdomu mem before
starting it, so it doesn't matter how much memory did the VM had
according to the template. It also removes the memory manipulation bits
from install-os-vpx.sh.

Change-Id: Iad85f573b90c23140012c20c552a17277d9c97a0
This commit is contained in:
Mate Lakat 2013-08-30 13:28:31 +01:00
parent 117af3430f
commit 16ed068db5
3 changed files with 28 additions and 29 deletions

View File

@ -268,3 +268,22 @@ function attach_network() {
xe network-attach uuid=$net host-uuid=$host
}
function set_vm_memory() {
local vm_name_label
local memory
vm_name_label="$1"
memory="$2"
local vm
vm=$(_vm_uuid "$vm_name_label")
xe vm-memory-limits-set \
static-min=${memory}MiB \
static-max=${memory}MiB \
dynamic-min=${memory}MiB \
dynamic-max=${memory}MiB \
uuid=$vm
}

View File

@ -228,8 +228,11 @@ if [ -z "$templateuuid" ]; then
$THIS_DIR/scripts/install-os-vpx.sh \
-t "$UBUNTU_INST_TEMPLATE_NAME" \
-n "$UBUNTU_INST_BRIDGE_OR_NET_NAME" \
-l "$GUEST_NAME" \
-r "$OSDOMU_MEM_MB"
-l "$GUEST_NAME"
set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB"
xe vm-start vm="$GUEST_NAME"
# wait for install to finish
wait_for_VM_to_halt
@ -255,6 +258,9 @@ fi
# Install XenServer tools, and other such things
$THIS_DIR/prepare_guest_template.sh "$GUEST_NAME"
# Set virtual machine parameters
set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB"
# start the VM to run the prepare steps
xe vm-start vm="$GUEST_NAME"

View File

@ -20,8 +20,6 @@
set -eux
BRIDGE=
RAM=
BALLOONING=
NAME_LABEL=
TEMPLATE_NAME=
@ -29,7 +27,7 @@ usage()
{
cat << EOF
Usage: $0 -t TEMPLATE_NW_INSTALL -l NAME_LABEL [-n BRIDGE] [-r RAM] [-b]
Usage: $0 -t TEMPLATE_NW_INSTALL -l NAME_LABEL [-n BRIDGE]
Install a VM from a template
@ -37,9 +35,6 @@ cat << EOF
-h Shows this message.
-t template VM template to use
-b Enable memory ballooning. When set min_RAM=RAM/2 max_RAM=RAM.
-r MiB Specifies RAM used by the VPX, in MiB.
By default it will take the value from the XVA.
-l name Specifies the name label for the VM.
-n bridge The bridge/network to use for eth0. Defaults to xenbr0
EOF
@ -53,12 +48,6 @@ get_params()
h) usage
exit 1
;;
b)
BALLOONING=1
;;
r)
RAM=$OPTARG
;;
n)
BRIDGE=$OPTARG
;;
@ -119,19 +108,6 @@ create_vif()
}
set_memory()
{
local v="$1"
if [ "$RAM" != "" ]
then
echo "Setting RAM to $RAM MiB."
[ "$BALLOONING" == 1 ] && RAM_MIN=$(($RAM / 2)) || RAM_MIN=$RAM
xe vm-memory-limits-set static-min=16MiB static-max=${RAM}MiB \
dynamic-min=${RAM_MIN}MiB dynamic-max=${RAM}MiB \
uuid="$v"
fi
}
# Make the VM auto-start on server boot.
set_auto_start()
@ -161,5 +137,3 @@ set_auto_start "$vm_uuid"
create_vif "$vm_uuid"
xe vm-param-set other-config:os-vpx=true uuid="$vm_uuid"
xe vm-param-set actions-after-reboot=Destroy uuid="$vm_uuid"
set_memory "$vm_uuid"
xe vm-start uuid=$vm_uuid