Java Code Examples for com.vmware.vim25.mo.InventoryNavigator#searchManagedEntity()

The following examples show how to use com.vmware.vim25.mo.InventoryNavigator#searchManagedEntity() . 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: VIJavaUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static synchronized boolean doMigrateVM(String targetVMName,
    String newHostName) throws Exception {
  ServiceInstance si = new ServiceInstance(new URL(url), username, password,
      true);
  try {
    Folder rootFolder = si.getRootFolder();
    InventoryNavigator in = new InventoryNavigator(rootFolder);
    HostSystem newHost = (HostSystem)in.searchManagedEntity("HostSystem",
        newHostName);
    if (newHost == null) {
      throw new TestException("Could not find host " + newHostName + " as a target host for vMotion.");
    }

    return migrateVM(si, rootFolder, newHost, targetVMName, newHostName);

  } finally {
    si.getServerConnection().logout();
  }
}
 
Example 2
Source File: VIJavaUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static synchronized boolean doMigrateVM(String targetVMName,
    String newHostName) throws Exception {
  ServiceInstance si = new ServiceInstance(new URL(url), username, password,
      true);
  try {
    Folder rootFolder = si.getRootFolder();
    InventoryNavigator in = new InventoryNavigator(rootFolder);
    HostSystem newHost = (HostSystem)in.searchManagedEntity("HostSystem",
        newHostName);
    if (newHost == null) {
      throw new TestException("Could not find host " + newHostName + " as a target host for vMotion.");
    }

    return migrateVM(si, rootFolder, newHost, targetVMName, newHostName);

  } finally {
    si.getServerConnection().logout();
  }
}
 
Example 3
Source File: VmwareClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * TODO: メソッドコメントを記述
 *
 * @param <T>
 * @param rootEntity
 * @param type
 * @param name
 * @return
 */
public <T extends ManagedEntity> T search(ManagedEntity rootEntity, Class<T> type, String name) {
    InventoryNavigator navigator = new InventoryNavigator(rootEntity);
    ManagedEntity entity;
    try {
        entity = navigator.searchManagedEntity(type.getSimpleName(), name);
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }
    return type.cast(entity);
}
 
Example 4
Source File: VmwareClient.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * TODO: メソッドコメントを記述
 *
 * @param rootEntity
 * @param name
 * @return
 */
public ManagedEntity searchByName(ManagedEntity rootEntity, String name) {
    InventoryNavigator navigator = new InventoryNavigator(rootEntity);
    ManagedEntity entity;
    try {
        entity = navigator.searchManagedEntity("ManagedEntity", name);
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }
    return entity;
}
 
Example 5
Source File: VMotionTrigger.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void run() {
  int vmToUse = -1;
  int attempts = 0;
  try {
    synchronized (vmList) {
      while (attempts < vmList.size()) {
        lastVMIndex = (lastVMIndex == (vmList.size() - 1)) ? 0
            : ++lastVMIndex;
        vmToUse = lastVMIndex;
        if (!vmsInVMotion[vmToUse]) {
          vmsInVMotion[vmToUse] = Boolean.TRUE;
          lastHostIndex[vmToUse] = (lastHostIndex[vmToUse] == (vmList
              .get(vmToUse).size() - 1)) ? 1
              : ++lastHostIndex[vmToUse];
          break;
        }
        ++attempts;
      }
    }
    if (attempts == vmList.size()) {
      vmToUse = -1; // avoid logic in finally block
      return; // No vm available for vMotion.
    }

    String targetVMName = vmList.get(vmToUse).get(0);
    String newHostName = vmList.get(vmToUse).get(lastHostIndex[vmToUse]);

    Folder rootFolder = si.getRootFolder();
    InventoryNavigator in = new InventoryNavigator(rootFolder);
    HostSystem newHost = (HostSystem)in.searchManagedEntity("HostSystem",
        newHostName);
    if (newHost == null) {
      log(WARNING, "Could not resolve host " + newHostName + ", vMotion to this host cannot be performed.");
      return;
    }

    //dummyVMotion(si, rootFolder, newHost, targetVMName, newHostName);
    migrateVM(si, rootFolder, newHost, targetVMName, newHostName);

  } catch (Exception e) {
    log(WARNING, "Found ", e);
  } finally {
    if (vmToUse != -1) {
      synchronized (vmList) {
        vmsInVMotion[vmToUse] = Boolean.FALSE;
      }
    }
  }
}
 
Example 6
Source File: VMotionTrigger.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void run() {
  int vmToUse = -1;
  int attempts = 0;
  try {
    synchronized (vmList) {
      while (attempts < vmList.size()) {
        lastVMIndex = (lastVMIndex == (vmList.size() - 1)) ? 0
            : ++lastVMIndex;
        vmToUse = lastVMIndex;
        if (!vmsInVMotion[vmToUse]) {
          vmsInVMotion[vmToUse] = Boolean.TRUE;
          lastHostIndex[vmToUse] = (lastHostIndex[vmToUse] == (vmList
              .get(vmToUse).size() - 1)) ? 1
              : ++lastHostIndex[vmToUse];
          break;
        }
        ++attempts;
      }
    }
    if (attempts == vmList.size()) {
      vmToUse = -1; // avoid logic in finally block
      return; // No vm available for vMotion.
    }

    String targetVMName = vmList.get(vmToUse).get(0);
    String newHostName = vmList.get(vmToUse).get(lastHostIndex[vmToUse]);

    Folder rootFolder = si.getRootFolder();
    InventoryNavigator in = new InventoryNavigator(rootFolder);
    HostSystem newHost = (HostSystem)in.searchManagedEntity("HostSystem",
        newHostName);
    if (newHost == null) {
      log(WARNING, "Could not resolve host " + newHostName + ", vMotion to this host cannot be performed.");
      return;
    }

    //dummyVMotion(si, rootFolder, newHost, targetVMName, newHostName);
    migrateVM(si, rootFolder, newHost, targetVMName, newHostName);

  } catch (Exception e) {
    log(WARNING, "Found ", e);
  } finally {
    if (vmToUse != -1) {
      synchronized (vmList) {
        vmsInVMotion[vmToUse] = Boolean.FALSE;
      }
    }
  }
}