[test-API][PATCH 1/2] Add support for spice graphics

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* utils/Python/xmlgenerator.py: This extends graphics element for spice 
  XML composing, and support sub-elements settings for audio, images, 
  streaming and so on:

    <graphics type='spice' autoport='yes'>
        <image compression='auto_glz'/>
        <jpeg compression='auto'/>
        <zlib compression='auto'/>
        <playback compression='on'/>
        <streaming mode='filter'/>
        <clipboard copypaste='no'/>
    </graphics>

* utils/Python/xmlbuilder.py: Add 2 methods add_graphics() and 
  build_graphics() to XmlBuilder class.
---
 utils/Python/xmlbuilder.py   |   36 +++++++++++++++++++++++-
 utils/Python/xmlgenerator.py |   62 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/utils/Python/xmlbuilder.py b/utils/Python/xmlbuilder.py
index 5a0f8c8..739eccb 100644
--- a/utils/Python/xmlbuilder.py
+++ b/utils/Python/xmlbuilder.py
@@ -64,6 +64,13 @@ class XmlBuilder:
         hostdev_node, domain.getElementsByTagName("console")[0])
         return hostdev
 
+    def add_graphics(self, params, domain):
+        graphics = xmlgenerator.graphics_xml(params)
+        graphics_node = domain.importNode(graphics.childNodes[0], True)
+        domain.getElementsByTagName("devices")[0].insertBefore(
+        graphics_node, domain.getElementsByTagName("console")[0])
+        return graphics
+
     def build_domain_install(self, params):
         domain = xmlgenerator.domain_xml(params, True)
         self.add_disk(params, domain)
@@ -151,6 +158,12 @@ class XmlBuilder:
             self.write_toxml(hostdev)
         return hostdev.toxml()
 
+    def build_graphics(self, params):
+        graphics = xmlgenerator.graphics_xml(params)
+        if __DEBUG__:
+            self.write_toxml(graphics)
+        return graphics.toxml()
+
     def build_pool(self, params):
         pool = xmlgenerator.pool_xml(params)
         if __DEBUG__:
@@ -242,6 +255,20 @@ if __name__ == "__main__":
 
     interfacexml = xmlobj.build_interface(params)
 
+    #--------------------------
+    # get graphics xml string
+    #--------------------------
+    print '=' * 30, 'graphics xml', '=' * 30
+    params['graphtype'] = 'spice'
+    params['image'] = 'auto_glz'
+    params['jpeg'] = 'auto'
+    params['zlib'] = 'auto'
+    params['playback'] = 'on'
+    params['streaming'] = 'filter'
+    params['clipboard'] = 'no'
+
+    graphicsxml = xmlobj.build_graphics(params)
+
     #---------------------
     # get pool xml string
     #---------------------
@@ -297,6 +324,13 @@ if __name__ == "__main__":
     params['memory'] = '1048576'
     params['vcpu'] = '2'
     params['inputbus'] = 'usb'
+    params['graphtype'] = 'spice'
+    params['image'] = 'auto_glz'
+    params['jpeg'] = 'auto'
+    params['zlib'] = 'auto'
+    params['playback'] = 'on'
+    params['streaming'] = 'filter'
+    params['clipboard'] = 'no'
     params['sound'] = 'ac97'
     params['bootcd'] = '/iso/rhel5.iso'
 
@@ -367,7 +401,7 @@ if __name__ == "__main__":
     #----------------------------------------
     # get domain snapshot xml string
     #----------------------------------------
-    params['name'] = 'hello'
+    params['snapshotname'] = 'hello'
     params['description'] = 'hello snapshot'
     snapshot_xml = xmlobj.build_domain_snapshot(params)
 
diff --git a/utils/Python/xmlgenerator.py b/utils/Python/xmlgenerator.py
index d57dd33..460f2e5 100644
--- a/utils/Python/xmlgenerator.py
+++ b/utils/Python/xmlgenerator.py
@@ -233,12 +233,6 @@ def domain_xml(params, install = False):
             input_element.setAttribute('bus', 'ps2')
     devices_element.appendChild(input_element)
 
-    # <graphics>
-    graphics_element = domain.createElement('graphics')
-    graphics_element.setAttribute('type', 'vnc')
-    graphics_element.setAttribute('port', '-1')
-    graphics_element.setAttribute('keymap', 'en-us')
-    devices_element.appendChild(graphics_element)
     domain_element.appendChild(devices_element)
 
     # <sound>
@@ -253,6 +247,62 @@ def domain_xml(params, install = False):
 
     return domain
 
+def graphics_xml(params):
+    graphics = xml.dom.minidom.Document()
+    # <graphics>
+    graphics_element = graphics.createElement('graphics')
+    if not params.has_key('graphtype'):
+        params['graphtype'] == 'vnc'
+
+    graphics_element.setAttribute('type', params['graphtype'])
+    graphics.appendChild(graphics_element)
+
+    if params['graphtype'] == 'vnc':
+        graphics_element.setAttribute('port', '-1')
+        graphics_element.setAttribute('keymap', 'en-us')
+    elif params['graphtype'] == 'spice':
+        graphics_element.setAttribute('autoport', 'yes')
+        if params.has_key('image'):
+            image_element = graphics.createElement('image')
+            # image to set image compression (accepts 
+            # auto_glz, auto_lz, quic, glz, lz, off)
+            image_element.setAttribute('compression', params['image'])
+            graphics_element.appendChild(image_element)
+        if params.has_key('jpeg'):
+            jpeg_element = graphics.createElement('jpeg')
+            # jpeg for JPEG compression for images over wan (accepts 
+            # auto, never, always)
+            jpeg_element.setAttribute('compression', params['jpeg'])
+            graphics_element.appendChild(jpeg_element)
+        if params.has_key('zlib'):
+            zlib_element = graphics.createElement('zlib')
+            # zlib for configuring wan image compression (accepts 
+            # auto, never, always)
+            zlib_element.setAttribute('compression', params['zlib'])
+            graphics_element.appendChild(zlib_element)
+        if params.has_key('playback'):
+            playback_element = graphics.createElement('playback')
+            # playback for enabling audio stream compression (accepts on or off)
+            playback_element.setAttribute('compression', params['playback'])
+            graphics_element.appendChild(playback_element)
+        if params.has_key('streaming'):
+            streaming_element = graphics.createElement('streaming')
+            # streamming for settings it's mode attribute to one of 
+            # filter, all or off
+            streaming_element.setAttribute('mode', params['streaming'])
+            graphics_element.appendChild(streaming_element)
+        if params.has_key('clipboard'):
+            clipboard_element = graphics.createElement('clipboard')
+            # Copy & Paste functionality is enabled by default, and can 
+            # be disabled by setting the copypaste property to no
+            clipboard_element.setAttribute('copypaste', params['clipboard'])
+            graphics_element.appendChild(clipboard_element)
+    else:
+        print 'Wrong graphics type was specified.'
+        sys.exit(1)
+
+    return graphics
+
 def disk_xml(params, cdrom = False):
     disk = xml.dom.minidom.Document()
     # <disk> -- START
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux