Java 类com.vmware.vim25.mo.HostSystem 实例源码

项目:gemfirexd-oss    文件:VIJavaUtil.java   
private static boolean migrateVM(String targetVMName, String newHostName,
    boolean tryAnotherVM, boolean tryAnotherHost) throws Exception {
  ServiceInstance si = new ServiceInstance(new URL(url), username, password,
      true);

  try {
    Folder rootFolder = si.getRootFolder();
    HostSystem newHost = (HostSystem)new InventoryNavigator(rootFolder)
        .searchManagedEntity("HostSystem", newHostName);

    return migrateVM(si, rootFolder, newHost, targetVMName, newHostName,
        tryAnotherVM, tryAnotherHost);
  } finally {
    si.getServerConnection().logout();
  }
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
private static String findVMNotOnHost(HostSystem host) throws RemoteException {
  VirtualMachine[] hostVMs = host.getVms();
  boolean foundMatch = false;
  String targetVM = null;
  for (String vmName : vmNames) {
    for (VirtualMachine vm : hostVMs) {
      if (vmName.equals(vm.getName())) {
        foundMatch = true;
        break;
      }
    }
    if (!foundMatch) {
      targetVM = vmName;
      break;
    }
    foundMatch = false;
  }
  return targetVM;
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
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();
  }
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
public static void HydraTask_migrateNetDownVM() throws Exception {
  SharedMap sMap = VMotionBB.getBB().getSharedMap();

  Boolean bool = (Boolean)sMap.get("connectionDropped");
  if (bool == null || !bool) {
    return;
  }

  initializeParams();
  if (!validateParams()) {
    return;
  }

  ServiceInstance si = new ServiceInstance(new URL(url), username, password,
      true);

  try {
    Folder rootFolder = si.getRootFolder();
    HostSystem newHost = (HostSystem)new InventoryNavigator(rootFolder)
        .searchManagedEntity("HostSystem", hostNames[0]);
    migrateVM(si, rootFolder, newHost, vmNames[0], hostNames[0], false, false);
  } finally {
    si.getServerConnection().logout();
  }
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
private static boolean migrateVM(String targetVMName, String newHostName,
    boolean tryAnotherVM, boolean tryAnotherHost) throws Exception {
  ServiceInstance si = new ServiceInstance(new URL(url), username, password,
      true);

  try {
    Folder rootFolder = si.getRootFolder();
    HostSystem newHost = (HostSystem)new InventoryNavigator(rootFolder)
        .searchManagedEntity("HostSystem", newHostName);

    return migrateVM(si, rootFolder, newHost, targetVMName, newHostName,
        tryAnotherVM, tryAnotherHost);
  } finally {
    si.getServerConnection().logout();
  }
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
private static String findVMNotOnHost(HostSystem host) throws RemoteException {
  VirtualMachine[] hostVMs = host.getVms();
  boolean foundMatch = false;
  String targetVM = null;
  for (String vmName : vmNames) {
    for (VirtualMachine vm : hostVMs) {
      if (vmName.equals(vm.getName())) {
        foundMatch = true;
        break;
      }
    }
    if (!foundMatch) {
      targetVM = vmName;
      break;
    }
    foundMatch = false;
  }
  return targetVM;
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
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();
  }
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
public static void HydraTask_migrateNetDownVM() throws Exception {
  SharedMap sMap = VMotionBB.getBB().getSharedMap();

  Boolean bool = (Boolean)sMap.get("connectionDropped");
  if (bool == null || !bool) {
    return;
  }

  initializeParams();
  if (!validateParams()) {
    return;
  }

  ServiceInstance si = new ServiceInstance(new URL(url), username, password,
      true);

  try {
    Folder rootFolder = si.getRootFolder();
    HostSystem newHost = (HostSystem)new InventoryNavigator(rootFolder)
        .searchManagedEntity("HostSystem", hostNames[0]);
    migrateVM(si, rootFolder, newHost, vmNames[0], hostNames[0], false, false);
  } finally {
    si.getServerConnection().logout();
  }
}
项目:primecloud-controller    文件:VmwareNetworkProcess.java   
/**
 * 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());
    }
}
项目:primecloud-controller    文件:VmwareNetworkProcess.java   
/**
 * 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());
    }
}
项目:primecloud-controller    文件:VmwareNetworkProcess.java   
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;
}
项目:vijava    文件:VmNicOp.java   
static boolean doesNetworkNameExist(VirtualMachine vm, 
    String netName) throws Exception 
{
  VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime();
  EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser();
  ManagedObjectReference hmor = vmRuntimeInfo.getHost();

  HostSystem host = new HostSystem(
      vm.getServerConnection(), hmor);
  ConfigTarget cfg = envBrowser.queryConfigTarget(host);
  VirtualMachineNetworkInfo[] nets = cfg.getNetwork();
  for (int i = 0; nets!=null && i < nets.length; i++) 
  {
    NetworkSummary netSummary = nets[i].getNetwork();
    if (netSummary.isAccessible() && 
        netSummary.getName().equalsIgnoreCase(netName)) 
    {
      return true;
    }
  }
  return false;
}
项目:vijava    文件:VmCdOp.java   
static DatastoreSummary findDatastoreSummary(VirtualMachine vm, String dsName) throws Exception 
{
  DatastoreSummary dsSum = null;
  VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime();
  EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); 
  ManagedObjectReference hmor = vmRuntimeInfo.getHost();

  if(hmor == null)
  {
    System.out.println("No Datastore found");
    return null;
  }

  ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor));
  VirtualMachineDatastoreInfo[] dis = configTarget.getDatastore();
  for (int i=0; dis!=null && i<dis.length; i++) 
  {
    dsSum = dis[i].getDatastore();
    if (dsSum.isAccessible() && dsName.equals(dsSum.getName())) 
    {
      break;
    }
  }
  return dsSum;
}
项目:vijava    文件:VmCdOp.java   
static VirtualDevice[] getDefaultDevices(VirtualMachine vm) 
throws Exception 
{
  VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime();
  EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); 
  ManagedObjectReference hmor = vmRuntimeInfo.getHost();
  VirtualMachineConfigOption cfgOpt = envBrowser.queryConfigOption(null, new HostSystem(vm.getServerConnection(), hmor));
  VirtualDevice[] defaultDevs = null;
  if (cfgOpt != null) 
  {
    defaultDevs = cfgOpt.getDefaultDevice();
    if (defaultDevs == null) 
    {
      throw new Exception("No Datastore found in ComputeResource");
    }
  }
  else
  {
    throw new Exception("No VirtualHardwareInfo found in ComputeResource");
  }
  return defaultDevs;
}
项目:opennmszh    文件:VmwareViJavaAccess.java   
/**
 * Searches for the primary ip address of a host system.
 * <p>The idea is to resolve the HostSystem's name and use the resulting IP if the IP is listed on the available addresses list,
 * otherwise, use the first ip listed on the available list.</p>
 *
 * @param hostSystem the host system to query
 * @return the primary ip address
 * @throws RemoteException
 */
// TODO We should use the IP of the "Management Network" (i.e. the port that has enabled "Management Traffic" on the available vSwitches).
//      Resolving the name of the HostSystem as the FQDN is the most closest thing for that.
public String getPrimaryHostSystemIpAddress(HostSystem hostSystem) throws RemoteException {
    TreeSet<String> addresses = getHostSystemIpAddresses(hostSystem);
    String ipAddress = null;
    try {
        ipAddress = InetAddress.getByName(hostSystem.getName()).getHostAddress();
    } catch (Exception e) {
        logger.debug("Can't resolve the IP address from {}.", hostSystem.getName());
    }
    if (ipAddress == null) {
        return addresses.first();
    }
    return addresses.contains(ipAddress) ? ipAddress : addresses.first();
}
项目:gemfirexd-oss    文件:VMotionTrigger.java   
private static void dummyVMotion(ServiceInstance si, Folder rootFolder,
    HostSystem newHost, String targetVMName, String newHostName) {
  log("Selected host [vm] for vMotion: " + newHostName + " [" + targetVMName
      + "]");
  try {Thread.sleep(120000);} catch(InterruptedException ir) {}
  log("vMotion of " + targetVMName + " to " + newHostName
      + " completed");
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
private static boolean validateVMNotOnHost(ServiceInstance si,
    Folder rootFolder, HostSystem newHost, String vmName, String hostName)
    throws Exception {
  VirtualMachine[] vms = newHost.getVms();
  for (VirtualMachine vmac : vms) {
    if (vmac.getName().equals(vmName)) {
      Log.getLogWriter().info(
          vmName + " is already running on target host " + hostName
              + ". Selecting another pair...");
      return false;
    }
  }
  return true;
}
项目:gemfirexd-oss    文件:VMotionTrigger.java   
private static void dummyVMotion(ServiceInstance si, Folder rootFolder,
    HostSystem newHost, String targetVMName, String newHostName) {
  log("Selected host [vm] for vMotion: " + newHostName + " [" + targetVMName
      + "]");
  try {Thread.sleep(120000);} catch(InterruptedException ir) {}
  log("vMotion of " + targetVMName + " to " + newHostName
      + " completed");
}
项目:gemfirexd-oss    文件:VIJavaUtil.java   
private static boolean validateVMNotOnHost(ServiceInstance si,
    Folder rootFolder, HostSystem newHost, String vmName, String hostName)
    throws Exception {
  VirtualMachine[] vms = newHost.getVms();
  for (VirtualMachine vmac : vms) {
    if (vmac.getName().equals(vmName)) {
      Log.getLogWriter().info(
          vmName + " is already running on target host " + hostName
              + ". Selecting another pair...");
      return false;
    }
  }
  return true;
}
项目:jcloud-vsphere    文件:VSphereHostSupplier.java   
private HostSystem getSystemHost() {
   Iterable<HostSystem> hosts = ImmutableSet.<HostSystem>of();
   try {
      VSphereServiceInstance instance = serviceInstance.get();
      ManagedEntity[] hostEntities = new InventoryNavigator(instance.getInstance().getRootFolder()).searchManagedEntities("HostSystem");
      hosts = Iterables.transform(Arrays.asList(hostEntities), new Function<ManagedEntity, HostSystem>() {
         public HostSystem apply(ManagedEntity input) {
            return (HostSystem) input;
         }
      });

      HostSystem curHostSystem = null;
      long maxMemory = Integer.MIN_VALUE;
      for (HostSystem hostSystem : hosts) {
         int currentMemory = hostSystem.getSummary().getQuickStats().getOverallMemoryUsage();
         long currentTotalMemory = hostSystem.getConfig().getSystemResources().getConfig().getMemoryAllocation().getLimit();
         if (currentTotalMemory - currentMemory > maxMemory) {
            curHostSystem = hostSystem;
            maxMemory = currentTotalMemory - currentMemory;
         }
      }

      return curHostSystem;
   } catch (Exception e) {
      logger.error("Problem in finding a valid host: " + e.toString(), e);
   }
   return null;
}
项目:jcloud-vsphere    文件:VSpherePredicate.java   
@Override
public boolean apply(ResourcePool input) {
   try {
      for (HostSystem hostSystem : input.getOwner().getHosts()) {
         if (hostSystem.getName().equals(hostname))
            return true;
      }
   } catch (RemoteException e) {
      return false;
   }
   return false;
}
项目:jcloud-vsphere    文件:GetRecommendedVSphereHost.java   
@Nullable
   @Override
   public VSphereHost apply(@Nullable String dataCenter) {
      try (VSphereServiceInstance instance = serviceInstance.get();) {

         ManagedEntity[] clusterEntities = new InventoryNavigator(instance.getInstance().getRootFolder()).searchManagedEntities("ClusterComputeResource");
         Iterable<ClusterComputeResource> clusterComputeResources = Iterables.transform(Arrays.asList(clusterEntities), new Function<ManagedEntity, ClusterComputeResource>() {
            public ClusterComputeResource apply(ManagedEntity input) {
               return (ClusterComputeResource) input;
            }
         });

         HostSystem curHostSystem = null;
         for (ClusterComputeResource cluster : clusterComputeResources) {
            if (cluster.getName().equals(dataCenter) || dataCenter.equals("default")) {
               HostSystem[] hostSystems = cluster.getHosts();
               long maxMemory = Integer.MIN_VALUE;
               for (HostSystem hostSystem : hostSystems) {
                  int currentMemory = hostSystem.getSummary().getQuickStats().getOverallMemoryUsage();
                  long currentTotalMemory = hostSystem.getConfig().getSystemResources().getConfig().getMemoryAllocation().getLimit();
                  if (currentTotalMemory - currentMemory > maxMemory) {
                     curHostSystem = hostSystem;
                     maxMemory = currentTotalMemory - currentMemory;
                  }
               }
               break;
            }
         }
         return new VSphereHost(curHostSystem.getName(), serviceInstance.get());
//         return this.systemHostToVSphereHost.apply(curHostSystem);
      } catch (Exception e) {
         logger.error("Problem in finding a valid host: " + e.toString(), e);
      }
      return null;
   }
项目:jcloud-vsphere    文件:VSphereHost.java   
public VSphereHost(String hostName, VSphereServiceInstance serviceInstance) {
   this.serviceInstance = checkNotNull(serviceInstance, "serviceInstance");
   try {
      ManagedEntity hostEntity = new InventoryNavigator(serviceInstance.getInstance().getRootFolder()).searchManagedEntity("HostSystem", hostName);
      this.host = checkNotNull((HostSystem)hostEntity, "host");
   } catch (RemoteException e) {
      e.printStackTrace();
   }
}
项目:jcloud-vsphere    文件:HostSystemToVSphereHostTest.java   
@Test
public void applyTest() {
   HostSystemToVSphereHost hostSystemToVSphereHost = new HostSystemToVSphereHost();
   Assert.assertNull(hostSystemToVSphereHost.apply(null));
   HostSystem vm = PowerMock.createMock(HostSystem.class);
   ServiceInstance si = PowerMock.createMock(ServiceInstance.class);
   ServerConnection sc = PowerMock.createMock(ServerConnection.class);
   expect(vm.getServerConnection()).andReturn(sc).anyTimes();
   expect(sc.getServiceInstance()).andReturn(si).anyTimes();
   replay(vm, sc, ServerConnection.class);
   Assert.assertNotNull(hostSystemToVSphereHost.apply(vm));


}
项目:contrail-vcenter-plugin    文件:VCenterDB.java   
public boolean isVmEventOnMonitoredCluster(Event event, String hostName)
    throws RemoteException {
    String dcName;
    Datacenter dc;

    // If contrailClusterName is null, all clusters under datacenter 
    // are monitored by vcenter plugin.
    if (contrailClusterName == null)
        return true;

    if (event.getHost() != null) {
        hostName = event.getHost().getName();
        HostSystem host = getVmwareHost(hostName, contrailDC, contrailDataCenterName);

        if (host != null) {
            ClusterComputeResource cluster = (ClusterComputeResource) host.getParent();
            if (cluster != null) {
                String clstrName = cluster.getName();
                if (clstrName != null && clstrName.equals(contrailClusterName)) {
                    return true;
                }
            }
        }
    }

    return false;
}
项目:contrail-vcenter-plugin    文件:VCenterDB.java   
private void findHostsInFolder(Folder hostsFolder, List<HostSystem> hostsList)
        throws IOException, Exception {
    for (ManagedEntity e : hostsFolder.getChildEntity()) {
        if (e instanceof HostSystem) {
            hostsList.add((HostSystem)e);
        }

        // This is a cluster resource. Delve deeper to
        // find more hosts.
        if (e instanceof ComputeResource) {
            ComputeResource cr = (ComputeResource) e;
            if (e instanceof ClusterComputeResource) {
                ClusterComputeResource cluster = (ClusterComputeResource) e;
                if ((contrailClusterName != null) && 
                     (cluster.getName().equals(contrailClusterName) != true)) {
                   continue;
               }
            }
            for(HostSystem host : cr.getHosts()) {
                hostsList.add((HostSystem)host);
            }
        }

        if (e instanceof Folder) {
            findHostsInFolder((Folder)e, hostsList);
        }
    }
}
项目:contrail-vcenter-plugin    文件:VCenterDB.java   
SortedMap<String, VirtualMachineInfo> readVirtualMachines()
        throws IOException, Exception {

    s_logger.info("Start reading virtual machines from vcenter ...");

    SortedMap<String, VirtualMachineInfo> map =
            new ConcurrentSkipListMap<String, VirtualMachineInfo>();

    /* the method below can be called in a loop to read multiple
     * datacenters and read VMs per hosts
     * for (dc: datacenters)
     * for (host: dc)
        readVirtualMachines(map, host, dc, dcName);
     */

    Folder hostsFolder = contrailDC.getHostFolder();

    if (hostsFolder == null) {
        s_logger.error("Unable to read VMs, hostFolder is null");
        return map;
    }

    List<HostSystem> hostsList = new ArrayList<HostSystem>();

    findHostsInFolder(hostsFolder, hostsList);

    for (HostSystem host : hostsList) {
        readVirtualMachines(map, host, contrailDC, contrailDataCenterName);
    }

    s_logger.info("Done reading from vcenter, found " + map.size() + " Virtual Machines");
    return map;
}
项目:vijava    文件:VirtualMachineDeviceManager.java   
/** Create a new virtual network adapter on the VM
* Your MAC address should start with 00:50:56
  */
 public void createNetworkAdapter(VirtualNetworkAdapterType type, String networkName, String macAddress, boolean wakeOnLan, boolean startConnected) throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException
 {
   VirtualMachinePowerState powerState = vm.getRuntime().getPowerState();
   String vmVerStr = vm.getConfig().getVersion();
   int vmVer = Integer.parseInt(vmVerStr.substring(vmVerStr.length()-2));

   if((powerState == VirtualMachinePowerState.suspended) ||
     (powerState == VirtualMachinePowerState.suspended && vmVer < 7))
   {
     throw new InvalidPowerState();
   }

   HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost());
   ComputeResource cr = (ComputeResource) host.getParent();
   EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser();
   ConfigTarget configTarget = envBrowser.queryConfigTarget(host);
   VirtualMachineConfigOption vmCfgOpt = envBrowser.queryConfigOption(null, host);

   type = validateNicType(vmCfgOpt.getGuestOSDescriptor(), vm.getConfig().getGuestId(), type);

   VirtualDeviceConfigSpec nicSpec = createNicSpec(type, networkName, macAddress, wakeOnLan, startConnected, configTarget);

   VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
   vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec []{nicSpec});
   Task task = vm.reconfigVM_Task(vmConfigSpec);

   task.waitForTask(200, 100);
 }
项目:vijava    文件:VmStartupOption.java   
public static void main(String[] args) throws Exception
{
  CommandLineParser clp = new CommandLineParser(
      constructOptions(), args);
  String urlStr = clp.get_option("url");
  String username = clp.get_option("username");
  String password = clp.get_option("password");
  String hostname = clp.get_option("hostname");

  ServiceInstance si = new ServiceInstance(new URL(urlStr),
      username, password, true);
  HostSystem host = (HostSystem) new InventoryNavigator(si
      .getRootFolder()).searchManagedEntity("HostSystem",
      hostname);

  if (host == null) {
    System.out.println("Host cannot be found");
    return;
  }

  HostAutoStartManager hasm = host.getHostAutoStartManager();
  if (hasm == null) {
    System.out
        .println("HostAutoStartManager is not available.");
    return;
  }

  AutoStartDefaults asd = new AutoStartDefaults();
  asd.setStartDelay(new Integer(100));
  asd.setEnabled(Boolean.TRUE);
  asd.setStopDelay(new Integer(60));
  HostAutoStartManagerConfig spec = new HostAutoStartManagerConfig();
  spec.setDefaults(asd);
  hasm.reconfigureAutostart(spec);

  System.out
      .println("Done with reconfiguring the autostart options.");
}
项目:vijava    文件:CimTicket.java   
public static void main(String[] args) throws Exception
{
  if(args.length!=3)
  {
    System.out.println("Usage: java CimTicket <url> " +
            "<username> <password>");
    return;
  }
  String urlStr = args[0];
  String username = args[1];
  String password = args[2];

  ServiceInstance si = new ServiceInstance(new URL(urlStr),
      username, password, true);
  Folder rootFolder = si.getRootFolder();

  HostSystem host = (HostSystem) new InventoryNavigator(
      rootFolder).searchManagedEntities("HostSystem")[0];

  System.out.println(host.getName());
  HostServiceTicket ticket = host.acquireCimServicesTicket();
  System.out.println("\nHost Name:" + ticket.getHost());
  System.out.println("sessionId=" + ticket.getSessionId());
  System.out.println("sslThumpprint=" 
      + ticket.getSslThumbprint());
  System.out.println("serviceVersion=" 
      + ticket.getServiceVersion());
  System.out.println("service=" + ticket.getService());
  System.out.println("port=" + ticket.getPort());

  retrieveCimInfo(urlStr, ticket.getSessionId());

  si.getServerConnection().logout();
}
项目:opennmszh    文件:VmwareViJavaAccess.java   
/**
 * Returns a host system by a given managed object Id.
 *
 * @param managedObjectId the managed object Id
 * @return the host system object
 */
public HostSystem getHostSystemByManagedObjectId(String managedObjectId) {
    ManagedObjectReference managedObjectReference = new ManagedObjectReference();

    managedObjectReference.setType("HostSystem");
    managedObjectReference.setVal(managedObjectId);

    HostSystem hostSystem = (HostSystem) MorUtil.createExactManagedEntity(m_serviceInstance.getServerConnection(), managedObjectReference);

    return hostSystem;
}
项目:WBSAirback    文件:HypervisorManagerVMware.java   
public boolean existsNFSStore(String name, String host, String address, String path) throws Exception {
    if(address == null || path == null || address.isEmpty() || path.isEmpty()) {
        return false;
    }
    ServiceInstance si = new ServiceInstance(new URL(this._url), this._user, this._password, true);
    if(host == null || host.isEmpty()) {
        si.getServerConnection().logout();
        throw new Exception("invalid host name");
    }
    try {
        HostSystem _host = (HostSystem) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("HostSystem", host);
        if(_host == null) {
            si.getServerConnection().logout();
            throw new Exception("host system not found");
        }

        HostDatastoreSystem _hds = _host.getHostDatastoreSystem();
        for(Datastore _ds : _hds.getDatastores()) {
            DatastoreInfo _info = _ds.getInfo();
            if(_info instanceof NasDatastoreInfo) {
                NasDatastoreInfo _nasinfo = (NasDatastoreInfo) _info;
                if(name.equalsIgnoreCase(_nasinfo.getNas().getName())) {
                    return true;
                } else if(address.equalsIgnoreCase(_nasinfo.getNas().getRemoteHost()) &&
                        path.equalsIgnoreCase(_nasinfo.getNas().getRemotePath())) {
                    return true;
                }
            }
        }
    } catch(Exception _ex) {
    } finally {
        si.getServerConnection().logout();
    }
    return false;
}
项目:gemfirexd-oss    文件:VMotionTrigger.java   
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;
      }
    }
  }
}
项目:gemfirexd-oss    文件:VMotionTrigger.java   
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;
  }
}
项目:gemfirexd-oss    文件:VMotionTrigger.java   
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;
      }
    }
  }
}
项目:gemfirexd-oss    文件:VMotionTrigger.java   
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;
  }
}
项目:jcloud-vsphere    文件:VSphereComputeServiceContextModule.java   
@Override
   protected void configure() {
      super.configure();

      //bind(ComputeService.class).to(VSphereComputeService.class);
      bind(TemplateOptions.class).to(VSphereTemplateOptions.class);
      bind(LocationsSupplier.class).to(VSphereLocationSupplier.class);
      bind(FileManagerApi.class).to(VSphereFileManager.class);

      bind(new TypeLiteral<ComputeServiceAdapter<VirtualMachine, Hardware, Image, Location>>() {
      }).to(VSphereComputeServiceAdapter.class);

      bind(new TypeLiteral<Function<String, DistributedVirtualPortgroup>>() {
      }).to(Class.class.cast(VLanNameToDistributedVirtualPortgroup.class));

      bind(new TypeLiteral<Function<Location, Location>>() {
      }).to(Class.class.cast(IdentityFunction.class));

      bind(new TypeLiteral<Function<Image, Image>>() {
      }).to(Class.class.cast(IdentityFunction.class));

      bind(new TypeLiteral<Function<Hardware, Hardware>>() {
      }).to(Class.class.cast(IdentityFunction.class));

      bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() {
      }).to(VirtualMachineToNodeMetadata.class);

      bind(new TypeLiteral<Function<HostSystem, VSphereHost>>() {
      }).to(HostSystemToVSphereHost.class);

      bind(new TypeLiteral<Supplier<VSphereServiceInstance>>() {
      }).to((Class) CreateAndConnectVSphereClient.class);

