blob: 9a46bc888e0c95f43219c2807751bcfb09443745 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
###########################################
# Include: Set hardware related variables #
###########################################
get_vm_id() {
local script=${BASH_SOURCE[-1]}
[ -z "$script" ] && script="$0"
if [ -n "$script" ]; then
script=$(readlink -f "$script")
if [ -n "$script" ] && [ -s "$script" ]; then
#bingo
VM_ID=$(ps ax | grep -F "$script" | grep -v 'grep' | grep -o -- "${script}.*\$" | sort -u | wc -l)
if [ "$VM_ID" -gt 0 ]; then
[ "${#VM_ID}" -eq 1 ] && VM_ID="0${VM_ID}"
[ "${#VM_ID}" -gt 2 ] && VM_ID="${VM_ID:0:2}"
[ "${#VM_ID}" -eq 2 ] && return
fi
fi
fi
# fallback: take last two digits of current pid...
VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2)
}
get_vm_id
# Make sure cpu_cores is not empty
cpu_cores=${cpu_cores:-"1"}
# Amount of memory for the VM. Be generous if diff is written to HDD
if mount | grep -q '^/dev/sd.*on.*/tmp'; then
reserve=20
min=768
max=1800
else
reserve=65
min=768
max=8192
fi
# Calculate absulute amount of RAM that should stay available to the host
reserve="$[ ( $totalmem * $reserve ) / 100 ]"
# Respect some upper and lower bounds for the host amount
[ "$reserve" -lt "$min" ] && reserve="$min"
[ "$reserve" -gt "$max" ] && reserve="$max"
# Get a result which can be divided by 4
mem="$[ ( ( $totalmem - $reserve ) / 4 ) * 4 ]"
if [ -n "$mainvirtmem" ]; then
forcemem="$[ "$mainvirtmem" / 4 * 4 ]"
mem="$forcemem"
fi
hostmem="$[ $totalmem - $mem ]"
# Fill in VMID
macaddrsuffix=$(echo "$macaddrsuffix" | sed "s/%VMID%/${VM_ID}/")
if ! echo "$macaddrprefix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then
slxlog "virt-mac" "Could not properly generate mac address prefix (got $macaddrprefix)"
fi
if ! echo "$macaddrsuffix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then
slxlog "virt-mac" "Could not properly generate mac address suffix (got $macaddrsuffix)"
fi
macaddr="$macaddrprefix:$macaddrsuffix"
# Virtual fd/cd/dvd and drive devices, floppy b: for configuration
# if $floppy_0 from virtualization.conf set then fdtest="TRUE"
fdtest=${floppy_0:+"TRUE"}
# if $fdtest not set floppy0="FALSE", else "TRUE"
floppy0=${fdtest:-"FALSE"}
# if $cdrom_0 from virtualization.conf set then cdtest="TRUE"
cdtest=${cdrom_0:+"TRUE"}
# if $cdtest not set cdrom0="FALSE", else "TRUE"
cdrom0=${cdtest:-"FALSE"}
# if $cdrom_1 from virtualization.conf set then cdtest="TRUE"
cdtest=${cdrom_1:+"TRUE"}
# if $cdtest not set cdrom1="FALSE", else "TRUE"
cdrom1=${cdtest:-"FALSE"}
# IDE is expected default, test for the virtual disk image type should
# be done while creating the runscripts ...
# TODO enable SCSI support instead of just disabling it.
ide="TRUE"
scsi="FALSE"
hddrv="ide"
audio="true"
remotedesktopport="590${VM_ID}"
# Enable 3D
enable3d=$(grep -i -o "<enable3d param=.*" "${xmlfile}" | awk -F '"' '{print $2}' | rv_clean_string)
# Add rw share for home dir
homesharepath="${HOME}/PERSISTENT"
homesharename="home"
# Add common share
commonsharepath="${HOME}/SHARE"
commonsharename="share"
# Set hostname: using original hostname and adding string
hostname="virt-$(hostname)"
writelog "\tVM Hostname:\t\t$hostname"
|