Package com.vmware.vim25.mo

Examples of com.vmware.vim25.mo.ServiceInstance


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

    ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);
   
    String hostname = "sjin-dev1.eng.vmware.com";

    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;

    host = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity("HostSystem", hostname);
 
    if(host==null)
    {
      System.out.println("Host not found");
      si.getServerConnection().logout();
      return;
    }
   
    HostDatastoreSystem hds = host.getHostDatastoreSystem();
   
    HostNasVolumeSpec hnvs = new HostNasVolumeSpec();
    hnvs.setRemoteHost("10.20.140.25");
    hnvs.setRemotePath("/home/vm_share");
    hnvs.setLocalPath("VM_Share");
    hnvs.setAccessMode("readWrite"); // or, "readOnly"
   
    Datastore ds = hds.createNasDatastore(hnvs);
    DatastoreInfo di = ds.getInfo();
   
    System.out.println("Name:" + di.getName());
    System.out.println("FreeSpace:" + di.getFreeSpace());
   
    si.getServerConnection().logout();
  }
View Full Code Here


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

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

    EventManager evtMgr = si.getEventManager();

    if(evtMgr!=null)
    {
      EventFilterSpec eventFilter = new EventFilterSpec();
      EventHistoryCollector ehc =
        evtMgr.createCollectorForEvents(eventFilter);
     
      int total = 0;
     
      Event[] latestEvts = ehc.getLatestPage();
      printEvents(latestEvts, 0);
      total += latestEvts==null? 0 : latestEvts.length;
     
      System.out.println("\nBefore Latest Page:");
      ehc.resetCollector();
      while(true)
      {
        Event[] events = ehc.readPreviousEvents(50);
        if(events==null)
        {
          break;
        }
        printEvents(events, total);
        total += events.length;
      }
    }
    si.getServerConnection().logout();
  }
View Full Code Here

        System.out.println("java ExportOvfToLocal <SdkUrl> <username> <password> <VappOrVmName> <hostip> <VirtualMachine|VirtualApp> <localDir>");
        System.out.println("java ExportOvfToLocal https://10.20.152.74/sdk root password NewVM1 10.20.152.74 VirtualMachine C:\\Temp\\ovf\\");
        return;
      }
     
      ServiceInstance si = new ServiceInstance(new URL(args[0]), args[1], args[2], true);

      String vAppOrVmName = args[3];
      String hostip = args[4];
      String entityType = args[5];
      String targetDir = args[6];

      HostSystem host = (HostSystem) si.getSearchIndex().findByIp(null, hostip, false);
       
      System.out.println("Host Name : " + host.getName());
      System.out.println("Network : " + host.getNetworks()[0].getName());
      System.out.println("Datastore : " + host.getDatastores()[0].getName());

      InventoryNavigator iv = new InventoryNavigator(si.getRootFolder());
     
      HttpNfcLease hnLease = null;
     
      ManagedEntity me = null;
      if (entityType.equals("VirtualApp"))
      {
        me = iv.searchManagedEntity("VirtualApp", vAppOrVmName);
        hnLease = ((VirtualApp)me).exportVApp();
      }
      else
      {
        me = iv.searchManagedEntity("VirtualMachine", vAppOrVmName);
        hnLease = ((VirtualMachine)me).exportVm();
      }
       
      // Wait until the HttpNfcLeaseState is ready
      HttpNfcLeaseState hls;
      for(;;)
      {
        hls = hnLease.getState();
        if(hls == HttpNfcLeaseState.ready)
        {
          break;
        }
        if(hls == HttpNfcLeaseState.error)
        {
          si.getServerConnection().logout();
          return;
        }
      }
     
      System.out.println("HttpNfcLeaseState: ready ");
      HttpNfcLeaseInfo httpNfcLeaseInfo = hnLease.getInfo();
      httpNfcLeaseInfo.setLeaseTimeout(300*1000*1000);
      printHttpNfcLeaseInfo(httpNfcLeaseInfo);

      //Note: the diskCapacityInByte could be many time bigger than
      //the total size of VMDK files downloaded.
      //As a result, the progress calculated could be much less than reality.
      long diskCapacityInByte = (httpNfcLeaseInfo.getTotalDiskCapacityInKB()) * 1024;

      leaseProgUpdater = new LeaseProgressUpdater(hnLease, 5000);
      leaseProgUpdater.start();

      long alredyWrittenBytes = 0;
      HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
      if (deviceUrls != null)
      {
        OvfFile[] ovfFiles = new OvfFile[deviceUrls.length];
        System.out.println("Downloading Files:");
        for (int i = 0; i < deviceUrls.length; i++)
        {
          String deviceId = deviceUrls[i].getKey();
          String deviceUrlStr = deviceUrls[i].getUrl();
          String diskFileName = deviceUrlStr.substring(deviceUrlStr.lastIndexOf("/") + 1);
          String diskUrlStr = deviceUrlStr.replace("*", hostip);
          String diskLocalPath = targetDir + diskFileName;
          System.out.println("File Name: " + diskFileName);
          System.out.println("VMDK URL: " + diskUrlStr);
          String cookie = si.getServerConnection().getVimService().getWsc().getCookie();
          long lengthOfDiskFile = writeVMDKFile(diskLocalPath, diskUrlStr, cookie, alredyWrittenBytes, diskCapacityInByte);
          alredyWrittenBytes += lengthOfDiskFile;
          OvfFile ovfFile = new OvfFile();
          ovfFile.setPath(diskFileName);
          ovfFile.setDeviceId(deviceId);
          ovfFile.setSize(lengthOfDiskFile);
          ovfFiles[i] = ovfFile;
        }
       
        OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
        ovfDescParams.setOvfFiles(ovfFiles);
        OvfCreateDescriptorResult ovfCreateDescriptorResult =
          si.getOvfManager().createDescriptor(me, ovfDescParams);

        String ovfPath = targetDir + vAppOrVmName + ".ovf";
        FileWriter out = new FileWriter(ovfPath);
        out.write(ovfCreateDescriptorResult.getOvfDescriptor());
        out.close();
        System.out.println("OVF Desriptor Written to file: " + ovfPath);
      }
     
      System.out.println("Completed Downloading the files");
      leaseProgUpdater.interrupt();
      hnLease.httpNfcLeaseProgress(100);
      hnLease.httpNfcLeaseComplete();

      si.getServerConnection().logout();
    }
