CLOUDSTACK-2074: cloudstack UI - Affinity - Affinity Group page - add new tab 
"instances" that displays all vm instances under this affinity group.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3390f011
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3390f011
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3390f011

Branch: refs/heads/master
Commit: 3390f0114b2a6f52802fb6cb1f0e8321e3da4a71
Parents: 935b08b
Author: Jessica Wang <[email protected]>
Authored: Thu Apr 18 12:24:44 2013 -0700
Committer: Jessica Wang <[email protected]>
Committed: Thu Apr 18 12:24:44 2013 -0700

----------------------------------------------------------------------
 ui/scripts/affinity.js |   62 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3390f011/ui/scripts/affinity.js
----------------------------------------------------------------------
diff --git a/ui/scripts/affinity.js b/ui/scripts/affinity.js
index 0bb08cc..daa8fb7 100644
--- a/ui/scripts/affinity.js
+++ b/ui/scripts/affinity.js
@@ -166,7 +166,67 @@
                                                                }
                                                        });                   
             }
-          }
+          },
+                                                                               
+                                       /**
+           * VMs tab
+           */
+          vms: {
+            title: 'label.instances',
+            multiple: true,
+            fields: [
+              {
+                id: { label: 'ID' },
+                displayname: { label: 'label.display.name' },
+                state: { label: 'label.state' }                                
                        
+              }
+            ],
+            dataProvider: function(args) {             
+                                                 var vmIds = 
args.context.affinityGroups[0].virtualmachineIds;
+                                                       if(vmIds == null || 
vmIds.length == 0) {
+                                                         
args.response.success({data: null});          
+                                                         return;
+                                                       }
+                                               
+              $.ajax({
+                                                         url: 
createURL('listVirtualMachines'),
+                                                               success: 
function(json) {                                                                
 
+                                                                       var 
firstPageVms = json.listvirtualmachinesresponse.virtualmachine;                 
                                                    
+                                                                       var 
items = [];                                                                 
+                                                                       
if(vmIds != null) {
+                                                                               
for(var i = 0; i < vmIds.length; i++) {                                         
                                  
+                                                                               
        var item = {id: vmIds[i]};      
+                      var matchFound = false;                                  
                                                
+                                                                               
        if(firstPageVms != null) {
+                                                                               
          for(var k = 0; k < firstPageVms.length; k++) {
+                                                                               
                  if(firstPageVms[k].id == vmIds[i]) {
+                                                                               
                          matchFound = true;
+                                                                               
                          item.displayname = firstPageVms[k].displayname;
+                                                                               
                                item.state = firstPageVms[k].state;
+                                                                               
                                break; //break for looup
+                                                                               
                        }
+                                                                               
                }
+                                                                               
        }               
+                      if(matchFound == false) { //the VM is not in API 
response of "listVirtualMachines&page=1&pagesize=500"
+                        $.ajax({
+                                                                               
                  url: createURL('listVirtualMachines'),
+                                                                               
                        async: false,
+                                                                               
                        data: {id: vmIds[i]},
+                                                                         
success: function(json) {     
+                                                                               
                          var vmObj = 
json.listvirtualmachinesresponse.virtualmachine[0];
+                                                                               
                                item.displayname = vmObj.displayname;
+                                                                               
                                item.state = vmObj.state;
+                                                                               
                        }
+                                                                               
                });
+                      }                                                        
                                
+                                                                               
        items.push(item);                                                       
          
+                                                                               
}
+                                                                       }       
                                                                                
        
+                                                                       
args.response.success({data: items});                                           
                                                                                
        
+                                                               }
+                                                       });                     
                  
+            }
+          }                                    
         }
       }
     }

Reply via email to