summaryrefslogtreecommitdiffstats
path: root/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables_legacy.inc
blob: 05d55f00c496d0788f18d85b905cacae08421798 (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
###########################################
# Include: Set hardware related variables #
###########################################

# take last two digits of current pid...
VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2)

# 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=1536
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 ]"

# TODO: We should only generate the suffix here (last 3 octets) as the first 3 are
# dependant on the virtualizer/emulator. Check if any run-virt.include still relies on
# $macguestpart/$macaddr. If so, fix it to use its specific first 3 bytes
# and append $macaddrssuffix
macguestpart="00:50:56:${VM_ID}"
machostpart=$(echo "${hostmacaddr}" | awk -F ":" '{print $(NF-1)":"$NF}')
macaddr=$(echo "${macguestpart}:${machostpart}" | tr "[a-z]" "[A-Z]")
macaddrsuffix=$(echo "${VM_ID}:${machostpart}" | tr "[a-z]" "[A-Z]")

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

# 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"