View Full Code Here

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

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

    String vmname = args[3];
    InventoryNavigator inv = new InventoryNavigator(
        si.getRootFolder());
    VirtualMachine vm = (VirtualMachine)inv.searchManagedEntity(
            "VirtualMachine", vmname);
    if(vm==null)
    {
      System.out.println("Cannot find the VM " + vmname
        + "\nExisting...");
      si.getServerConnection().logout();
      return;
    }
   
    AlarmManager alarmMgr = si.getAlarmManager();
   
    AlarmSpec spec = new AlarmSpec();
   
    StateAlarmExpression expression =
      createStateAlarmExpression();
    AlarmAction emailAction = createAlarmTriggerAction(
        createEmailAction());
    AlarmAction methodAction = createAlarmTriggerAction(
        createPowerOnAction());
    GroupAlarmAction gaa = new GroupAlarmAction();

    gaa.setAction(new AlarmAction[]{emailAction, methodAction});
    spec.setAction(gaa);
    spec.setExpression(expression);
    spec.setName("VmPowerStateAlarm");
    spec.setDescription("Monitor VM state and send email " +
        "and power it on if VM powers off");
    spec.setEnabled(true);   
   
    AlarmSetting as = new AlarmSetting();
    as.setReportingFrequency(0); //as often as possible
    as.setToleranceRange(0);
   
    spec.setSetting(as);
   
    alarmMgr.createAlarm(vm, spec);
   
    si.getServerConnection().logout();
  }
