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

项目: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 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 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();
  }
}
项目:vijava    文件:SessionProducer.java   
public static void main(String[] args) throws Exception
{
    CommandLineParser clp = new CommandLineParser(new OptionSpec[]{}, args);
    String urlStr = clp.get_option("url");
        String username = clp.get_option("username");
    String password = clp.get_option("password");

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

    String sessionStr = si.getServerConnection().getSessionStr();

    System.out.println("sessionStr=" + sessionStr);

    Thread.sleep(30*60*1000);

    si.getServerConnection().logout();
}
项目:vijava    文件:PrintAlarmManager.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java PrintAlarmManager " 
      + "<url> <username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  AlarmManager alarmMgr = si.getAlarmManager();

  System.out.println("Alarm expressions:");
  AlarmExpression[] defaultExps = alarmMgr.getDefaultExpression();
  printAlarmExpressions(defaultExps);

  System.out.println("\n\nAlarm descriptions:");
  AlarmDescription ad = alarmMgr.getDescription();
  printAlarmDescription(ad);

  si.getServerConnection().logout();
}
项目:roboconf-platform    文件:VmwareIaasHandler.java   
@Override
public boolean isMachineRunning( TargetHandlerParameters parameters, String machineId )
throws TargetException {

    boolean result;
    try {
        final ServiceInstance vmwareServiceInstance = getServiceInstance( parameters.getTargetProperties());
        VirtualMachine vm = getVirtualMachine( vmwareServiceInstance, machineId );
        result = vm != null;

    } catch( Exception e ) {
        throw new TargetException( e );
    }

    return result;
}
项目:roboconf-platform    文件:VmwareIaasHandler.java   
@Override
public String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId )
throws TargetException {

    String result = null;
    try {
        ServiceInstance vmwareServiceInstance = VmwareIaasHandler.getServiceInstance( parameters.getTargetProperties());
        String rootInstanceName = InstanceHelpers.findRootInstancePath( parameters.getScopedInstancePath());
        VirtualMachine vm = VmwareIaasHandler.getVirtualMachine( vmwareServiceInstance, rootInstanceName );
        if( vm != null )
            result = vm.getGuest().getIpAddress();

    } catch( Exception e ) {
        throw new TargetException( e );
    }

    return result;
}
项目:WBSAirback    文件:HypervisorManagerVMware.java   
public HypervisorManagerVMware(String address, String user, String password) throws Exception {
    if(!NetworkManager.isValidAddress(address)) {
        throw new Exception("invalid network address");
    }

    StringBuilder _sb = new StringBuilder();
    _sb.append("https://");
    _sb.append(address);
    _sb.append("/sdk/VimService");
    this._url = _sb.toString();
    this._address = address;
    this._user = user;
    this._password = password;
    try {
        trustAllHttpsCertificates();
        logger.info("Vmware: connected at first attempt");
    } catch (SSLHandshakeException sslEx) {
        trustAllHttpsCertificatesWithoutKeys();
        logger.info("Vmware: connected at second attempt");
    }
    new ServiceInstance(new URL(this._url), this._user, this._password, true);
}
项目:vmware-vsphere-monitoring-extension    文件:VMWareMonitor.java   
private void connect() {

        if (configuration != null && configuration.getConfigYml() != null) {
            Map<String, ?> config = configuration.getConfigYml();
            String host = (String) config.get("host");
            String username = (String) config.get("username");
            String password = getPassword(config);

            String url = "https://" + host + "/sdk";
            try {
                ServiceInstance serviceInstance = new ServiceInstance(new URL(url), username, password, true);
                rootFolder = serviceInstance.getRootFolder();
            } catch (Exception e) {
                logger.error("Unable to connect to the host [" + host + "]", e);
                throw new RuntimeException("Unable to connect to the host [" + host + "]", e);
            }
            logger.info("Connection to: " + url + " Successful");
        }
    }
