com.vmware.vim25.mo.ComputeResource Java Examples

The following examples show how to use com.vmware.vim25.mo.ComputeResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockVmwareDescribeService.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
@Override
public List<ComputeResource> getComputeResources(Long platformNo) {
    List<ComputeResource> computeResources = new ArrayList<ComputeResource>();

    computeResources.add(new ComputeResource(null, null) {
        @Override
        public String getName() {
            return "Cluster1";
        }
    });

    computeResources.add(new ComputeResource(null, null) {
        @Override
        public String getName() {
            return "Cluster2";
        }
    });

    return computeResources;
}
 
Example #2
Source File: WinServerEdit.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
private void loadData() {
    VmwareDescribeService vmwareDescribeService = BeanContext.getBean(VmwareDescribeService.class);
    Long platformNo = platform.getPlatform().getPlatformNo();

    // キーペア情報を取得
    List<VmwareKeyPair> vmwareKeyPairs = vmwareDescribeService.getKeyPairs(ViewContext.getUserNo(), platformNo);
    this.vmwareKeyPairs = vmwareKeyPairs;

    // クラスタ情報を取得
    List<ComputeResource> computeResources = vmwareDescribeService.getComputeResources(platformNo);
    List<String> clusters = new ArrayList<String>();
    for (ComputeResource computeResource : computeResources) {
        clusters.add(computeResource.getName());
    }
    this.clusters = clusters;
}
 
Example #3
Source File: VmwareNetworkProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * TODO: メソッドコメントを記述
 *
 * @param vmwareProcessClient
 * @param networkNo
 * @param instanceNo
 */
public void addNetwork(VmwareProcessClient vmwareProcessClient, Long networkNo, Long instanceNo) {
    VmwareNetwork vmwareNetwork = vmwareNetworkDao.read(networkNo);

    // HostSystemを取得
    VmwareClient vmwareClient = vmwareProcessClient.getVmwareClient();
    ManagedEntity[] hostSystems;
    if (instanceNo == null) {
        hostSystems = vmwareClient.searchByType(HostSystem.class);
    } else {
        VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo);
        ComputeResource computeResource = vmwareClient.search(ComputeResource.class,
                vmwareInstance.getComputeResource());
        hostSystems = vmwareClient.searchByType(computeResource, HostSystem.class);
    }

    // ネットワークを追加
    for (ManagedEntity entity : hostSystems) {
        HostSystem hostSystem = HostSystem.class.cast(entity);
        vmwareProcessClient.addNetwork(hostSystem.getName(), vmwareNetwork.getNetworkName(),
                vmwareNetwork.getVlanId(), vmwareNetwork.getVswitchName());
    }
}
 
Example #4
Source File: VmwareNetworkProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * TODO: メソッドコメントを記述
 *
 * @param vmwareProcessClient
 * @param networkNo
 * @param instanceNo
 */
public void removeNetwork(VmwareProcessClient vmwareProcessClient, Long networkNo, Long instanceNo) {
    VmwareNetwork vmwareNetwork = vmwareNetworkDao.read(networkNo);

    // HostSystemを取得
    VmwareClient vmwareClient = vmwareProcessClient.getVmwareClient();
    ManagedEntity[] hostSystems;
    if (instanceNo == null) {
        hostSystems = vmwareClient.searchByType(HostSystem.class);
    } else {
        VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo);
        ComputeResource computeResource = vmwareClient.search(ComputeResource.class,
                vmwareInstance.getComputeResource());
        hostSystems = vmwareClient.searchByType(computeResource, HostSystem.class);
    }

    // ネットワークを除去
    for (ManagedEntity entity : hostSystems) {
        HostSystem hostSystem = HostSystem.class.cast(entity);
        vmwareProcessClient.removeNetwork(hostSystem.getName(), vmwareNetwork.getNetworkName());
    }
}
 
Example #5
Source File: VmwareNetworkProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
public DistributedVirtualPortgroupInfo getDVPortgroupInfo(VirtualMachine machine, String networkName) {
    HostSystem host = new HostSystem(machine.getServerConnection(), machine.getRuntime().getHost());
    ComputeResource computeResource = (ComputeResource) host.getParent();
    EnvironmentBrowser envBrowser = computeResource.getEnvironmentBrowser();

    DistributedVirtualPortgroupInfo dvPortgroupInfo = null;
    try {
        ConfigTarget configTarget = envBrowser.queryConfigTarget(host);

        // 分散ポートグループの場合
        if (configTarget.getDistributedVirtualPortgroup() != null) {
            // 分散ポートグループ情報を取得
            dvPortgroupInfo = findDVPortgroupInfo(configTarget.getDistributedVirtualPortgroup(), networkName);
        }
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }

    return dvPortgroupInfo;
}
 
