Vijava 学习笔记之VirtualMachine(Memory 容量更改)

虾米姐 阅读:635 2021-03-31 22:37:37 评论:0

vijava 代码:

package com.vmware.client; 
 
import com.vmware.util.Session; 
import com.vmware.vim25.VirtualMachineConfigSpec; 
import com.vmware.vim25.mo.*; 
 
/** 
 * Created by vixuan-008 on 2015/4/21. 
 */ 
public class VirtualMachineUpdateMemory { 
    public static void main(String[] args){ 
        try{ 
            try{ 
                String vmname="ESX01_SCALEIO"; 
                ServiceInstance serviceInstance= Session.getInstance("172.16.1.20", "root", "vmware"); 
                Folder rootFolder = serviceInstance.getRootFolder(); 
                VirtualMachine vm = (VirtualMachine) new InventoryNavigator( 
                        rootFolder).searchManagedEntity("VirtualMachine", vmname); 
                if(vm==null) 
                { 
                    System.out.println("No VM " + vmname + " found"); 
                    serviceInstance.getServerConnection().logout(); 
                    return; 
                } 
 
                //update VrituaMachine config file 
                VirtualMachineConfigSpec vmConfigSpec =new VirtualMachineConfigSpec(); 
                //update VirtualMachine Memory 
                long memorySize=8192; 
                vmConfigSpec.setMemoryMB(memorySize); 
                Task task = vm.reconfigVM_Task(vmConfigSpec); 
                if(task.waitForMe()==Task.SUCCESS) 
                { 
                    System.out.println("memory capacity update is Successful!"); 
                } 
                else 
                { 
                    System.out.println("memory capacity update is failed!"); 
                } 
                serviceInstance.getServerConnection().logout(); 
 
 
 
            }catch (Exception e){ 
                e.printStackTrace(); 
            } 
        }catch (Exception e){ 
            e.printStackTrace(); 
        } 
    } 
}
效果截图:



声明

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

关注我们

一个IT知识分享的公众号