java Map嵌套多个Map

package com.vmware.client;

import com.vmware.util.Session;
import com.vmware.vim25.DatastoreSummary;
import com.vmware.vim25.mo.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 指定物理服务器所关联的DataStore(物理服务器存储)
 * Created by vixuan-008 on 2015/4/24.
 */
public class HostSystemDataStoreSystem {
    public static  void main(String[] args){
        try{
            //获取 HostSystem
            ServiceInstance serviceInstance= Session.getInstance("172.16.1.20", "root", "vmware");

            Folder rootFolder = serviceInstance.getRootFolder();
            ManagedEntity[] mes=new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem");
            if(mes==null && mes.length>0){
                serviceInstance.getServerConnection().logout();
                throw  new Exception();
            }else{
              <span style="color:#ff0000;">  Map<String,Map<String,String>> map=new HashMap<String, Map<String, String>>();//Map多重嵌套</span>
                for(int i=0;i<mes.length;i++){
                    HostSystem hostSystem=(HostSystem)mes[i];
                    System.out.println("name:" + hostSystem.getName());
                    if(hostSystem==null)
                    {
                        System.out.println("Host not found");
                        serviceInstance.getServerConnection().logout();
                        return;
                    }

                    HostDatastoreSystem hostDatastoreSystem = hostSystem.getHostDatastoreSystem();
                    Datastore[] datastores=hostDatastoreSystem.getDatastores();
                    if(datastores!=null){
                        if(datastores.length>0){
                            for (int j=0;j<datastores.length;j++){
                                Datastore datastore=datastores[j];
                                //datastore 相关描述信息
                                DatastoreSummary datastoreSummary=datastore.getSummary();
                                System.out.println("------start-------------");
                                System.out.println("capacity:"+datastoreSummary.capacity);
                                System.out.println("freeSpace:"+datastoreSummary.freeSpace);
                                System.out.println("name:"+datastoreSummary.name);
                                System.out.println("type:"+datastoreSummary.type);
                                System.out.println("uncommitted:"+datastoreSummary.uncommitted);
                                System.out.println("url:"+datastoreSummary.url);
                                System.out.println("------end-------------");
                              <span style="color:#ff0000;">  if(map.get(hostSystem.getName())!=null){     //核心代码
                                    Map tempMap=map.get(hostSystem.getName());
                                    tempMap.put(datastore.getName(),""+datastoreSummary.freeSpace);
                                }else{
                                    Map<String,String> datastoreMaps=new HashMap<String, String>();
                                    datastoreMaps.put(datastore.getName(),""+datastoreSummary.freeSpace);
                                    map.put(hostSystem.getName(),datastoreMaps);
                                }</span>


                            }

                        }
                    }
                }





            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值