Example #6
Source File: DescribePlatform.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
private PlatformVmwareResponse getVmwareDetail(Long userNo, Long platformNo) {
    PlatformVmwareResponse response = new PlatformVmwareResponse();

    // キー名
    List<VmwareKeyPair> keyPairs = vmwareDescribeService.getKeyPairs(userNo, platformNo);
    for (VmwareKeyPair keyPair : keyPairs) {
        response.getKeyNames().add(keyPair.getKeyName());
    }

    // ComputeResource
    List<ComputeResource> computeResources = vmwareDescribeService.getComputeResources(platformNo);
    for (ComputeResource computeResource : computeResources) {
        response.getComputeResources().add(computeResource.getName());
    }

    return response;
}
 
Example #7
Source File: VmwareDescribeServiceImpl.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<ComputeResource> getComputeResources(Long platformNo) {
    PlatformVmware platformVmware = platformVmwareDao.read(platformNo);

    VmwareClientFactory factory = new VmwareClientFactory();
    factory.setUrl(platformVmware.getUrl());
    factory.setUsername(platformVmware.getUsername());
    factory.setPassword(platformVmware.getPassword());
    factory.setDatacenterName(platformVmware.getDatacenter());
    factory.setIgnoreCert(true);
    VmwareClient vmwareClient = factory.createVmwareClient();

    List<ComputeResource> computeResources = new ArrayList<ComputeResource>();

    ManagedEntity[] entities = vmwareClient.searchByType(ComputeResource.class);
    for (ManagedEntity entity : entities) {
        ComputeResource computeResource = ComputeResource.class.cast(entity);
        if (StringUtils.isNotEmpty(platformVmware.getComputeResource())
                && !StringUtils.equals(computeResource.getName(), platformVmware.getComputeResource())) {
            continue;
        }
        computeResources.add(computeResource);
    }

    // ソート
    Collections.sort(computeResources, Comparators.COMPARATOR_COMPUTE_RESOURCE);

    return computeResources;
}
 
Example #8
Source File: VmwareProcessClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
protected VirtualMachineCloneSpec createCloneSpec(String computeResourceName, String resourcePoolName,
        String datastoreName) {
    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();

    // ComputeResource
    ComputeResource computeResource = vmwareClient.search(ComputeResource.class, computeResourceName);
    if (computeResource == null) {
        // ComputeResourceが見つからない場合
        throw new AutoException("EPROCESS-000503", computeResourceName);
    }

    // ResourcePool
    if (StringUtils.isEmpty(resourcePoolName)) {
        resourcePoolName = "Resources";
    }
    ResourcePool resourcePool = vmwareClient.search(computeResource, ResourcePool.class, resourcePoolName);
    if (resourcePool == null) {
        // ResourcePoolが見つからない場合
        throw new AutoException("EPROCESS-000504", resourcePoolName);
    }
    relocateSpec.setPool(resourcePool.getMOR());

    // Datastore
    if (StringUtils.isNotEmpty(datastoreName)) {
        // データストアが指定されている場合
        Datastore datastore = vmwareClient.search(Datastore.class, datastoreName);
        if (datastore == null) {
            // データストアが見つからない場合
            throw new AutoException("EPROCESS-000505", datastoreName);
        }
        relocateSpec.setDatastore(datastore.getMOR());
    }

    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setLocation(relocateSpec);
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);

    return cloneSpec;
}
 
Example #9
Source File: EditInstanceVmware.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkComputeResource(Long platformNo, String computeResourceName) {
    List<ComputeResource> computeResources = vmwareDescribeService.getComputeResources(platformNo);
    for (ComputeResource computeResource : computeResources) {
        if (StringUtils.equals(computeResourceName, computeResource.getName())) {
            return true;
        }
    }

    return false;
}
 
Example #10
Source File: VMotionTrigger.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private static boolean migrateVM(ServiceInstance si, Folder rootFolder,
    HostSystem newHost, String targetVMName, String newHostName)
    throws Exception {

  log("Selected host [vm] for vMotion: " + newHostName + " [" + targetVMName
      + "]");
  VirtualMachine vm = (VirtualMachine)new InventoryNavigator(rootFolder)
      .searchManagedEntity("VirtualMachine", targetVMName);
  if (vm == null) {
    log(WARNING, "Could not resolve VM " + targetVMName + ", vMotion of this VM cannot be performed.");
    return false;
  }

  ComputeResource cr = (ComputeResource)newHost.getParent();

  String[] checks = new String[] { "cpu", "software" };
  HostVMotionCompatibility[] vmcs = si.queryVMotionCompatibility(vm,
      new HostSystem[] { newHost }, checks);

  String[] comps = vmcs[0].getCompatibility();
  if (checks.length != comps.length) {
    log(WARNING, "CPU/software NOT compatible, vMotion failed.");
    return false;
  }

  long start = System.currentTimeMillis();
  Task task = vm.migrateVM_Task(cr.getResourcePool(), newHost,
      VirtualMachineMovePriority.highPriority,
      VirtualMachinePowerState.poweredOn);
  if (task.waitForMe() == Task.SUCCESS) {
    long end = System.currentTimeMillis();
    log("vMotion of " + targetVMName + " to " + newHostName
        + " completed in " + (end - start) + "ms. Task result: "
        + task.getTaskInfo().getResult());
    return true;
  } else {
    TaskInfo info = task.getTaskInfo();
    log(WARNING, "vMotion of " + targetVMName + " to " + newHostName
        + " failed. Error details: " + info.getError().getFault());
    return false;
  }
}
 
