[Kimchi-devel] [PATCH V3 4/5] vm ticket in backend: update mockmodel

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Mon Jul 21 15:51:57 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

Support lookup and update ticket for vm.

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/mockmodel.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 0e45d1e..2fa722d 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -88,6 +88,15 @@ def reset(self):
     def _static_vm_update(self, dom, params):
         state = dom.info['state']
 
+        if 'ticket' in params:
+            ticket = params.pop('ticket')
+            passwd = ticket.get('passwd')
+            dom.ticket["passwd"] = passwd if passwd is not None else "".join(
+                random.sample(string.ascii_letters + string.digits, 8))
+            expire = ticket.get('expire')
+            dom.ticket["ValidTo"] = expire if expire is None else round(
+                time.time()) + expire
+
         for key, val in params.items():
             if key == 'name':
                 if state == 'running' or params['name'] in self.vms_get_list():
@@ -129,6 +138,10 @@ def vm_lookup(self, name):
             vm.info['screenshot'] = self.vmscreenshot_lookup(name)
         else:
             vm.info['screenshot'] = None
+        vm.info['ticket'] = {"passwd": vm.ticket["passwd"]}
+        validTo = vm.ticket["ValidTo"]
+        vm.info['ticket']["expire"] = (validTo - round(time.time())
+                                       if validTo is not None else None)
         return vm.info
 
     def vm_delete(self, name):
@@ -1033,6 +1046,7 @@ def __init__(self, uuid, name, template_info):
         self.networks = template_info['networks']
         ifaces = [MockVMIface(net) for net in self.networks]
         self.storagedevices = {}
+        self.ticket = {"passwd": "123456", "ValidTo": None}
         self.ifaces = dict([(iface.info['mac'], iface) for iface in ifaces])
 
         stats = {'cpu_utilization': 20,
-- 
1.9.3




More information about the Kimchi-devel mailing list