View Full Code Here

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

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

    // get the latest event and print it out
    EventManager evtMgr = si.getEventManager();
    Event latestEvent = evtMgr.getLatestEvent();
    printEvent(latestEvent);

    // create a filter spec for querying events
    EventFilterSpec efs = new EventFilterSpec();
    // limit to only error and warning
    efs.setType(new String[] {"VmFailedToPowerOnEvent",
        "HostConnectionLostEvent"});
    // limit to error and warning only
    efs.setCategory(new String[] {"error", "warning"});
   
    // limit to the children of root folder
    EventFilterSpecByEntity eFilter =
      new EventFilterSpecByEntity();
    eFilter.setEntity(si.getRootFolder().getMOR());
    eFilter.setRecursion(
        EventFilterSpecRecursionOption.children);
   
    // limit to the events happened since a month ago
    EventFilterSpecByTime tFilter = new EventFilterSpecByTime();
    Calendar startTime = si.currentTime();
    startTime.roll(Calendar.MONTH, false);
    tFilter.setBeginTime(startTime);
    efs.setTime(tFilter);
    // limit to the user of "administrator"
    EventFilterSpecByUsername uFilter =
        new EventFilterSpecByUsername();
    uFilter.setSystemUser(false);
    uFilter.setUserList(new String[] {"administrator"});

    Event[] events = evtMgr.queryEvents(efs);
   
    // print each of the events
    for(int i=0; events!=null && i<events.length; i++)
    {
      System.out.println("\nEvent #" + i);
      printEvent(events[i]);
    }
   
    si.getServerConnection().logout();
  }
View Full Code Here

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

    String drs_obj_id = "domain-c5"; // The reference ID for cluster
    String vm1_oid = "vm-26"; // The reference ID for VM 1
    String vm2_oid = "vm-28"; // The reference ID for VM 2
   
    // initialize the system, set up web services
    ServiceInstance si = new ServiceInstance(url, username, password, true);
   
    //create the MOR object for DRS cluster
    ManagedObjectReference mref_drs = createMOR("ClusterComputeResource", drs_obj_id);
    ClusterComputeResource ccr = (ClusterComputeResource )
      MorUtil.createExactManagedEntity(si.getServerConnection(), mref_drs);
   
    // create a new ClusterConfigSpec and populate it with related data for affinity rule
    ClusterConfigSpec ccs = new ClusterConfigSpec();

    ClusterAffinityRuleSpec cars = new ClusterAffinityRuleSpec();
    cars.setName("App and DB Appliance Bundle");
    cars.setEnabled(Boolean.TRUE);
    ManagedObjectReference vm1 = createMOR("VirtualMachine", vm1_oid);
    ManagedObjectReference vm2 = createMOR("VirtualMachine", vm2_oid);
    cars.setVm(new ManagedObjectReference[] {vm1, vm2});
   
    ClusterRuleSpec crs = new ClusterRuleSpec();
    //*NOTE*: the following setOperation has to be called since operation must be set.
    crs.setOperation(ArrayUpdateOperation.add);
    crs.setInfo(cars);

    ccs.setRulesSpec(new ClusterRuleSpec[] {crs});

    // make a call to set the configuration.
    ccr.reconfigureCluster_Task(ccs, true);

    si.getServerConnection().logout();
   
    System.out.println("Done with setting affinity rule for DRS cluster.");
  }
View Full Code Here

      System.out.println("Usage: java DrsApp " +
          "<url> <username> <password>");
      System.exit(0);
    }

    ServiceInstance si = new ServiceInstance(
        new URL(args[0]), args[1], args[2], true);
    Folder root = si.getRootFolder();
    ManagedEntity[] mes = new InventoryNavigator(
        root).searchManagedEntities("ClusterComputeResource");
    if(mes==null || mes.length == 0)
    {
      System.out.println("There is no DRS cluster. Exiting.");
      si.getServerConnection().logout();
      return;
    }

    ClusterComputeResource ccr =
        ((ClusterComputeResource)mes[0]);
View Full Code Here

    }

    String vmname = args[3];
    String cloneName = args[4];

    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;
    }

    VirtualMachineCloneSpec cloneSpec =
      new VirtualMachineCloneSpec();
View Full Code Here

      System.exit(0);
    }
    String vmname = args[3];
    String diskName = args[4];
    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;
    }
   
    VirtualMachineConfigSpec vmConfigSpec =
        new VirtualMachineConfigSpec();

    VirtualDeviceConfigSpec vdiskSpec =
        createRemoveDiskConfigSpec(vm.getConfig(), diskName);
    vmConfigSpec.setDeviceChange(
        new VirtualDeviceConfigSpec[]{vdiskSpec} );
    Task task = vm.reconfigVM_Task(vmConfigSpec);
   
    if(task.waitForMe()==Task.SUCCESS)
    {
      System.out.println("Disk removed.");
    }
    else
    {
      System.out.println("Error while removing disk");
    }
   
    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.