Browse Source

Member list to show ERRORED instances

Change-Id: I1b1a659c2a6ce85e375d7892a54d998b3697265f
closes-bug: #1482325
ank 2 years ago
parent
commit
44a3e4acf3

+ 6
- 7
gbpui/panels/policytargets/tables.py View File

@@ -144,13 +144,12 @@ class RemoveVMLink(tables.DeleteAction):
144 144
                           self.table.kwargs['policy_target_id']})
145 145
         try:
146 146
             pts = []
147
-            for port in api.neutron.port_list(request, device_id=instance_id):
148
-                policytarget = client.pt_list(request,
149
-                tenant_id=request.user.tenant_id, port_id=port.id)
150
-                if policytarget:
151
-                    pts.append(policytarget[0])
152
-            for pt in pts:
153
-                client.pt_delete(request, pt.id)
147
+            instance = api.nova.server_get(request, instance_id)
148
+            metadata_pts = instance.metadata.get('pts', None)
149
+            if metadata_pts:
150
+                pts = metadata_pts.split(",")
151
+                for pt in pts:
152
+                    client.pt_delete(request, pt)
154 153
             api.nova.server_delete(request, instance_id)
155 154
             LOG.debug('Deleted instance %s successfully' % instance_id)
156 155
             return http.HttpResponseRedirect(url)

+ 8
- 5
gbpui/panels/policytargets/tabs.py View File

@@ -128,6 +128,7 @@ class InstancesTab(tabs.TableTab):
128 128
             tenant_id=self.request.user.tenant_id,
129 129
             policy_target_group_id=policy_targetid)
130 130
             policy_target_ports = [x.port_id for x in policytargets]
131
+            policy_target_ids = [p.id for p in policytargets]
131 132
             marker = self.request.GET.get(
132 133
                 tables.InstancesTable._meta.pagination_param, None)
133 134
             # TODO(Sumit): Setting paginate to False is a temporary
@@ -150,11 +151,13 @@ class InstancesTab(tabs.TableTab):
150 151
             if policy_target_ports:
151 152
                 time.sleep(0.5)
152 153
             for item in instances:
153
-                for port in api.neutron.port_list(self.request,
154
-                                                  device_id=item.id):
155
-                    if port.id in policy_target_ports:
156
-                        filtered_instances.append(item)
157
-                        break
154
+                metadata_pts = item.metadata.get('pts', None)
155
+                if metadata_pts:
156
+                    pts = metadata_pts.split(",")
157
+                    for pt in pts:
158
+                        if pt in policy_target_ids:
159
+                            filtered_instances.append(item)
160
+                            break
158 161
         except Exception:
159 162
             self._has_more = False
160 163
             error_message = _('Unable to get instances')

+ 5
- 1
gbpui/panels/policytargets/workflows.py View File

@@ -582,6 +582,7 @@ class LaunchInstance(workflows.Workflow):
582 582
                 else:
583 583
                     instance_name = context['name'] + str(count)
584 584
                 nics = []
585
+                pts = []
585 586
                 for ptg_id in context['group_id']:
586 587
                     values = ptg_id.split(":")
587 588
                     ptg_id = values[0]
@@ -604,6 +605,8 @@ class LaunchInstance(workflows.Workflow):
604 605
                                 break
605 606
                     ep = client.pt_create(request, **args)
606 607
                     nics.append({'port-id': ep.port_id})
608
+                    pts.append(ep.id)
609
+                meta_data = {'pts': ','.join(pts)}
607 610
                 api.nova.server_create(request,
608 611
                                    instance_name,
609 612
                                    image_id,
@@ -618,7 +621,8 @@ class LaunchInstance(workflows.Workflow):
618 621
                                    instance_count=1,
619 622
                                    admin_pass=context['admin_pass'],
620 623
                                    disk_config=context.get('disk_config'),
621
-                                   config_drive=context.get('config_drive'))
624
+                                   config_drive=context.get('config_drive'),
625
+                                   meta=meta_data)
622 626
                 count += 1
623 627
             return True
624 628
         except Exception as e:

Loading…
Cancel
Save