Package com.vmware.vim25.mo

Examples of com.vmware.vim25.mo.VirtualMachine


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


    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);
    HostSystem newHost = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity(
            "HostSystem", newHostName);
    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)
    {
      System.out.println("CPU/software NOT compatible. Exit.");
      si.getServerConnection().logout();
      return;
    }
   
    Task task = vm.migrateVM_Task(cr.getResourcePool(), newHost,
        VirtualMachineMovePriority.highPriority,
        VirtualMachinePowerState.poweredOn);
 
    if(task.waitForMe()==Task.SUCCESS)
    {
View Full Code Here

   
    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();
   
    if("memory".equalsIgnoreCase(deviceType))
    {
      System.out.println("Reconfig memory for VM: " + vmname);
      vmConfigSpec.setMemoryAllocation(getShares(value));         
    }
    else if("cpu".equalsIgnoreCase(deviceType))
    {
      System.out.println("Reconfig CPU for VM:  " + vmname);      
      vmConfigSpec.setCpuAllocation(getShares(value));
    }
    else
    {
      System.out.println("Incorrect option for " + vmname);
    }

    Task task = vm.reconfigVM_Task(vmConfigSpec);
    task.waitForMe();
  }
View Full Code Here

    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();
   
    if("add".equalsIgnoreCase(op))
    {
      String dsName ="storage1 (2)";
      String iso = "vimaster";
      VirtualDeviceConfigSpec cdSpec = createAddCdConfigSpec(vm, dsName, iso);
      vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[]{cdSpec});
    }
    else if("remove".equalsIgnoreCase(op))
    {
      String cdName = "CD/DVD Drive 2";
      VirtualDeviceConfigSpec cdSpec = createRemoveCdConfigSpec(vm, cdName);
      vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[]{cdSpec});
    }
    else
    {
      System.out.println("Invlaid device type [disk|cd]");
      return;
    }
   
    Task task = vm.reconfigVM_Task(vmConfigSpec);
    task.waitForMe();
  }
View Full Code Here

    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 nicSpec =
      getNICDeviceConfigSpec(vm, op, name);
   
    String result = null;
    if(nicSpec!=null)
    {
      vmConfigSpec.setDeviceChange(
          new VirtualDeviceConfigSpec []{nicSpec});
      Task task = vm.reconfigVM_Task(vmConfigSpec);
      result = task.waitForMe();
    }

    if(result==Task.SUCCESS)
    {
View Full Code Here

   
    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("reboot".equalsIgnoreCase(op))
    {
      vm.rebootGuest();
      System.out.println(vmname + " guest OS rebooted");
    }
    else if("poweron".equalsIgnoreCase(op))
    {
      Task task = vm.powerOnVM_Task(null);
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " powered on");
      }
    }
    else if("poweroff".equalsIgnoreCase(op))
    {
      Task task = vm.powerOffVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " powered off");
      }
    }
    else if("reset".equalsIgnoreCase(op))
    {
      Task task = vm.resetVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " reset");
      }
    }
    else if("standby".equalsIgnoreCase(op))
    {
      vm.standbyGuest();
      System.out.println(vmname + " guest OS stoodby");
    }
    else if("suspend".equalsIgnoreCase(op))
    {
      Task task = vm.suspendVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " suspended");
      }
    }
    else if("shutdown".equalsIgnoreCase(op))
    {
      Task task = vm.suspendVM_Task();
      if(task.waitForMe()==Task.SUCCESS)
      {
        System.out.println(vmname + " suspended");
      }
    }
View Full Code Here

    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();
   
    if("add".equalsIgnoreCase(op))
    {
      int diskSize = 1;
      // mode: persistent|independent_persistent,independent_nonpersistent
      String diskMode = "persistent";
      String diskName = "vijava_disk";
      VirtualDeviceConfigSpec vdiskSpec = createAddDiskConfigSpec(vm, diskSize, diskMode, diskName);
      VirtualDeviceConfigSpec [] vdiskSpecArray = {vdiskSpec};        
      vmConfigSpec.setDeviceChange(vdiskSpecArray);
    }
    else if("remove".equalsIgnoreCase(op))
    {
      // mode: persistent|independent_persistent,independent_nonpersistent
      String diskName = "vijava_disk";
      VirtualDeviceConfigSpec vdiskSpec = createRemoveDiskConfigSpec(vm, diskName);
      VirtualDeviceConfigSpec [] vdiskSpecArray = {vdiskSpec};        
      vmConfigSpec.setDeviceChange(vdiskSpecArray);
    }
    else
    {
      System.out.println("Invlaid device type [disk|cd]");
      return;
    }
   
    Task task = vm.reconfigVM_Task(vmConfigSpec);
    task.waitForMe();
  }
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

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

      }

      //verify cdrom
     
      //Find if vm by name vmname already exists
      VirtualMachine existingVm=vsphereServer.findVmByName(vmName);

      if (existingVm!=null) {
        System.out.println("Machine exists with name:"+existingVm.getName());
        //vsphereServer.showVmDetail(existingVm);

        //Where was this used for?
        //      VirtualMachineCapability vmc = existingVm.getCapability();
        //      VirtualMachineSummary summary = (VirtualMachineSummary) (existingVm.getSummary());

        if(vmOverwrite) {
          if (vsphereServer.isVmPoweredOn(existingVm))
          {
            vsphereServer.powerOffVm(existingVm);       
          }

          vsphereServer.destroyVm(existingVm);       

        } else {
          System.out.println("use --overwrite true to overwrite");
          System.exit(1);
        }
      }

      VirtualMachine newVm=vsphereServer.createVm(vmName,vmMemory,
          vmCpus,vmOsType,vmDisks,
          vmNics,vsphereDataCenterName,vsphereDataStoreName,vsphereClusterName);

      if (vmCdromIsoPath!=null) {
        vsphereServer.setCdromVm(newVm,vmCdromIsoPath,vmCdromDataStoreName);
View Full Code Here

TOP

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

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.