Package com.vmware.vim25.mo

Examples of com.vmware.vim25.mo.ServiceInstance


     */
    public void connect()
        throws Exception
    {
        logger_.info(String.format("connecting to %s...", url_));
    si_ = new ServiceInstance
            (new URL(url_), username_, password_, true);
    rootFolder_ = si_.getRootFolder();
        logger_.info("connected");
    }
View Full Code Here


    /** connect to the service if not already connected. */
    public void connect() throws AmazonServiceException {
        try {
            if (service == null) {
                service = new ServiceInstance(new URL(url), username, password, true);
            }
        } catch (RemoteException e) {
            throw new AmazonServiceException("cannot connect to VSphere", e);
        } catch (MalformedURLException e) {
            throw new AmazonServiceException("cannot connect to VSphere", e);
View Full Code Here

     String vmPath = clp.get_option("vmPath");
     String datacenterName= clp.get_option("DatacenterName");

     try
     {
       ServiceInstance si = new ServiceInstance(new URL(urlStr), username, password, true);
       VirtualMachine vm = (VirtualMachine) si.getSearchIndex().findByInventoryPath(vmPath);
       Datacenter dc = (Datacenter) si.getSearchIndex().findByInventoryPath(datacenterName);
      
       if(vm==null || dc ==null)
       {
         System.out.println("VirtualMachine or Datacenter path is NOT correct. Pls double check. ");
         return;
View Full Code Here

    //please change the following three depending your op
    String snapshotname = "test";
    String desc = "A description for sample snapshot";
    boolean removechild = true;
   
    ServiceInstance si = new ServiceInstance(
        new URL(args[0]), args[1], args[2], true);

    Folder rootFolder = si.getRootFolder();
    VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
      rootFolder).searchManagedEntity("VirtualMachine", vmname);

    if(vm==null)
    {
      System.out.println("No VM " + vmname + " found");
      si.getServerConnection().logout();
      return;
    }

    if("create".equalsIgnoreCase(op))
    {
      Task task = vm.createSnapshot_Task(
          snapshotname, desc, false, false);
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println("Snapshot was created.");
      }
    }
    else if("list".equalsIgnoreCase(op))
    {
      listSnapshots(vm);
    }
    else if(op.equalsIgnoreCase("revert"))
    {
      VirtualMachineSnapshot vmsnap = getSnapshotInTree(
          vm, snapshotname);
      if(vmsnap!=null)
      {
        Task task = vmsnap.revertToSnapshot_Task(null);
        if(task.waitForMe()==Task.SUCCESS)
        {
          System.out.println("Reverted to snapshot:"
              + snapshotname);
        }
      }
    }
    else if(op.equalsIgnoreCase("removeall"))
    {
      Task task = vm.removeAllSnapshots_Task();     
      if(task.waitForMe()== Task.SUCCESS)
      {
        System.out.println("Removed all snapshots");
      }
    }
    else if(op.equalsIgnoreCase("remove"))
    {
      VirtualMachineSnapshot vmsnap = getSnapshotInTree(
          vm, snapshotname);
      if(vmsnap!=null)
      {
        Task task = vmsnap.removeSnapshot_Task(removechild);
        if(task.waitForMe()==Task.SUCCESS)
        {
          System.out.println("Removed snapshot:" + snapshotname);
        }
      }
    }
    else
    {
      System.out.println("Invalid operation");
      return;
    }
    si.getServerConnection().logout();
  }
View Full Code Here

{
  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();
 
View Full Code Here

    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");
View Full Code Here

    String username = args[1];
    String password = args[2];

    System.out.println("Connecting to " + urlStr + " as " + username);

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

    System.out.println("info---" + si.getAboutInfo().getFullName());

    // Displays all the Events with Full Formatted message
    try
    {
      EventManager _eventManager = si.getEventManager();
      EventFilterSpec eventFilter = new EventFilterSpec();

      EventHistoryCollector history = _eventManager
          .createCollectorForEvents(eventFilter);
      Event[] events = history.getLatestPage();

      System.out.println("Events In the latestPage are : ");
      for (int i = 0; i < events.length; i++)
      {
        Event anEvent = events[i];
        System.out.println("Event: " + anEvent.getClass().getName()
            + "  FullFormattedMessage: "
            + anEvent.getFullFormattedMessage());
      }
    } catch (Exception e)
    {
      System.out.println("Caught Exception : " + " Name : "
          + e.getClass().getName() + " Message : " + e.getMessage()
          + " Trace : ");
      e.printStackTrace();
    }

    si.getServerConnection().logout();

  }
View Full Code Here

      System.out.println("Usage: java RealtimePerfMonitor "
        + "<url> <username> <password> <vmname>");
      return;
    }

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

    String vmname = args[3];
    ManagedEntity vm = new InventoryNavigator(
      si.getRootFolder()).searchManagedEntity(
        "VirtualMachine", vmname);
   
    if(vm == null)
    {
      System.out.println("Virtual Machine " + vmname
          + " cannot be found.");
      si.getServerConnection().logout();
      return;
    }

    PerformanceManager perfMgr = si.getPerformanceManager();

    // find out the refresh rate for the virtual machine
    PerfProviderSummary pps = perfMgr.queryPerfProviderSummary(vm);
    int refreshRate = pps.getRefreshRate().intValue();