项目:newrelic-pcf-drain    文件:MonitoringConfiguration.java   
@Bean
@ConditionalOnProperty("vsphere.host")
InventoryNavigator inventoryNavigator(@Value("${vsphere.host}") String host,
        @Value("${vsphere.username}") String username,
        @Value("${vsphere.password}") String password) throws MalformedURLException,
        RemoteException {
    URL url = new URL(String.format("https://%s/sdk", host));
    ServiceInstance serviceInstance = new ServiceInstance(url, username, password, true);
    return new InventoryNavigator(serviceInstance.getRootFolder());
}
项目: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;
}
项目:cf-new-relic-drain    文件:MonitoringConfiguration.java   
@Bean
@ConditionalOnProperty("vsphere.host")
InventoryNavigator inventoryNavigator(@Value("${vsphere.host}") String host,
        @Value("${vsphere.username}") String username,
        @Value("${vsphere.password}") String password) throws MalformedURLException,
        RemoteException {
    URL url = new URL(String.format("https://%s/sdk", host));
    ServiceInstance serviceInstance = new ServiceInstance(url, username, password, true);
    return new InventoryNavigator(serviceInstance.getRootFolder());
}
项目: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    文件:CreateAndConnectVSphereClient.java   
@Inject
public CreateAndConnectVSphereClient(Function<Supplier<NodeMetadata>, ServiceInstance> providerContextToCloud,
                                     Factory runScriptOnNodeFactory,
                                     @Provider Supplier<URI> providerSupplier,
                                     @Provider Supplier<Credentials> credentials) {

   this.credentials = checkNotNull(credentials, "credentials is needed");
   this.providerSupplier = checkNotNull(providerSupplier, "endpoint to vSphere node or vCenter server is needed");
}
项目:jcloud-vsphere    文件:VSphereLocationSupplierTest.java   
@Test
public void vSphereLocationSupplierTest() throws IOException {
   ServerConnection serverConnection = PowerMock.createMock(ServerConnection.class);
   WSClient wsClient = PowerMock.createMock(WSClient.class);
   ManagedObjectReference managedObjectReference = PowerMock.createMock(ManagedObjectReference.class);
   ServiceInstance serviceInstance = PowerMock.createMock(ServiceInstance.class);
   CreateAndConnectVSphereClient supplier = PowerMock.createMock(CreateAndConnectVSphereClient.class);
   VSphereServiceInstance vSphereServiceInstance = PowerMock.createMock(VSphereServiceInstance.class);
   Folder rootFolder = PowerMock.createMock(Folder.class);

   expect(supplier.get()).andReturn(vSphereServiceInstance);

   expect(vSphereServiceInstance.getInstance()).andReturn(serviceInstance);

   expect(serviceInstance.getRootFolder()).andReturn(rootFolder);

   expect(rootFolder.getServerConnection()).andReturn(serverConnection).anyTimes();
   expect(rootFolder.getMOR()).andReturn(managedObjectReference);
   expect(serverConnection.getServiceInstance()).andReturn(serviceInstance).anyTimes();
   expect(serverConnection.getVimService()).andReturn(new VimPortType(wsClient)).anyTimes();
   AboutInfo aboutInfo = new AboutInfo();
   aboutInfo.setApiVersion("5.1");
   expect(serviceInstance.getPropertyCollector()).andReturn(new PropertyCollector(serverConnection, managedObjectReference));
   expect(serviceInstance.getAboutInfo()).andReturn(aboutInfo);
   vSphereServiceInstance.close();
   replay(supplier, vSphereServiceInstance, serviceInstance, rootFolder, serverConnection);


   VSphereLocationSupplier vSphereLocationSupplier = new VSphereLocationSupplier(supplier);
   Set<? extends Location> location = vSphereLocationSupplier.get();

   Assert.assertEquals(1, location.size());
   for (Location l : location) {
      Assert.assertEquals("default", l.getId());
   }


   verify(supplier, vSphereServiceInstance, serviceInstance, rootFolder, serverConnection);
}
项目: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));


}
项目:vmstats    文件:meGrabber.java   
public meGrabber(ServiceInstance si, 
        BlockingQueue<Object> vm_mob_queue,
           BlockingQueue<Object> esx_mob_queue, 
           Hashtable<String, String> appConfig, 
           BlockingQueue<Object> sender) {
    this.vm_mob_queue = vm_mob_queue;
    this.esx_mob_queue = esx_mob_queue;
    this.appConfig = appConfig;
    this.si = si;
       this.sender = sender;
       this.clusterMap = new HashMap<String, String>();
       this.vm_cache = new ArrayList<Object>();
       this.esx_cache = new ArrayList<Object>();
}
项目:primecloud-controller    文件:VmwareClient.java   
/**
 * serviceInstanceを取得します。
 *
 * @return serviceInstance
 */
