Sfoglia il codice sorgente

实现在创建快照时,禁止重复创建操作

James Iter 8 anni fa
parent
commit
decca48f66
2 ha cambiato i file con 34 aggiunte e 3 eliminazioni
  1. 33 2
      api/guest.py
  2. 1 1
      templates/guests_show.html

+ 33 - 2
api/guest.py

@@ -24,6 +24,7 @@ from models import OSTemplateInitializeOperate
 from models import GuestXML
 from models import SSHKeyGuestMapping
 from models import SSHKey
+from models import Snapshot
 from models import status
 
 
@@ -824,18 +825,48 @@ def r_get_by_filter():
         row['url'] = url_for('v_ssh_keys.show')
         ssh_key_id_mapping[row['id']] = row
 
+    rows, _ = Snapshot.get_by_filter(filter_str=':'.join(['guest_uuid', 'in', ','.join(uuids)]))
+
+    snapshots_guest_uuid_mapping = dict()
+
+    for row in rows:
+        guest_uuid = row['guest_uuid']
+        if guest_uuid not in snapshots_guest_uuid_mapping:
+            snapshots_guest_uuid_mapping[guest_uuid] = list()
+
+        snapshots_guest_uuid_mapping[guest_uuid].append(row)
+
     for i, guest in enumerate(ret['data']):
+
+        guest_uuid = ret['data'][i]['uuid']
+
         if 'ssh_keys' not in ret['data'][i]:
             ret['data'][i]['ssh_keys'] = list()
 
-        if ret['data'][i]['uuid'] in guest_uuid_ssh_key_id_mapping:
-            for ssh_key_id in guest_uuid_ssh_key_id_mapping[ret['data'][i]['uuid']]:
+        if guest_uuid in guest_uuid_ssh_key_id_mapping:
+            for ssh_key_id in guest_uuid_ssh_key_id_mapping[guest_uuid]:
 
                 if ssh_key_id not in ssh_key_id_mapping:
                     continue
 
                 ret['data'][i]['ssh_keys'].append(ssh_key_id_mapping[ssh_key_id])
 
+        if 'snapshot' not in ret['data'][i]:
+            ret['data'][i]['snapshot'] = {
+                'creatable': True,
+                'mapping': list()
+            }
+
+        if guest_uuid in snapshots_guest_uuid_mapping:
+            ret['data'][i]['snapshot']['mapping'] = snapshots_guest_uuid_mapping[guest_uuid]
+
+            for snapshot in snapshots_guest_uuid_mapping[guest_uuid]:
+                if snapshot['progress'] == 100:
+                    continue
+
+                else:
+                    ret['data'][i]['snapshot']['creatable'] = False
+
     return ret
 
 

+ 1 - 1
templates/guests_show.html

@@ -719,7 +719,7 @@
                                     </a>
                                 </li>
                                 <li class="divider"></li>
-                                <li class="">
+                                <li class="{% if not item.snapshot.creatable %} disabled {% endif %}">
                                     <a href="javascript:;" data-toggle="modal" data-target="#create_snapshot_modal"
                                        onclick="$('#instance_uuid').val($($(this).parent().parent().parent().parent().parent().children()[0]).text());
                                                 $('#create_snapshot_instance_desc').text($($(this).parent().parent().parent().parent().parent().children()[2]).find('div a')[0].textContent + '/' + $($(this).parent().parent().parent().parent().parent().children()[2]).find('div p')[0].textContent);