[Kimchi-devel] [PATCH] [Kimchi 3/9] Virt-Viewer launcher: control/vms.py and model/vms.py changes

dhbarboza82 at gmail.com dhbarboza82 at gmail.com
Thu Jul 7 12:57:42 UTC 2016


From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>

control/vms.py:
- added a new resource called VMVirtViewerFile that
returns an URL to download the virt-viewer launcher file.
- added a new URL called 'virtviewerfile' to allow
access to the new VMVirtViewerFile resource.

model/vms.py:
- turned get_graphics() into a staticmethod to be
used outside of the vms.py module.

Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
 control/vms.py | 12 ++++++++++++
 model/vms.py   |  9 +++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/control/vms.py b/control/vms.py
index bbf0fa4..645cb40 100644
--- a/control/vms.py
+++ b/control/vms.py
@@ -65,6 +65,7 @@ class VM(Resource):
         super(VM, self).__init__(model, ident)
         self.role_key = 'guests'
         self.screenshot = VMScreenShot(model, ident)
+        self.virtviewerfile = VMVirtViewerFile(model, ident)
         self.uri_fmt = '/vms/%s'
         for ident, node in sub_nodes.items():
             setattr(self, ident, node(model, self.ident))
@@ -103,3 +104,14 @@ class VMScreenShot(Resource):
         self.lookup()
         internal_uri = self.info.replace('plugins/kimchi', '')
         raise internal_redirect(internal_uri)
+
+
+class VMVirtViewerFile(Resource):
+    def __init__(self, model, ident):
+        super(VMVirtViewerFile, self).__init__(model, ident)
+        self.role_key = 'guests'
+
+    @property
+    def data(self):
+        internal_uri = self.info.replace('plugins/kimchi', '')
+        raise internal_redirect(internal_uri)
diff --git a/model/vms.py b/model/vms.py
index 6a309fc..e0b0a37 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -1154,7 +1154,7 @@ class VMModel(object):
         state = DOM_STATE_MAP[info[0]]
         screenshot = None
         # (type, listen, port, passwd, passwdValidTo)
-        graphics = self._vm_get_graphics(name)
+        graphics = self.get_graphics(name, self.conn)
         graphics_port = graphics[2]
         graphics_port = graphics_port if state == 'running' else None
         try:
@@ -1426,8 +1426,9 @@ class VMModel(object):
 
         return True
 
-    def _vm_get_graphics(self, name):
-        dom = self.get_vm(name, self.conn)
+    @staticmethod
+    def get_graphics(name, conn):
+        dom = VMModel.get_vm(name, conn)
         xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE)
 
         expr = "/domain/devices/graphics/@type"
@@ -1492,7 +1493,7 @@ class VMModel(object):
 
     def connect(self, name):
         # (type, listen, port, passwd, passwdValidTo)
-        graphics_port = self._vm_get_graphics(name)[2]
+        graphics_port = self.get_graphics(name, self.conn)[2]
         if graphics_port is not None:
             websocket.add_proxy_token(name.encode('utf-8'), graphics_port)
         else:
-- 
2.5.5




More information about the Kimchi-devel mailing list