Browse code

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

Mate Lakat authored on 2013/08/30 21:28:31
Showing 3 changed files
... ...
@@ -268,3 +268,22 @@ function attach_network() {
268 268
 
269 269
     xe network-attach uuid=$net host-uuid=$host
270 270
 }
271
+
272
+function set_vm_memory() {
273
+    local vm_name_label
274
+    local memory
275
+
276
+    vm_name_label="$1"
277
+    memory="$2"
278
+
279
+    local vm
280
+
281
+    vm=$(_vm_uuid "$vm_name_label")
282
+
283
+    xe vm-memory-limits-set \
284
+        static-min=${memory}MiB \
285
+        static-max=${memory}MiB \
286
+        dynamic-min=${memory}MiB \
287
+        dynamic-max=${memory}MiB \
288
+        uuid=$vm
289
+}
... ...
@@ -228,8 +228,11 @@ if [ -z "$templateuuid" ]; then
228 228
     $THIS_DIR/scripts/install-os-vpx.sh \
229 229
         -t "$UBUNTU_INST_TEMPLATE_NAME" \
230 230
         -n "$UBUNTU_INST_BRIDGE_OR_NET_NAME" \
231
-        -l "$GUEST_NAME" \
232
-        -r "$OSDOMU_MEM_MB"
231
+        -l "$GUEST_NAME"
232
+
233
+    set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB"
234
+
235
+    xe vm-start vm="$GUEST_NAME"
233 236
 
234 237
     # wait for install to finish
235 238
     wait_for_VM_to_halt
... ...
@@ -255,6 +258,9 @@ fi
255 255
 # Install XenServer tools, and other such things
256 256
 $THIS_DIR/prepare_guest_template.sh "$GUEST_NAME"
257 257
 
258
+# Set virtual machine parameters
259
+set_vm_memory "$GUEST_NAME" "$OSDOMU_MEM_MB"
260
+
258 261
 # start the VM to run the prepare steps
259 262
 xe vm-start vm="$GUEST_NAME"
260 263
 
... ...
@@ -20,8 +20,6 @@
20 20
 set -eux
21 21
 
22 22
 BRIDGE=
23
-RAM=
24
-BALLOONING=
25 23
 NAME_LABEL=
26 24
 TEMPLATE_NAME=
27 25
 
... ...
@@ -29,7 +27,7 @@ usage()
29 29
 {
30 30
 cat << EOF
31 31
 
32
-  Usage: $0 -t TEMPLATE_NW_INSTALL -l NAME_LABEL [-n BRIDGE] [-r RAM] [-b] 
32
+  Usage: $0 -t TEMPLATE_NW_INSTALL -l NAME_LABEL [-n BRIDGE]
33 33
 
34 34
   Install a VM from a template
35 35
 
... ...
@@ -37,9 +35,6 @@ cat << EOF
37 37
 
38 38
      -h           Shows this message.
39 39
      -t template  VM template to use
40
-     -b           Enable memory ballooning. When set min_RAM=RAM/2 max_RAM=RAM.
41
-     -r MiB       Specifies RAM used by the VPX, in MiB.
42
-                  By default it will take the value from the XVA.
43 40
      -l name      Specifies the name label for the VM.
44 41
      -n bridge    The bridge/network to use for eth0. Defaults to xenbr0
45 42
 EOF
... ...
@@ -53,12 +48,6 @@ get_params()
53 53
       h) usage
54 54
          exit 1
55 55
          ;;
56
-      b)
57
-         BALLOONING=1
58
-         ;;
59
-      r)
60
-         RAM=$OPTARG
61
-         ;;
62 56
       n)
63 57
          BRIDGE=$OPTARG
64 58
          ;;
... ...
@@ -119,19 +108,6 @@ create_vif()
119 119
 }
120 120
 
121 121
 
122
-set_memory()
123
-{
124
-  local v="$1"
125
-  if [ "$RAM" != "" ]
126
-  then
127
-    echo "Setting RAM to $RAM MiB."
128
-    [ "$BALLOONING" == 1 ] && RAM_MIN=$(($RAM / 2)) || RAM_MIN=$RAM
129
-    xe vm-memory-limits-set static-min=16MiB static-max=${RAM}MiB \
130
-                            dynamic-min=${RAM_MIN}MiB dynamic-max=${RAM}MiB \
131
-                            uuid="$v"
132
-  fi
133
-}
134
-
135 122
 
136 123
 # Make the VM auto-start on server boot.
137 124
 set_auto_start()
... ...
@@ -161,5 +137,3 @@ set_auto_start "$vm_uuid"
161 161
 create_vif "$vm_uuid"
162 162
 xe vm-param-set other-config:os-vpx=true uuid="$vm_uuid"
163 163
 xe vm-param-set actions-after-reboot=Destroy uuid="$vm_uuid"
164
-set_memory "$vm_uuid"
165
-xe vm-start uuid=$vm_uuid