Skip to content

Commit

Permalink
Merge pull request #55 from OpenNebula/vmtweak3
Browse files Browse the repository at this point in the history
improve deploy-tweaks
  • Loading branch information
atodorov-storpool authored Apr 18, 2019
2 parents 5b1e953 + 21ce608 commit aa4b208
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 52 deletions.
41 changes: 31 additions & 10 deletions docs/advanced_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ The script add additional tunes to the _clock_ entry when the _hyperv_ feature i

### cpu.py

The script create/tweak the _cpu_ element of the domain XML. The following variables are commonly used
The script create/tweak the _cpu_ element of the domain XML.

> Default values could be exported via the `kvmrc` file.

#### T_CPU_SOCKETS and T_CPU_THREADS
Expand All @@ -366,27 +368,45 @@ USER_TEMPLATE/T_CPU_THREADS = 2
</cpu>
```

#### Other
#### Advanced

The following variables were made available for use in some corner cases.

> For advanced use only! A special care should be taken when mixing the variables as some of the options are not compatible when combined.
T_CPU_FEATURES
##### T_CPU_MODE

Possible options: _custom_, _host-model_, _host-passthrough_.

Special keyword _delete_ will instruct the helper to delete the element.

##### T_CPU_FEATURES

Comma separated list of supported features. The policy could be added using a colon (':') as separator.

T_CPU_MODEL
##### T_CPU_MODEL

T_CPU_VENDOR
The optional _fallback_ attribute could be set after the model, separated with a colon (':').
The special keyword _delete_ will instruct the helper to delete the element.

T_CPU_CHECK
##### T_CPU_VENDOR

T_CPU_MATCH
Could be set only when a `model` is defined.

##### T_CPU_CHECK

Possible options: _none_, _partial_, _full_.
The special keyword _delete_ will instruct the helper to delete the element.

##### T_CPU_MATCH

Possible options: _minimum_, _exact_, _strict_.
The special keyword _delete_ will instruct the helper to delete the element.

T_CPU_MODE

### volatile2dev.py

The script will reconfigure the volatile disks from file to device when the VM disk's TM_MAD is _storpool_
The script will reconfigure the volatile disks from file to device when the VM disk's TM_MAD is _storpool_.

```xml
<disk type='file' device='disk'>
Expand All @@ -407,11 +427,12 @@ to
</disk>
```

To do the changes when hot-attaching a volatile disk the original attach_disk script (`/var/lib/one/remotes/vmm/kvm/attach_disk`) should be pathed too:
To do the changes when hot-attaching a volatile disk the original attach_disk script (`/var/lib/one/remotes/vmm/kvm/attach_disk`) should be patched too:

```bash
cd /var/lib/one/remotes/vmm/kvm
patch -p1 < ~/addon-storpool/patches/vmm/5.8.0/attach_disk.patch
```

> The installation script should apply the patch too
6 changes: 5 additions & 1 deletion vmm/kvm/deploy-tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ if [ -f ./config ]; then
fi

SCRIPT_PATH="$(dirname $0)"
source "$SCRIPT_PATH/../../etc/vmm/kvm/kvmrc"
if [ -f "$SCRIPT_PATH/../../etc/vmm/kvm/kvmrc" ]; then
source "$SCRIPT_PATH/../../etc/vmm/kvm/kvmrc"
elif [ -f "$SCRIPT_PATH/kvmrc"]; then
source "$SCRIPT_PATH/kvmrc"
fi
source "$SCRIPT_PATH/../../scripts_common.sh"

function splog()
Expand Down
116 changes: 75 additions & 41 deletions vmm/kvm/deploy-tweaks.d.example/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#--------------------------------------------------------------------------- #

from __future__ import print_function
import os
from sys import argv, exit, stderr
from xml.etree import ElementTree as ET

Expand Down Expand Up @@ -48,6 +49,8 @@ def indent(elem, level=0):
doc = ET.parse(xmlDomain)
root = doc.getroot()

changed = 0

for prefix, uri in ns.items():
ET.register_namespace(prefix, uri)

Expand All @@ -71,11 +74,10 @@ def indent(elem, level=0):

cpu = root.find('./cpu')
if cpu is None:
cpu = ET.SubElement(root, 'cpu', {
'mode' : 'host-passthrough',
})
cpu = ET.SubElement(root, 'cpu')


threads = 1
threads = int(os.getenv('T_CPU_THREADS', 1))
cpu_threads = vm.find('.//USER_TEMPLATE/T_CPU_THREADS')
if cpu_threads is not None:
try:
Expand All @@ -86,7 +88,7 @@ def indent(elem, level=0):
print("USER_TEMPLATE/CPU_THREADS is '{0}' Error:{1}".format(cpu_threads.text,e))
exit(1)

sockets = 0
sockets = int(os.getenv('T_CPU_SOCKETS', 0))
cpu_sockets = vm.find('.//USER_TEMPLATE/T_CPU_SOCKETS')
if cpu_sockets is not None:
try:
Expand All @@ -104,6 +106,8 @@ def indent(elem, level=0):
'threads' : '{0}'.format(threads),
})

changed = 1

numa = ET.SubElement(cpu, 'numa')
for i in range(sockets):
cpuStart = socket_cpu_threads * i
Expand All @@ -115,75 +119,105 @@ def indent(elem, level=0):
'memory' : '{0}'.format(cpuMem),
})

cpu_features = vm.find('.//USER_TEMPLATE/T_CPU_FEATURES')
cpu_features = os.getenv('T_CPU_FEATURES', None)
vm_cpu_features = vm.find('.//USER_TEMPLATE/T_CPU_FEATURES')
if vm_cpu_features is not None:
cpu_features = vm_cpu_features.text
if cpu_features is not None:
features = cpu_features.text
for f in features.split(','):
for f in cpu_features.split(','):
arr = f.split(':')
policy = 'optional'
name = arr[0]
if len(arr) > 1:
policy = arr[1]
feature = ET.SubElement(cpu, 'feature' , {
'policy' : policy,
'name' : name
})
if len(arr) > 1:
if arr[1] in ['force','require','optional','disable','forbid']:
feature.set('policy', arr[1])
changed = 1


cpu_model = vm.find('.//USER_TEMPLATE/T_CPU_MODEL')
cpu_model = os.getenv('T_CPU_MODEL', None)
vm_cpu_model = vm.find('.//USER_TEMPLATE/T_CPU_MODEL')
if vm_cpu_model is not None:
cpu_model = vm_cpu_model.text
if cpu_model is not None:
model = cpu.find('./model')
if cpu_model.text is not None:
m = cpu_model.text.split(':')
if cpu_model.lower() == 'delete':
if model is not None:
cpu.remove(model)
changed = 1
else:
m = cpu_model.split(':')
cpu_model = m[0]
fallback = None
if len(m) > 1:
fallback = m[1]
if model is None:
model = ET.SubElement(cpu, 'model')
model.text = cpu_model
if len(m) > 1:
fallback = m[1]
if fallback is not None:
model.set('fallback', fallback)
if cpu_model:
model.text = cpu_model
else:
model.text = ''
else:
cpu.remove(model)

cpu_vendor = vm.find('.//USER_TEMPLATE/T_CPU_VENDOR')
if model.get('fallback') is not None:
del model.atrrib['fallback']
changed = 1

cpu_vendor = os.getenv('T_CPU_VENDOR', None)
vm_cpu_vendor = vm.find('.//USER_TEMPLATE/T_CPU_VENDOR')
if vm_cpu_vendor is not None:
cpu_vendor = vm_cpu_vendor.text
if cpu_vendor is not None:
model = cpu.find('./model')
if model is not None:
vendor = cpu.find('.//vendor')
if vendor is None:
vendor = ET.SubElement(cpu, 'vendor')
vendor.text = cpu_vendor.text
vendor.text = cpu_vendor
changed = 1

cpu_check = vm.find('.//USER_TEMPLATE/T_CPU_CHECK')
cpu_check = os.getenv('T_CPU_CHECK', None)
vm_cpu_check = vm.find('.//USER_TEMPLATE/T_CPU_CHECK')
if vm_cpu_check is not None:
cpu_check = vm_cpu_check.text
if cpu_check is not None:
check = cpu_check.text
if check in [ '', None ]:
if cpu_check.lower() == 'delete':
if cpu.get('check') is not None:
del cpu.attrib['check']
changed = 1
else:
cpu.set('check', check)

cpu_match = vm.find('.//USER_TEMPLATE/T_CPU_MATCH')
if cpu_check in ['none','partial','full']:
cpu.set('check', cpu_check)
changed = 1

cpu_match = os.getenv('T_CPU_MATCH', None)
vm_cpu_match = vm.find('.//USER_TEMPLATE/T_CPU_MATCH')
if vm_cpu_match is not None:
cpu_match = vm_cpu_match.text
if cpu_match is not None:
match = cpu_match.text
if match in [ '', None ]:
if cpu_match.lower() == 'delete':
if cpu.get('match') is not None:
del cpu.attrib['match']
changed = 1
else:
cpu.set('match', match)

cpu_mode = vm.find('.//USER_TEMPLATE/T_CPU_MODE')
if cpu_match in ['minimum','exact','strict']:
cpu.set('match', cpu_match)
changed = 1

cpu_mode = os.getenv('T_CPU_MODE', None)
vm_cpu_mode = vm.find('.//USER_TEMPLATE/T_CPU_MODE')
if vm_cpu_mode is not None:
cpu_mode = vm_cpu_mode.text
if cpu_mode is not None:
mode = cpu_mode.text
if mode in [ '', None]:
if cpu.get('match') is not None:
if cpu_mode.lower() == 'delete':
if cpu.get('mode') is not None:
del cpu.attrib['mode']
changed = 1
else:
cpu.set('mode', mode)
if cpu_match in ['custom','host-model','host-passthrough']:
cpu.set('mode', cpu_mode)
changed = 1

indent(root)
doc.write(xmlDomain)
if changed:
indent(root)
doc.write(xmlDomain)

0 comments on commit aa4b208

Please sign in to comment.