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

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Tue Jul 15 15:45:12 UTC 2014


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

Support lookup and update method for ticket.

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

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index d1cec70..3309759 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -782,6 +782,23 @@ def vmiface_update(self, vm, mac, params):
             info['model'] = params['model']
         return mac
 
+    def vmticket_lookup(self, vm):
+        dom = self._get_vm(vm)
+        to = dom.ticket.get('passwdValidTo')
+        if to is not None and to <= time.time():
+            raise OperationFailed("KCHVM0031E", {'name': vm})
+        return {"passwd": dom.ticket['passwd']}
+
+    def vmticket_update(self, vm, params):
+        dom = self._get_vm(vm)
+        password = params.get("passwd")
+        password = password if password is not None else "".join(
+            random.sample(string.ascii_letters + string.digits, 8))
+        expire = params.get("expire")
+        dom.ticket['passwd'] = password
+        if expire is not None:
+            dom.ticket['passwdValidTo'] = time.time() + expire
+
     def tasks_get_list(self):
         with self.objstore as session:
             return session.get_list('task')
@@ -1033,6 +1050,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"}
         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