https://access.redhat.com/documentation/en-us/red_hat_virtualization/4.2/html/administration_guide/vdsm_hooks_examples

1、首先自定义属性,

engine-config -s UserDefinedVMProperties=numaset=^(interleave|strict|preferred):[\^]?\d+(-\d+)?(,[\^]?\d+(-\d+)?)*$

该规则是允许下列输入
 numaset=strict:1 
 numaset=strict:1-4 
 numaset=strict:^3 
 numaset=strict:1-4,6 

设置自定义属性必须重启引擎才能生效。

定义hooking脚本,一帮通过python来写

cd /usr/libexec/vdsm/hooks/before_vm_start/

vi 50_numa.py

#!/usr/bin/python

import os
import sys
import hooking
import traceback

'''
numa hook
=========
add numa support for domain xml:

<numatune>
    <memory mode="strict" nodeset="1-4,^3" />
</numatune>

memory=interleave|strict|preferred

numaset="1" (use one NUMA node)
numaset="1-4" (use 1-4 NUMA nodes)
numaset="^3" (don't use NUMA node 3)
numaset="1-4,^3,6" (or combinations)

syntax:
    numa=strict:1-4
'''

if os.environ.has_key('numa'):
    try:
        mode, nodeset = os.environ['numa'].split(':')

        domxml = hooking.read_domxml()

        domain = domxml.getElementsByTagName('domain')[0]
        numas = domxml.getElementsByTagName('numatune')

        if not len(numas) > 0:
            numatune = domxml.createElement('numatune')
            domain.appendChild(numatune)

            memory = domxml.createElement('memory')
            memory.setAttribute('mode', mode)
            memory.setAttribute('nodeset', nodeset)
            numatune.appendChild(memory)

            hooking.write_domxml(domxml)
        else:
            sys.stderr.write('numa: numa already exists in domain xml')
            sys.exit(2)
    except:
        sys.stderr.write('numa: [unexpected error]: %s\n' % traceback.format_exc())
        sys.exit(2)
定义完脚本需要增加执行的权限
chmod +x ./50_numa
且要拷贝hooking.py 拷贝到当前目录,
cp /usr/lib/python2.7/site-packages/vdsm/hook/hooking.py ./

发表评论

电子邮件地址不会被公开。 必填项已用*标注