Package com.vmware.vim25.mo

Examples of com.vmware.vim25.mo.InventoryNavigator


  }

  public ArrayList<String> listResourcePools() throws InvalidProperty, RuntimeFault, RemoteException {

    ManagedEntity[] resourcepools = new InventoryNavigator(rootFolder).searchManagedEntities("ResourcePool");

    ArrayList<String> resourcePoolList=new ArrayList<String>();
   
    for(int i=0; i<resourcepools.length; i++)
    {
View Full Code Here


 
  public ArrayList<String> listNetworks() throws InvalidProperty, RuntimeFault, RemoteException {

    ManagedEntity[] datacenters =
      new InventoryNavigator(rootFolder).searchManagedEntities("Datacenter");
   
    ArrayList<String> networkList=new ArrayList<String>();

    for(int i=0; i<datacenters.length; i++)
    {
View Full Code Here

  public ArrayList<String> listVms() throws InvalidProperty, RuntimeFault, RemoteException  {

    ArrayList<String> vmList=new ArrayList<String>();
   
    ManagedEntity[] vms=new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");

    for(int i=0; i<vms.length; i++)
    {
      vmList.add(vms[i].getName());
    }
View Full Code Here

    return vmList;
  }
 
 
  public VirtualMachine findVmByName(String vmName) throws InvalidProperty, RuntimeFault, RemoteException {
    VirtualMachine existingVm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine",vmName);

    return existingVm;
  }
View Full Code Here

      String vmGuestOsId, VmDisk[] vmDisks,
      VmNic[] vmNics, String vmDataCenterName, String vmDataStoreName, String vmClusterName ) throws Exception {
    //  ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");

    System.out.println("Datacenter:"+vmDataCenterName);
    Datacenter dc = (Datacenter) new InventoryNavigator(rootFolder).searchManagedEntity("Datacenter", vmDataCenterName);

    //Now find the correct resourcepool to create the vm
    ManagedEntity[] resourcepools = new InventoryNavigator(rootFolder).searchManagedEntities("ResourcePool");

   
    ResourcePool rp = null;

    System.out.println("Cluster:"+vmClusterName);
   
    for(int i=0; i<resourcepools.length; i++)
    {
      ResourcePool resourcepool = (ResourcePool) resourcepools[i];
      if (resourcepools[i].getParent().getName().equals(vmClusterName)) {
        System.out.println("using cluster/resourcepool "+vmClusterName);
        rp= (ResourcePool)resourcepools[i];
      }
    }

    Folder vmFolder = dc.getVmFolder();

    // create vm config spec
    VirtualMachineConfigSpec vmSpec =
      new VirtualMachineConfigSpec();
    vmSpec.setName(vmName);
    vmSpec.setAnnotation("Created by JvsphereControl");
    vmSpec.setMemoryMB(vmMemorySize);
    vmSpec.setNumCPUs(vmCpuCount);
    vmSpec.setGuestId(vmGuestOsId);
   
    System.out.println("Vmname:"+vmName);
    System.out.println("Memorysize:"+vmMemorySize);
    System.out.println("GuestOsId:"+vmGuestOsId);

    //We create one scsi controller
    VirtualDeviceConfigSpec machineSpecs[]= new VirtualDeviceConfigSpec[vmNics.length+1+vmDisks.length];
    int cKey = 1000;
    VirtualDeviceConfigSpec scsiSpec = VsphereUtils.createScsiSpec(cKey);
    machineSpecs[0]=scsiSpec;
   
    // Associate the virtual disks with the scsi controller
    for (int i=0; i< vmDisks.length; i++) {
        VirtualDeviceConfigSpec diskSpec = VsphereUtils.createDiskSpec(
          vmDataStoreName, cKey, vmDisks[i].getSize(), vmDisks[i].getMode(),i);

        System.out.println("Disk Datastore:"+vmDataStoreName);
        System.out.println("Ckey:"+cKey);
        System.out.println("DiskSize:"+vmDisks[i].getSize());
        System.out.println("DiskMode:"+vmDisks[i].getMode());

      machineSpecs[i+1]=diskSpec;
     
    }
   
     
    //virtual network interfaces
    for (int i=0; i< vmNics.length; i++ ) {

      machineSpecs[vmDisks.length+1+i]= VsphereUtils.createNicSpec(
          vmNics[i].getName(), vmNics[i].getNetwork(),vmNics[i].isStartConnected(),vmNics[i].isConnected(),vmNics[i].getType());
          System.out.println("NicName:"+vmNics[i].getName());
          System.out.println("NicNetwork:"+vmNics[i].getNetwork());
          System.out.println("NicStartConnected:"+vmNics[i].isStartConnected());
          System.out.println("NicConnected:"+vmNics[i].isConnected());
          System.out.println("NicType:"+vmNics[i].getType());

    }  

    vmSpec.setDeviceChange(machineSpecs);

   
    // create vm file info for the vmx file
    VirtualMachineFileInfo vmfi = new VirtualMachineFileInfo();
    vmfi.setVmPathName("["+ vmDataStoreName +"]");
    System.out.println("Vm DatastoreName"+vmDataStoreName);

    vmSpec.setFiles(vmfi);

    // call the createVM_Task method on the vm folder
    // TOO: null, host ?
    Task task = vmFolder.createVM_Task(vmSpec, rp, null);
    String result= task.waitForTask();
    //    String result = task.waitForMe();  


    VirtualMachine newVm=null;

    if(result == Task.SUCCESS)
    {
      System.out.println("VM Created Sucessfully");

      //Search for it and start it if requested
      //TODO powerOnVM_Task (null) =!! null = host , maar was is die host?

      newVm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine",vmName);
    } else
    {
      System.out.println("VM could not be created. Error:");
      if (task.getTaskInfo() != null && task.getTaskInfo().getError() != null)
      {          
View Full Code Here

     * @param name Name of the entity.
     * @return Found managed entity in success or null in failure.
     */
    protected ManagedEntity searchManagedEntity(String type, String name)
    {
        ManagedEntity ret = null;
        try {
            ret = new InventoryNavigator
                (rootFolder_).searchManagedEntity(type, name);
        } catch (Exception e) { /* InvalidProperty, RuntimeFault, RemoteException */
            logger_.warning(Utility.toString(e));
View Full Code Here

        ManagedObjectReference mor =
            generateMoref("VirtualMachine", morefStr);
        if (mor == null) { return null; }

        ManagedEntity vm =
            MorUtil.createExactManagedEntity(si_.getServerConnection(), mor);

        if (vm instanceof VirtualMachine) {
            return (VirtualMachine) vm; /* may be null */
        } else {
View Full Code Here

     */
    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

            vmsnap = getSnapshotInTree(snapName);
            if (vmsnap == null) { return false; }
        }

        try {
            Task task = null;
            switch (type) {
            case CREATE:
                task = vm_.createSnapshot_Task(snapName, null, false, false);
                break;
            case DELETE:
                task = vmsnap.removeSnapshot_Task(true);
                break;
            case REVERT:
                task = vmsnap.revertToSnapshot_Task(null, true);
                break;
            default:
                throw new Exception("Snapshot TaskType is wrong.");
            }
            assert task != null;
            String ret = task.waitForTask();
            if (ret.equals("success")) {
                logger_.info(messageInSuccess);
                return true;
            } else {
                logger_.info(messageInFailure);
View Full Code Here

        vmConfigSpec.setDeviceChange
            (specList.toArray(new VirtualDeviceConfigSpec[0]));

        /* reconfigure vm task */
        try {
            Task task = vm_.reconfigVM_Task(vmConfigSpec);
            String ret = task.waitForTask();
            logger_.info(String.format("%s: addDisksToVm()\n", ret));
            if (ret.equals("success")) {
                return true;
            } else {
                return false;
View Full Code Here

TOP

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

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.