//        bind(new TypeLiteral<Supplier<Set<? extends Location>>>() {
//        }).to((Class) VSphereLocationSupplier.class);

      bind(new TypeLiteral<Supplier<VSphereHost>>() {
      }).to((Class) VSphereHostSupplier.class);

      bind(new TypeLiteral<Supplier<Map<String, CustomFieldDef>>>() {
      }).to((Class) CreateOrGetTagsId.class);

      bind(new TypeLiteral<Supplier<NetworkConfigSupplier>>() {
      }).to((Class) NetworkConfigSupplier.class);

      bind(new TypeLiteral<Function<VirtualMachine, SshClient>>() {
      }).to(VirtualMachineToSshClient.class);

      bind(new TypeLiteral<Function<VirtualMachine, Image>>() {
      }).to(VirtualMachineToImage.class);

      bind(new TypeLiteral<Function<String, VSphereHost>>() {
      }).to(GetRecommendedVSphereHost.class);
   }
项目:jcloud-vsphere    文件:VSphereHostSupplier.java   
@Inject
public VSphereHostSupplier(Supplier<VSphereServiceInstance> serviceInstance,
                           Function<HostSystem, VSphereHost> systemHostToVSphereHost) {
   this.serviceInstance = checkNotNull(serviceInstance, "serviceInstance");
   this.systemHostToVSphereHost = checkNotNull(systemHostToVSphereHost, "systemHostToVSphereHost");
}
项目:jcloud-vsphere    文件:GetRecommendedVSphereHost.java   
@Inject
public GetRecommendedVSphereHost(Supplier<VSphereServiceInstance> serviceInstance,
                                 Function<HostSystem, VSphereHost> systemHostToVSphereHost) {
   this.serviceInstance = checkNotNull(serviceInstance, "serviceInstance");
   this.systemHostToVSphereHost = checkNotNull(systemHostToVSphereHost, "systemHostToVSphereHost");
}