Example #11
Source File: VMotionTrigger.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private static boolean migrateVM(ServiceInstance si, Folder rootFolder,
    HostSystem newHost, String targetVMName, String newHostName)
    throws Exception {

  log("Selected host [vm] for vMotion: " + newHostName + " [" + targetVMName
      + "]");
  VirtualMachine vm = (VirtualMachine)new InventoryNavigator(rootFolder)
      .searchManagedEntity("VirtualMachine", targetVMName);
  if (vm == null) {
    log(WARNING, "Could not resolve VM " + targetVMName + ", vMotion of this VM cannot be performed.");
    return false;
  }

  ComputeResource cr = (ComputeResource)newHost.getParent();

  String[] checks = new String[] { "cpu", "software" };
  HostVMotionCompatibility[] vmcs = si.queryVMotionCompatibility(vm,
      new HostSystem[] { newHost }, checks);

  String[] comps = vmcs[0].getCompatibility();
  if (checks.length != comps.length) {
    log(WARNING, "CPU/software NOT compatible, vMotion failed.");
    return false;
  }

  long start = System.currentTimeMillis();
  Task task = vm.migrateVM_Task(cr.getResourcePool(), newHost,
      VirtualMachineMovePriority.highPriority,
      VirtualMachinePowerState.poweredOn);
  if (task.waitForMe() == Task.SUCCESS) {
    long end = System.currentTimeMillis();
    log("vMotion of " + targetVMName + " to " + newHostName
        + " completed in " + (end - start) + "ms. Task result: "
        + task.getTaskInfo().getResult());
    return true;
  } else {
    TaskInfo info = task.getTaskInfo();
    log(WARNING, "vMotion of " + targetVMName + " to " + newHostName
        + " failed. Error details: " + info.getError().getFault());
    return false;
  }
}
 
Example #12
Source File: InstanceServiceImpl.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Long createVmwareInstance(Long farmNo, String instanceName, Long platformNo, String comment, Long imageNo,
        String instanceType) {
    // インスタンスの作成
    Long instanceNo = createInstance(farmNo, instanceName, platformNo, comment, imageNo);

    // プラットフォームのチェック
    Platform platform = platformDao.read(platformNo);
    if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType()) == false) {
        throw new AutoApplicationException("ESERVICE-000408", instanceName);
    }
    PlatformVmware platformVmware = platformVmwareDao.read(platformNo);

    // VMwareインスタンスの作成
    VmwareInstance vmwareInstance = new VmwareInstance();
    vmwareInstance.setInstanceNo(instanceNo);

    // 仮想マシン名
    Farm farm = farmDao.read(farmNo);
    String machineName = farm.getFarmName() + "_" + instanceName;
    vmwareInstance.setMachineName(machineName);

    // InstanceType
    ImageVmware imageVmware = imageVmwareDao.read(imageNo);
    if (StringUtils.isEmpty(instanceType)) {
        if (StringUtils.isNotEmpty(imageVmware.getDefaultInstanceType())) {
            instanceType = imageVmware.getDefaultInstanceType();
        } else {
            String[] instanceTypes = imageVmware.getInstanceTypes().split(",");
            instanceType = instanceTypes[0];
        }
    }
    vmwareInstance.setInstanceType(instanceType);

    // クラスタ、ホスト
    String computeResource = platformVmware.getComputeResource();
    if (StringUtils.isEmpty(computeResource)) {
        List<ComputeResource> computeResources = vmwareDescribeService.getComputeResources(platformNo);
        computeResource = computeResources.get(0).getName();
    }
    vmwareInstance.setComputeResource(computeResource);

    // リソースプール
    // TODO: リソースプールの選択をどうする?
    String resourcePool = null;
    vmwareInstance.setResourcePool(resourcePool);

    // データストア(この時点ではデータストアを決めない)
    String datastore = null;
    vmwareInstance.setDatastore(datastore);

    // キーペア
    List<VmwareKeyPair> vmwareKeyPairs = vmwareKeyPairDao.readByUserNoAndPlatformNo(farm.getUserNo(), platformNo);
    Long keyPairNo = vmwareKeyPairs.get(0).getKeyNo();
    vmwareInstance.setKeyPairNo(keyPairNo);

    // RootSize
    if (imageVmware.getRootSize() != null) {
        vmwareInstance.setRootSize(imageVmware.getRootSize());
    }

    vmwareInstanceDao.create(vmwareInstance);

    // イベントログ出力
    eventLogger.log(EventLogLevel.INFO, farmNo, farm.getFarmName(), null, null, instanceNo, instanceName,
            "InstanceCreate", instanceType, platformNo, new Object[] { platform.getPlatformName() });

    // フック処理の実行
    processHook.execute("post-create-instance", farm.getUserNo(), farm.getFarmNo(), instanceNo);

    return instanceNo;
}
 