View Full Code Here

      System.out.println("Usage: java SetHostTime " +
            "<url> <username> <password> <hostname>");
      return;
    }

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

    String hostname = args[3];
    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;
    host = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity("HostSystem", hostname);

    if(host==null)
    {
      System.out.println("Cannot find the host:" + hostname);
      si.getServerConnection().logout();
      return;
    }
    HostDateTimeSystem hdts = host.getHostDateTimeSystem();
   
    HostDateTimeInfo info = hdts.getDateTimeInfo();

    System.out.println("The NTP Servers:");
    HostNtpConfig cfg = info.getNtpConfig();
    String[] svrs = cfg.getServer();
    for(int i=0; svrs!=null && i<svrs.length; i++)
    {
      System.out.println("Server["+i+"]:" + svrs[i]);
    }
   
    System.out.println("\nCurrent Time Zone:");
    HostDateTimeSystemTimeZone tz = info.getTimeZone();
    System.out.println("Key:" + tz.getKey());
    System.out.println("Name:" + tz.getName());
    // the GMT offset is in seconds.
    // for example, America/Los_Angeles, -28800
    System.out.println("GmtOffset:" + tz.getGmtOffset());
    System.out.println("Description:" + tz.getDescription());
   
    Calendar curTime = si.currentTime();
    System.out.println("\nCurrent time:" + curTime.getTime());
    //roll back one hour
    curTime.roll(Calendar.HOUR, false);
    hdts.updateDateTime(curTime);
   
    curTime = si.currentTime();
    System.out.println("Current time (after):"
        + curTime.getTime());

    // reset the time
    curTime.roll(Calendar.HOUR, true);
    hdts.updateDateTime(curTime);
   
    si.getServerConnection().logout();
  }
View Full Code Here

      System.out.println("Usage: java GetMultiPerf "
        + "<url> <username> <password> <vmname>");
      return;
    }

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

    String vmname = args[3];
    VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
      si.getRootFolder()).searchManagedEntity(
        "VirtualMachine", vmname);

    if(vm == null)
    {
      System.out.println("Virtual Machine " + vmname
          + " cannot be found.");
      si.getServerConnection().logout();
      return;
    }

    PerformanceManager perfMgr = si.getPerformanceManager();

    int perfInterval = 1800; // 30 minutes for PastWeek
   
    // retrieve all the available perf metrics for vm
    PerfMetricId[] pmis = perfMgr.queryAvailablePerfMetric(
        vm, null, null, perfInterval);
   
    Calendar curTime = si.currentTime();
   
    PerfQuerySpec qSpec = new PerfQuerySpec();
    qSpec.setEntity(vm.getRuntime().getHost());
    //metricIDs must be provided, or InvalidArgumentFault
    qSpec.setMetricId(pmis);
    qSpec.setFormat("normal"); //optional since it's default
    qSpec.setIntervalId(perfInterval);

    Calendar startTime = (Calendar) curTime.clone();
    startTime.roll(Calendar.DATE, -4);
    System.out.println("start:" + startTime.getTime());
    qSpec.setStartTime(startTime);
   
    Calendar endTime = (Calendar) curTime.clone();
    endTime.roll(Calendar.DATE, -3);
    System.out.println("end:" + endTime.getTime());
    qSpec.setEndTime(endTime);
   
    PerfCompositeMetric pv = perfMgr.queryPerfComposite(qSpec);
    if(pv != null)
    {
      printPerfMetric(pv.getEntity());
      PerfEntityMetricBase[] pembs = pv.getChildEntity();
      for(int i=0; pembs!=null && i< pembs.length; i++)
      {
        printPerfMetric(pembs[i]);
      }
    }
    si.getServerConnection().logout();
  }
View Full Code Here

TOP

Related Classes of com.vmware.vim25.mo.ServiceInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.