• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ArrayUpdateOperation类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中com.vmware.vim25.ArrayUpdateOperation的典型用法代码示例。如果您正苦于以下问题:Java ArrayUpdateOperation类的具体用法?Java ArrayUpdateOperation怎么用?Java ArrayUpdateOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ArrayUpdateOperation类属于com.vmware.vim25包,在下文中一共展示了ArrayUpdateOperation类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: main

点赞 2

import com.vmware.vim25.ArrayUpdateOperation; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
	if(args.length!=3)
	{
		System.out.println("Usage: DrsAffRule url username password");
		System.exit(-1);
	}
	
	URL url = null;
	try 
	{ 
		url = new URL(args[0]); 
	} catch ( MalformedURLException urlE)
	{
		System.out.println("The URL provided is NOT valid. Please check it.");
		System.exit(-1);
	}
	String username = args[1];
	String password = args[2];
	String drs_obj_id = "domain-c5"; // The reference ID for cluster
	String vm1_oid = "vm-26"; // The reference ID for VM 1
	String vm2_oid = "vm-28"; // The reference ID for VM 2
	
	// initialize the system, set up web services
	ServiceInstance si = new ServiceInstance(url, username, password, true);
	
	//create the MOR object for DRS cluster
	ManagedObjectReference mref_drs = createMOR("ClusterComputeResource", drs_obj_id);
	ClusterComputeResource ccr = (ClusterComputeResource )
	  MorUtil.createExactManagedEntity(si.getServerConnection(), mref_drs);
	
	// create a new ClusterConfigSpec and populate it with related data for affinity rule
	ClusterConfigSpec ccs = new ClusterConfigSpec();

	ClusterAffinityRuleSpec cars = new ClusterAffinityRuleSpec();
	cars.setName("App and DB Appliance Bundle");
	cars.setEnabled(Boolean.TRUE);
	ManagedObjectReference vm1 = createMOR("VirtualMachine", vm1_oid);
	ManagedObjectReference vm2 = createMOR("VirtualMachine", vm2_oid);
	cars.setVm(new ManagedObjectReference[] {vm1, vm2});
	
	ClusterRuleSpec crs = new ClusterRuleSpec();
	//*NOTE*: the following setOperation has to be called since operation must be set.
	crs.setOperation(ArrayUpdateOperation.add);
	crs.setInfo(cars);

	ccs.setRulesSpec(new ClusterRuleSpec[] {crs});

	// make a call to set the configuration.
	ccr.reconfigureCluster_Task(ccs, true);

	si.getServerConnection().logout();
	
	System.out.println("Done with setting affinity rule for DRS cluster.");
}
 

开发者ID:Juniper,
项目名称:vijava
代码行数:56,
代码来源:DrsAffRule.java

示例2: setRestartPriorityForVM

点赞 2

import com.vmware.vim25.ArrayUpdateOperation; //导入依赖的package包/类
@Override
public void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception {
    if (vmMo == null || StringUtils.isBlank(priority)) {
        return;
    }

    if (!isHAEnabled()) {
        s_logger.debug("Couldn't set restart priority for VM: " + vmMo.getName() + ", HA disabled in the cluster");
        return;
    }

    ManagedObjectReference vmMor = vmMo.getMor();
    if (vmMor == null || !vmMor.getType().equals("VirtualMachine")) {
        s_logger.debug("Failed to set restart priority for VM: " + vmMo.getName() + ", invalid VM object reference");
        return;
    }

    String currentVmRestartPriority = getRestartPriorityForVM(vmMo);
    if (StringUtils.isNotBlank(currentVmRestartPriority) && currentVmRestartPriority.equalsIgnoreCase(priority)) {
        return;
    }

    ClusterDasVmSettings clusterDasVmSettings = new ClusterDasVmSettings();
    clusterDasVmSettings.setRestartPriority(priority);

    ClusterDasVmConfigInfo clusterDasVmConfigInfo = new ClusterDasVmConfigInfo();
    clusterDasVmConfigInfo.setKey(vmMor);
    clusterDasVmConfigInfo.setDasSettings(clusterDasVmSettings);

    ClusterDasVmConfigSpec clusterDasVmConfigSpec = new ClusterDasVmConfigSpec();
    clusterDasVmConfigSpec.setOperation((StringUtils.isNotBlank(currentVmRestartPriority)) ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD);
    clusterDasVmConfigSpec.setInfo(clusterDasVmConfigInfo);

    ClusterConfigSpecEx clusterConfigSpecEx = new ClusterConfigSpecEx();
    ClusterDasConfigInfo clusterDasConfigInfo = new ClusterDasConfigInfo();
    clusterConfigSpecEx.setDasConfig(clusterDasConfigInfo);
    clusterConfigSpecEx.getDasVmConfigSpec().add(clusterDasVmConfigSpec);

    ManagedObjectReference morTask = _context.getService().reconfigureComputeResourceTask(_mor, clusterConfigSpecEx, true);

    boolean result = _context.getVimClient().waitForTask(morTask);

    if (result) {
        _context.waitForTaskProgressDone(morTask);

        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - setRestartPriority done(successfully)");
    } else {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - setRestartPriority done(failed)");
        s_logger.error("Set restart priority failed for VM: " + vmMo.getName() + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
}
 

开发者ID:apache,
项目名称:cloudstack,
代码行数:54,
代码来源:ClusterMO.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)