public ServiceInstance getServiceInstance() {
    if (serviceInstance == null) {
        initialize();
    }
    return serviceInstance;
}
项目:vijava    文件:CacheInstance.java   
public CacheInstance(ServiceInstance si)
{
  this.si = si;
    mom = new ManagedObjectWatcher(si.getPropertyCollector());
    cache = new ManagedObjectCache(si);
    mom.addObserver(cache);
}
项目:vijava    文件:ListAuthorization.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java ListAuthorization <url> " 
      + "<username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  AuthorizationManager am = si.getAuthorizationManager();
  AuthorizationDescription ad = am.getDescription();

  System.out.println("Descriptions of all privileges:");
  printDescriptions(ad.getPrivilege());

  System.out.println("Descriptions of all privilege groups:");
  printDescriptions( ad.getPrivilegeGroup());

  System.out.println("List of all privileges with details:");
  printPrivileges(am.getPrivilegeList());

  System.out.println("List of all the roles with details:");
  printRoles(am.getRoleList());

  si.getServerConnection().logout();
}
项目:vijava    文件:VMDeviceMgmt.java   
public static void main(String[] args) throws Exception 
  {
    String vmName = "Rawc1.2_Win7x32bit_Target";

    ServiceInstance si = new ServiceInstance(new URL("https://8.8.8.8/sdk"), "administrator", "vmware", true);
    VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("VirtualMachine", vmName);

    VirtualMachineDeviceManager vmdm = new VirtualMachineDeviceManager(vm);

    vmdm.createNetworkAdapter(VirtualNetworkAdapterType.VirtualE1000, "dvPortGroup", "00:50:56:00:12:14", true, true);

//  vmdm.createNetworkAdapter(VirtualNetworkAdapterType.VirtualVmxnet3, null, "VM Network", true, false);
//  vmdm.createNewHardDisk(2048, VirtualDiskType.thin, VirtualDiskMode.persistent);
//  vmdm.addHardDisk("[psorl-iscsi01] tobin-win7-a/Rawc1.2_Win7x32bit_Target.vmdk", VirtualDiskMode.persistent);

//  vmdm.createNewHardDrive(1000, VirtualDiskType.flatMonolithic, VirtualDiskMode.persistent, false, false, null);
//  vmdm.createNewHardDrive(1000, VirtualDiskType.flatMonolithic, VirtualDiskMode.persistent, false, false, null);

//  List<VirtualDevice> devs = new ArrayList<VirtualDevice>();
//  devs.add( vmdm.findHardDisk("Hard disk 2"));
//  devs.add( vmdm.findHardDisk("Hard disk 3"));
//  devs.add( vmdm.findHardDisk("Hard disk 4"));
//  devs.add( vmdm.findHardDisk("Hard disk 5"));
//    
//  // CAUTION: the second parameter is true, and remove disk files in datastore.
//    vmdm.removeDevices(devs, true);

    si.getServerConnection().logout();
  }