Example #13
Source File: Comparators.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int compare(ComputeResource o1, ComputeResource o2) {
    return o1.getName().compareTo(o2.getName());
}
 
Example #14
Source File: VmwareIaasHandler.java    From roboconf-platform with Apache License 2.0 4 votes vote down vote up
@Override
public String createMachine( TargetHandlerParameters parameters ) throws TargetException {

	this.logger.fine( "Creating a new VM @ VMware." );

	// For IaaS, we only expect root instance names to be passed
	if( InstanceHelpers.countInstances( parameters.getScopedInstancePath()) > 1 )
		throw new TargetException( "Only root instances can be passed in arguments." );

	String rootInstanceName = InstanceHelpers.findRootInstancePath( parameters.getScopedInstancePath());

	// Deal with the creation
	try {
		System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser");
		Map<String,String> targetProperties = parameters.getTargetProperties();
		final String machineImageId = targetProperties.get( TEMPLATE );
		final ServiceInstance vmwareServiceInstance = getServiceInstance( targetProperties );

		final ComputeResource vmwareComputeResource = (ComputeResource)(
				new InventoryNavigator( vmwareServiceInstance.getRootFolder())
				.searchManagedEntity("ComputeResource", targetProperties.get( CLUSTER )));

		// Generate the user data first, so that nothing has been done on the IaaS if it fails
		String userData = UserDataHelpers.writeUserDataAsString(
				parameters.getMessagingProperties(),
				parameters.getDomain(),
				parameters.getApplicationName(),
				rootInstanceName );

		VirtualMachine vm = getVirtualMachine( vmwareServiceInstance, machineImageId );
		String vmwareDataCenter = targetProperties.get( DATA_CENTER );
		Folder vmFolder =
				((Datacenter)(new InventoryNavigator( vmwareServiceInstance.getRootFolder())
				.searchManagedEntity("Datacenter", vmwareDataCenter)))
				.getVmFolder();

		this.logger.fine("machineImageId=" + machineImageId);
		if (vm == null || vmFolder == null)
			throw new TargetException("VirtualMachine (= " + vm + " ) or Datacenter path (= " + vmFolder + " ) is NOT correct. Please, double check.");

		VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
		cloneSpec.setLocation(new VirtualMachineRelocateSpec());
		cloneSpec.setPowerOn(false);
		cloneSpec.setTemplate(true);

		VirtualMachineConfigSpec vmSpec = new VirtualMachineConfigSpec();
		vmSpec.setAnnotation( userData );
		cloneSpec.setConfig(vmSpec);

		Task task = vm.cloneVM_Task( vmFolder, rootInstanceName, cloneSpec );
		this.logger.fine("Cloning the template: "+ machineImageId +" ...");
		String status = task.waitForTask();
		if (!status.equals(Task.SUCCESS))
			throw new TargetException("Failure: Virtual Machine cannot be cloned." );

		VirtualMachine vm2 = getVirtualMachine( vmwareServiceInstance, rootInstanceName );
		this.logger.fine("Transforming the clone template to Virtual machine ...");
		vm2.markAsVirtualMachine( vmwareComputeResource.getResourcePool(), null);

		DynamicProperty dprop = new DynamicProperty();
		dprop.setName("guestinfo.userdata");
		dprop.setVal(userData);
		vm2.getGuest().setDynamicProperty(new DynamicProperty[]{dprop});

		task = vm2.powerOnVM_Task(null);
		this.logger.fine("Starting the virtual machine: "+ rootInstanceName +" ...");
		status = task.waitForTask();
		if( ! status.equals( Task.SUCCESS ))
			throw new TargetException("Failure: Virtual Machine cannot be started." );

		return vm2.getName();

	} catch( Exception e ) {
		throw new TargetException( e );
	}
}
 
Example #15
Source File: VmwareDescribeService.java    From primecloud-controller with GNU General Public License v2.0 votes vote down vote up
public List<ComputeResource> getComputeResources(Long platformNo);