Vijava 学习笔记之VirtualMachine(CPU Process 更改)分析

哈哈 阅读:170 2021-03-31 22:37:30 评论: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 VirtualMachineCPUUpdate { 
    public static void main(String[] args){ 
        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 CPU processors 
            vmConfigSpec.numCPUs=4; 
            Task task = vm.reconfigVM_Task(vmConfigSpec); 
            if(task.waitForMe()==Task.SUCCESS) 
            { 
                System.out.println("cpu processors update is Successful!"); 
            } 
            else 
            { 
                System.out.println("cpu  processors  update is failed!"); 
            } 
            serviceInstance.getServerConnection().logout(); 
        }catch (Exception e){ 
            e.printStackTrace(); 
        } 
 
    } 
 
 
} 

效果截图:


声明

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

发表评论
搜索
排行榜
关注我们

一个IT知识分享的公众号