Frank Kobzik has uploaded a new change for review.
Change subject: hooks: vm: graphics console listen on all ifs
......................................................................
hooks: vm: graphics console listen on all ifs
This hook makes the graphics console device listen on all interfaces (instead
of listening on display network).
The configuration is described in the hook itself.
Signed-off-by: Frantisek Kobzik <fkobzik(a)redhat.com>
Change-Id: I512586497209cb631e684c5f09084dcecfca0ec3
---
A vdsm_hooks/console_listen_on_all_ifs/before_vm_start.py
1 file changed, 101 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/61/35661/1
diff --git a/vdsm_hooks/console_listen_on_all_ifs/before_vm_start.py
b/vdsm_hooks/console_listen_on_all_ifs/before_vm_start.py
new file mode 100755
index 0000000..a26f50e
--- /dev/null
+++ b/vdsm_hooks/console_listen_on_all_ifs/before_vm_start.py
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+
+import os
+import ConfigParser
+import sys
+import hooking
+import traceback
+from xml.dom import minidom
+from vdsm.config import config
+
+#
+# Placed in before_vm_start
+#
+# This hook makes graphics console server listen on all interfaces (instead of
+# on one dedicated display network).
+#
+# Configuration:
+# in /etc/vdsm.conf add this line:
+# console_listen_on_all_ifs = true
+#
+# Example input:
+# <domain>
+# <devices>
+# <graphics type='spice' port='5900' autoport='yes'
listen='127.0.0.1'>
+# <listen type='address' address='127.0.0.1'/>
+# </graphics>
+# </devices>
+# </domain>
+# Corresponding output:
+# <domain>
+# <devices>
+# <graphics type='spice' port='5900' autoport='yes'
listen='127.0.0.1'>
+# <listen type='address' address='0'/>
+# </graphics>
+# </devices>
+# </domain>
+#
+
+
+def wipe_listen_children(elem):
+ listens = elem.getElementsByTagName('listen')
+ for listen in listens:
+ elem.removeChild(listen)
+
+
+def add_promiscuous_listen(elem, doc):
+ listen = doc.createElement('listen')
+ listen.setAttribute('type', 'address')
+ listen.setAttribute('address', '0')
+ elem.appendChild(listen)
+
+
+def adjust_graphics(domxml):
+ for graphics in domxml.getElementsByTagName('graphics'):
+ wipe_listen_children(graphics)
+ add_promiscuous_listen(graphics, domxml)
+
+
+def main():
+ try:
+ if config.getboolean('vars', 'console_listen_on_all_ifs'):
+ sys.stderr.write('console_listen_on_all_ifs: '
+ 'starting to modify vm \n')
+ domxml = hooking.read_domxml()
+ adjust_graphics(domxml)
+ hooking.write_domxml(domxml)
+ except ConfigParser.NoOptionError:
+ sys.stderr.write('console_listen_on_all_ifs: WARN : '
+ 'Couldn\'t read configuration.')
+ except:
+ sys.stderr.write('console_listen_on_all_ifs: ERROR %s\n' %
+ traceback.format_exc())
+ sys.exit(2)
+
+
+def test():
+ domxml = minidom.parseString("""
+ <domain>
+ <devices>
+ <graphics type='spice' port='5900' autoport='yes'
listen='127.0.0.1'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+ </devices>
+ </domain>
+ """)
+ print "Domain before applying hook: %s" % \
+ domxml.toxml(encoding='UTF-8')
+ adjust_graphics(domxml)
+ print "Graphics console after applying hook: %s" % \
+ domxml.toxml(encoding='UTF-8')
+
+
+if __name__ == '__main__':
+ try:
+ if '--test' in sys.argv:
+ test()
+ else:
+ main()
+ except:
+ hooking.exit_hook('extnet hook: [unexpected error]: %s\n' %
+ traceback.format_exc())
--
To view, visit
http://gerrit.ovirt.org/35661
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I512586497209cb631e684c5f09084dcecfca0ec3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Frank Kobzik <fkobzik(a)redhat.com>