Vijava 學習筆記之 VirtualMachine操作(關機、待機和重新載入)
阿新 • • 發佈:2019-02-08
package com.vmware.client; import com.vmware.util.ClientSesion; import com.vmware.vim25.mo.*; import java.net.URL; /** * Created by vixuan-008 on 2015/4/16. */ public class VirtualMachineTaskStop { public static void main(String[] args){ try { String ip="172.16.10.15"; ClientSesion session = new ClientSesion("地址", "使用者名稱", "密碼"); URL url = new URL("https", session.getHost(), "/sdk"); ServiceInstance si = new ServiceInstance(url, session.getUsername(), session.getPassword(), true); Folder rootFolder = si.getRootFolder(); ManagedEntity mes = new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine","AD"); if (mes != null) { VirtualMachine virtualMachine = (VirtualMachine) mes; System.out.println("VirtualMachine name:" +virtualMachine.getName()); //虛擬機器重新載入 virtualMachine.reload(); //虛擬機器關機 //virtualMachine.shutdownGuest(); //虛擬機器待機 //virtualMachine.standbyGuest(); }else{ si.getServerConnection().logout(); } }catch (Exception e){ e.printStackTrace(); } } }