Vijava 学习笔记之模板分析

无情 阅读:267 2021-03-31 22:36:46 评论:0

Vijava 代码:

package com.vmware.template; 
 
import com.vmware.util.Session; 
import com.vmware.vim25.CustomizationSpecInfo; 
import com.vmware.vim25.VirtualMachineConfigInfo; 
import com.vmware.vim25.mo.*; 
 
import java.rmi.RemoteException; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
 
/** 
 * Created by vixuan-008 on 2015/4/29. 
 */ 
public class TemplateOption { 
    public static void main(String[] args){ 
            try{ 
                List result = new ArrayList(); 
                //获取 HostSystem 
                ServiceInstance serviceInstance= Session.getInstance("172.16.1.20", "root", "vmware"); 
                InventoryNavigator inventoryNavigator = new InventoryNavigator(serviceInstance.getRootFolder()); 
                try { 
                    ManagedEntity[] template = (ManagedEntity[]) inventoryNavigator.searchManagedEntities("VirtualMachine"); 
 
 
                    for (int i = 0; i < template.length; i++) { 
                        com.vmware.vim25.mo.VirtualMachine vm = (com.vmware.vim25.mo.VirtualMachine) template[i]; 
                        if (vm.getConfig().isTemplate() == true) { 
                            Map map = new HashMap(); 
                            map.put("templateName", vm.getConfig().getName()); 
                            map.put("guestName", vm.getConfig().getGuestFullName()); 
                            result.add(map); 
                        } 
                    } 
 
                } catch (RemoteException e) { 
                    e.printStackTrace(); 
                } 
 
                if(result.size()>0){ 
                    System.out.println("size is:"+result.size()); 
                    for(int i=0;i<result.size();i++){ 
                        HashMap hashMap=(HashMap)result.get(i); 
                        System.out.println("templateName:"+(String)hashMap.get("templateName")); 
                        System.out.println("guestName:"+(String)hashMap.get("guestName")); 
                    } 
                } 
 
            }catch (Exception e){ 
                e.printStackTrace(); 
            } 
    } 
 
} 

效果展示:


声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
KIKK导航

KIKK导航

排行榜
关注我们

一个IT知识分享的公众号