项目: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    文件:CacheFrameworkSample.java   
public static void main(String[] args) throws Exception
{
  ServiceInstance si = new ServiceInstance(new URL("http://10.20.143.205/sdk"), "root", "password", true); 
  Folder rootFolder = si.getRootFolder();
  ManagedEntity[] vms = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");
  ManagedEntity[] hosts = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem");

  CacheInstance vicf = new CacheInstance(si);
  vicf.watch(vms, new String[] {"name", "runtime.powerState", "summary"});
  vicf.watch(hosts, new String[] {"name", "summary"});
  vicf.start();

  //check if the caching is ready to use; otherwise wait
  while(!vicf.isReady()) 
  {
    Thread.sleep(1000);
  }

  Thread[] vrs = new VimReader[2];

  for(int i=0; i<vrs.length; i++)
  {
    vrs[i] = new VimReader("Thread " + i, vicf, vms, hosts);
    vrs[i].start();
  }

  for(int i=0; i<vrs.length; i++)
  {
    vrs[i].join();
  }
  si.getServerConnection().logout();
}
项目:vijava    文件:PrintPerfMgr.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java PrintPerfMgr " 
      + "<url> <username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  PerformanceManager perfMgr = si.getPerformanceManager();

  System.out.println("***Print All Descriptions:");
  PerformanceDescription pd = perfMgr.getDescription();
  printPerfDescription(pd);

  System.out.println("\n***Print All Historical Intervals:");
  PerfInterval[] pis = perfMgr.getHistoricalInterval();
  printPerfIntervals(pis);

  System.out.println("\n***Print All Perf Counters:");
  PerfCounterInfo[] pcis = perfMgr.getPerfCounter();
  printPerfCounters(pcis);

  si.getServerConnection().logout();
}
项目:vijava    文件:SwapLicenseV4.java   
public static void main(String[] args) throws Exception
{
  ServiceInstance si = new ServiceInstance(new URL("https://8.8.8.8/sdk"), 
      "administrator", "vmware", true);
  LicenseManager lm = si.getLicenseManager();
  LicenseAssignmentManager lam = lm.getLicenseAssignmentManager();

  LicenseAssignmentManagerLicenseAssignment[] las = lam.queryAssignedLicenses(null);

  String newLic = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX";
  String oldLic = "YYYYY-YYYYY-YYYYY-YYYYY-YYYYY";

  List<LicEntity> entities = new ArrayList<LicEntity>();

  for(LicenseAssignmentManagerLicenseAssignment la : las)
  {
    LicenseManagerLicenseInfo licInfo = la.getAssignedLicense();
    if(oldLic.equals(licInfo.getLicenseKey()))
    {
      entities.add(new LicEntity(la.getEntityId(), la.getEntityDisplayName()));
      System.out.println("entityId:" + la.getEntityId());

    }
  }

  lm.addLicense(newLic, null);

  for(LicEntity e : entities)
  {
    lam.updateAssignedLicense(e.entityId, newLic, e.displayName);
  }
  lm.removeLicense(oldLic);
}
项目:vijava    文件:PrintLicExpirationDateV4.java   
public static void main(String[] args) throws Exception
{
  ServiceInstance si = new ServiceInstance(new URL("https://8.8.8.8/sdk"), 
      "administrator", "vmware", true);
  LicenseManager lm = si.getLicenseManager();
  LicenseManagerLicenseInfo[] lics = lm.getLicenses();

  DateFormat df = DateFormat.getInstance();
  for(LicenseManagerLicenseInfo lic : lics)
  {
    Date expDate = null;

    if("eval".equalsIgnoreCase(lic.getEditionKey()))
    {
      LicenseManagerEvaluationInfo evalInfo = lm.getEvaluation();
      expDate = getExpirationDate(evalInfo.getProperties());
    }
    else
    {
      expDate = getExpirationDate(lic.getProperties());
    }

    if(expDate!=null)
    {
      System.out.println(lic.getLicenseKey() + " expires on " + df.format(expDate));
    }
    else
    {
      System.out.println(lic.getLicenseKey() + " expires on NEVER");
    }
  }
}
项目:vijava    文件:PrintLicense.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java PrintLicense <url> " 
      + "<username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  LicenseManager lm = si.getLicenseManager();

  System.out.println("License edition:" 
    + lm.getLicensedEdition());

  System.out.println("Licnese source available:"
    + lm.getSourceAvailable());

  printLicenseSource(lm.getSource());

  System.out.println("License Diagnostic Info:");
  printDiagnostics(lm.getDiagnostics());

  // The featureInfo property is deprecated as of 2.5.
  // Use the querySupportedFeatures as follows.
  System.out.println("\nLicense Features:");
  printLicenseFeatures(lm.querySupportedFeatures(null));

  System.out.println("\nLicense Usage:");
  printLicenseUsage(lm.queryLicenseUsage(null));

  System.out.println("\nLicense source availability:");
  printLicenseAvailable(
    lm.queryLicenseSourceAvailability(null));

  si.getServerConnection().logout();
}
项目:vijava    文件:DrsModeChanger.java   
public static void main(String[] args) throws Exception 
{
    if(args.length!=4)
    {
        System.out.println("Usage: DrsModeChanger url username password mode");
        System.exit(-1);
    }

    URL url = new URL(args[0]);
    String username = args[1];
    String password = args[2];
    String mode = args[3];
    String drs_obj_id = "domain-c5";

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

    ManagedObjectReference mref_drs = new ManagedObjectReference();
    mref_drs.set_value(drs_obj_id);
    mref_drs.setType("ClusterComputeResource");

    ClusterComputeResource ccr = (ClusterComputeResource )MorUtil.createExactManagedEntity(si.getServerConnection(), mref_drs);

    ClusterConfigSpec ccs = new ClusterConfigSpec();
    ClusterDrsConfigInfo cdci = new ClusterDrsConfigInfo();
    if("manual".equals(mode))
        cdci.setDefaultVmBehavior(DrsBehavior.manual);
    else 
        cdci.setDefaultVmBehavior(DrsBehavior.fullyAutomated);
    cdci.setVmotionRate(new Integer(5));
    ccs.setDrsConfig(cdci);

    ccr.reconfigureCluster_Task(ccs, true);

    si.getServerConnection().logout();
    System.out.println("End of changing DRS config to " + args[3]);
}
项目:vijava    文件:PrintTaskManager.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java PrintTaskManager " 
      + "<url> <username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  TaskManager taskMgr = si.getTaskManager();

  int maxCollector = taskMgr.getMaxCollector();
  System.out.println("Maximum number of collectors to " +
        "retrive historical tasks: " + maxCollector);

  System.out.println("\nTask description:");
  TaskDescription td = taskMgr.getDescriptioin();
  printTaskDescription(td);

  System.out.println("\nRecent tasks:");
  Task[] recentTasks = taskMgr.getRecentTasks();
  for(int i=0; recentTasks!=null && i<recentTasks.length; i++)
  {
    TaskInfo ti = recentTasks[i].getTaskInfo();
    System.out.println("\nName:" + ti.getName());
    System.out.println("Key:" + ti.getKey());
    System.out.println("State:" + ti.getState());
  }
  si.getServerConnection().logout();
}
项目:vijava    文件:QueryVirtualDisk.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java QueryVirtualDisk " 
      + "<url> <username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  VirtualDiskManager vdMgr = si.getVirtualDiskManager();
  if(vdMgr==null)
  {
    System.out.println("VirtualDiskManager not available.");
    si.getServerConnection().logout();
    return;
  }

  String vmdkPath = 
    "[storage1 (2)] sdk188_sec/sdk188_sec.vmdk";

  int fragPerfent = vdMgr.queryVirtualDiskFragmentation(
      vmdkPath, null);
  System.out.println("Defragmentation:" + fragPerfent + "%");

  String uuid = vdMgr.queryVirtualDiskUuid(vmdkPath, null);
  System.out.println("Disk UUID:" + uuid);

  HostDiskDimensionsChs hddc = vdMgr.queryVirtualDiskGeometry(
      vmdkPath, null);
  System.out.println("Cylinder:" + hddc.getCylinder());
  System.out.println("Head:" + hddc.getHead());
  System.out.println("Sector:" + hddc.getSector());

  si.getServerConnection().logout();
}
项目: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();
}
项目:vijava    文件:TestServlet.java   
protected void service(
    HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException 
{
  PrintWriter out = response.getWriter();

  String morStr = request.getParameter(MOREF);
  String type = morStr.substring(0, morStr.indexOf(":"));
  String value = morStr.substring(morStr.indexOf(":")+1);

  ManagedObjectReference mor = new ManagedObjectReference();
  mor.setType(type);
  mor.set_value(value);

  String sessionStr = "vmware_soap_session=\"" 
    + request.getParameter(SESSION_ID) + "\"";

  System.out.println("morStr:" + morStr);
  System.out.println("serviceUrl" 
      + request.getParameter(SERVICE_URL) );
  System.out.println("session:" + sessionStr);

  ServiceInstance si = new ServiceInstance(new URL(
      request.getParameter(SERVICE_URL)),sessionStr, true);

  ManagedEntity me = MorUtil.createExactManagedEntity(
      si.getServerConnection(), mor);

  String name = me.getName();
  out.println("name:" + name);
  out.println(DateFormat.getDateTimeInstance().format(
      new Date()));
}
项目:roboconf-platform    文件:VmwareIaasHandler.java   
static ServiceInstance getServiceInstance( Map<String,String> targetProperties )
throws RemoteException, MalformedURLException {

    return new ServiceInstance(
            new URL(targetProperties.get( URL )),
            targetProperties.get( USER ),
            targetProperties.get( PASSWORD ),
            Boolean.parseBoolean(targetProperties.get( IGNORE_CERTIFICATE )));
}