Show Table of Contents
A.9. 在 VDSM Hook 中检查虚拟机的自定义属性
在虚拟机的自定义属性中设置的每一个自定义项以及它的值,在调用 hook 脚本时都会被添加到系统环境参数中。因此,尽管所设定的正则表达式可以对自定义属性项中所输入的值进行一定程度的检查,您还必须在您的脚本中对所输入的值做验证。
例 A.3. 检查自定义属性
这个简单的 Python 程序实例检查自定义属性
key1 是否存在。如果它被设置,它的值会被输出到标准的错误输出中;如果它没有被设置,则没有操作会被执行。
#!/usr/bin/python
import os
import sys
if os.environ.has_key('key1'):
sys.stderr.write('key1 value was : %s\n' % os.environ['key1'])
else:
sys.exit(0)
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.