Package com.vmware.vim25

Examples of com.vmware.vim25.VirtualDisk


    VirtualDeviceBackingInfo parentBacking = templateDisk.getBacking();
    assert(parentBacking != null);

    // TODO Not sure if we need to check if the disk in template and the new disk needs to share the
    // same datastore
    VirtualDisk disk = new VirtualDisk();
    if(parentBacking instanceof VirtualDiskFlatVer1BackingInfo) {
      VirtualDiskFlatVer1BackingInfo backingInfo = new VirtualDiskFlatVer1BackingInfo();
          backingInfo.setDiskMode(((VirtualDiskFlatVer1BackingInfo)parentBacking).getDiskMode());
          backingInfo.setDatastore(morDs);
          backingInfo.setFileName(vmdkDatastorePath);
          backingInfo.setParent((VirtualDiskFlatVer1BackingInfo)parentBacking);
          disk.setBacking(backingInfo);
    } else if(parentBacking instanceof VirtualDiskFlatVer2BackingInfo) {
      VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
          backingInfo.setDiskMode(((VirtualDiskFlatVer2BackingInfo)parentBacking).getDiskMode());
          backingInfo.setDatastore(morDs);
          backingInfo.setFileName(vmdkDatastorePath);
          backingInfo.setParent((VirtualDiskFlatVer2BackingInfo)parentBacking);
          disk.setBacking(backingInfo);
    } else if(parentBacking instanceof VirtualDiskRawDiskMappingVer1BackingInfo) {
      VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
          backingInfo.setDiskMode(((VirtualDiskRawDiskMappingVer1BackingInfo)parentBacking).getDiskMode());
          backingInfo.setDatastore(morDs);
          backingInfo.setFileName(vmdkDatastorePath);
          backingInfo.setParent((VirtualDiskRawDiskMappingVer1BackingInfo)parentBacking);
          disk.setBacking(backingInfo);
    } else if(parentBacking instanceof VirtualDiskSparseVer1BackingInfo) {
      VirtualDiskSparseVer1BackingInfo backingInfo = new VirtualDiskSparseVer1BackingInfo();
          backingInfo.setDiskMode(((VirtualDiskSparseVer1BackingInfo)parentBacking).getDiskMode());
          backingInfo.setDatastore(morDs);
          backingInfo.setFileName(vmdkDatastorePath);
          backingInfo.setParent((VirtualDiskSparseVer1BackingInfo)parentBacking);
          disk.setBacking(backingInfo);
    } else if(parentBacking instanceof VirtualDiskSparseVer2BackingInfo) {
      VirtualDiskSparseVer2BackingInfo backingInfo = new VirtualDiskSparseVer2BackingInfo();
          backingInfo.setDiskMode(((VirtualDiskSparseVer2BackingInfo)parentBacking).getDiskMode());
          backingInfo.setDatastore(morDs);
          backingInfo.setFileName(vmdkDatastorePath);
          backingInfo.setParent((VirtualDiskSparseVer2BackingInfo)parentBacking);
          disk.setBacking(backingInfo);
    } else {
      throw new Exception("Unsupported disk backing: " + parentBacking.getClass().getCanonicalName());
    }

    if(controllerKey < 0)
      controllerKey = vmMo.getIDEDeviceControllerKey();
    disk.setControllerKey(controllerKey);
    if(deviceNumber < 0)
      deviceNumber = vmMo.getNextDeviceNumber(controllerKey);

      disk.setKey(-contextNumber);
      disk.setUnitNumber(deviceNumber);
      disk.setCapacityInKB(sizeInMb*1024);

      VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
      connectInfo.setConnected(true);
      connectInfo.setStartConnected(true);
      disk.setConnectable(connectInfo);
      return disk;
  }
View Full Code Here


    ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {

    assert(vmdkDatastorePathChain != null);
    assert(vmdkDatastorePathChain.length >= 1);

    VirtualDisk disk;
    VirtualDiskFlatVer2BackingInfo backingInfo;
    if(device != null) {
      disk = device;
      backingInfo = (VirtualDiskFlatVer2BackingInfo)disk.getBacking();
    } else {
      disk = new VirtualDisk();
      backingInfo = new VirtualDiskFlatVer2BackingInfo();
          backingInfo.setDatastore(morDs);
          backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
      disk.setBacking(backingInfo);
     
      if(controllerKey < 0)
        controllerKey = vmMo.getIDEDeviceControllerKey();
          if(deviceNumber < 0)
            deviceNumber = vmMo.getNextDeviceNumber(controllerKey);

      disk.setControllerKey(controllerKey);
        disk.setKey(-contextNumber);
        disk.setUnitNumber(deviceNumber);

        VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
        connectInfo.setConnected(true);
        connectInfo.setStartConnected(true);
        disk.setConnectable(connectInfo);
    }
   
        backingInfo.setFileName(vmdkDatastorePathChain[0]);
        if(vmdkDatastorePathChain.length > 1) {
          String[] parentDisks = new String[vmdkDatastorePathChain.length - 1];
View Full Code Here

    int deviceNumber, int contextNumber) throws Exception {

    assert(vmdkDatastorePathChain != null);
    assert(vmdkDatastorePathChain.length >= 1);

    VirtualDisk disk = new VirtualDisk();

    VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
        backingInfo.setDatastore(vmdkDatastorePathChain[0].second());
        backingInfo.setFileName(vmdkDatastorePathChain[0].first());
        backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
        if(vmdkDatastorePathChain.length > 1) {
          Pair<String, ManagedObjectReference>[] parentDisks = new Pair[vmdkDatastorePathChain.length - 1];
          for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
            parentDisks[i] = vmdkDatastorePathChain[i + 1];

          setParentBackingInfo(backingInfo, parentDisks);
        }

        disk.setBacking(backingInfo);

    if(controllerKey < 0)
      controllerKey = vmMo.getIDEDeviceControllerKey();
        if(deviceNumber < 0)
          deviceNumber = vmMo.getNextDeviceNumber(controllerKey);

    disk.setControllerKey(controllerKey);
      disk.setKey(-contextNumber);
      disk.setUnitNumber(deviceNumber);

      VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
      connectInfo.setConnected(true);
      connectInfo.setStartConnected(true);
      disk.setConnectable(connectInfo);

      return disk;
  }
View Full Code Here

            if(vdisk == null) {
                if(s_logger.isTraceEnabled())
                    s_logger.trace("resize volume done (failed)");
                throw new Exception("No such disk device: " + path);
            }
            VirtualDisk disk = vdisk.first();
            long oldSize = disk.getCapacityInKB();
            if (newSize <= oldSize && useWorkerVm == true) {
                deleteWorkerVm(vmMo, vmdkDataStorePath);
            }
            if (newSize < oldSize){
                throw new Exception("VMware doesn't support shrinking volume from larger size: " + oldSize+ " MB to a smaller size: " + newSize + " MB");
            } else if(newSize == oldSize){
                return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
            }
            disk.setCapacityInKB(newSize);

            VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
            VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
            deviceConfigSpec.setDevice(disk);
            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
View Full Code Here

    // vmdkDatastorePath: [datastore name] vmdkFilePath
    public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath, int sizeInMb, ManagedObjectReference morDs,
            int deviceNumber, int contextNumber) throws Exception {

        VirtualDisk disk = new VirtualDisk();

        VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
        backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
        backingInfo.setThinProvisioned(true);
        backingInfo.setEagerlyScrub(false);
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        disk.setBacking(backingInfo);

        int ideControllerKey = vmMo.getIDEDeviceControllerKey();
        if (controllerKey < 0)
            controllerKey = ideControllerKey;
        if (deviceNumber < 0) {
            deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
            if (controllerKey != ideControllerKey && isReservedScsiDeviceNumber(deviceNumber))
                deviceNumber++;
        }
        disk.setControllerKey(controllerKey);

        disk.setKey(-contextNumber);
        disk.setUnitNumber(deviceNumber);
        disk.setCapacityInKB(sizeInMb * 1024);

        VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
        connectInfo.setConnected(true);
        connectInfo.setStartConnected(true);
        disk.setConnectable(connectInfo);

        return disk;
    }
View Full Code Here

        VirtualDeviceBackingInfo parentBacking = templateDisk.getBacking();
        assert (parentBacking != null);

        // TODO Not sure if we need to check if the disk in template and the new disk needs to share the
        // same datastore
        VirtualDisk disk = new VirtualDisk();
        if (parentBacking instanceof VirtualDiskFlatVer1BackingInfo) {
            VirtualDiskFlatVer1BackingInfo backingInfo = new VirtualDiskFlatVer1BackingInfo();
            backingInfo.setDiskMode(((VirtualDiskFlatVer1BackingInfo)parentBacking).getDiskMode());
            backingInfo.setDatastore(morDs);
            backingInfo.setFileName(vmdkDatastorePath);
            backingInfo.setParent((VirtualDiskFlatVer1BackingInfo)parentBacking);
            disk.setBacking(backingInfo);
        } else if (parentBacking instanceof VirtualDiskFlatVer2BackingInfo) {
            VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
            backingInfo.setDiskMode(((VirtualDiskFlatVer2BackingInfo)parentBacking).getDiskMode());
            backingInfo.setDatastore(morDs);
            backingInfo.setFileName(vmdkDatastorePath);
            backingInfo.setParent((VirtualDiskFlatVer2BackingInfo)parentBacking);
            disk.setBacking(backingInfo);
        } else if (parentBacking instanceof VirtualDiskRawDiskMappingVer1BackingInfo) {
            VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
            backingInfo.setDiskMode(((VirtualDiskRawDiskMappingVer1BackingInfo)parentBacking).getDiskMode());
            backingInfo.setDatastore(morDs);
            backingInfo.setFileName(vmdkDatastorePath);
            backingInfo.setParent((VirtualDiskRawDiskMappingVer1BackingInfo)parentBacking);
            disk.setBacking(backingInfo);
        } else if (parentBacking instanceof VirtualDiskSparseVer1BackingInfo) {
            VirtualDiskSparseVer1BackingInfo backingInfo = new VirtualDiskSparseVer1BackingInfo();
            backingInfo.setDiskMode(((VirtualDiskSparseVer1BackingInfo)parentBacking).getDiskMode());
            backingInfo.setDatastore(morDs);
            backingInfo.setFileName(vmdkDatastorePath);
            backingInfo.setParent((VirtualDiskSparseVer1BackingInfo)parentBacking);
            disk.setBacking(backingInfo);
        } else if (parentBacking instanceof VirtualDiskSparseVer2BackingInfo) {
            VirtualDiskSparseVer2BackingInfo backingInfo = new VirtualDiskSparseVer2BackingInfo();
            backingInfo.setDiskMode(((VirtualDiskSparseVer2BackingInfo)parentBacking).getDiskMode());
            backingInfo.setDatastore(morDs);
            backingInfo.setFileName(vmdkDatastorePath);
            backingInfo.setParent((VirtualDiskSparseVer2BackingInfo)parentBacking);
            disk.setBacking(backingInfo);
        } else {
            throw new Exception("Unsupported disk backing: " + parentBacking.getClass().getCanonicalName());
        }

        int ideControllerKey = vmMo.getIDEDeviceControllerKey();
        if (controllerKey < 0)
            controllerKey = ideControllerKey;
        disk.setControllerKey(controllerKey);
        if (deviceNumber < 0) {
            deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
            if (controllerKey != ideControllerKey && isReservedScsiDeviceNumber(deviceNumber))
                deviceNumber++;
        }

        disk.setKey(-contextNumber);
        disk.setUnitNumber(deviceNumber);
        disk.setCapacityInKB(sizeInMb * 1024);

        VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
        connectInfo.setConnected(true);
        connectInfo.setStartConnected(true);
        disk.setConnectable(connectInfo);
        return disk;
    }
View Full Code Here

            ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {

        assert (vmdkDatastorePathChain != null);
        assert (vmdkDatastorePathChain.length >= 1);

        VirtualDisk disk;
        VirtualDiskFlatVer2BackingInfo backingInfo;
        if (device != null) {
            disk = device;
            backingInfo = (VirtualDiskFlatVer2BackingInfo)disk.getBacking();
        } else {
            disk = new VirtualDisk();
            backingInfo = new VirtualDiskFlatVer2BackingInfo();
            backingInfo.setDatastore(morDs);
            backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
            disk.setBacking(backingInfo);

            int ideControllerKey = vmMo.getIDEDeviceControllerKey();
            if (controllerKey < 0)
                controllerKey = ideControllerKey;
            if (deviceNumber < 0) {
                deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
                if (controllerKey != ideControllerKey && isReservedScsiDeviceNumber(deviceNumber))
                    deviceNumber++;
            }

            disk.setControllerKey(controllerKey);
            disk.setKey(-contextNumber);
            disk.setUnitNumber(deviceNumber);

            VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
            connectInfo.setConnected(true);
            connectInfo.setStartConnected(true);
            disk.setConnectable(connectInfo);
        }

        backingInfo.setFileName(vmdkDatastorePathChain[0]);
        if (vmdkDatastorePathChain.length > 1) {
            String[] parentDisks = new String[vmdkDatastorePathChain.length - 1];
View Full Code Here

            int deviceNumber, int contextNumber) throws Exception {

        assert (vmdkDatastorePathChain != null);
        assert (vmdkDatastorePathChain.length >= 1);

        VirtualDisk disk = new VirtualDisk();

        VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
        backingInfo.setDatastore(vmdkDatastorePathChain[0].second());
        backingInfo.setFileName(vmdkDatastorePathChain[0].first());
        backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
        if (vmdkDatastorePathChain.length > 1) {
            Pair<String, ManagedObjectReference>[] parentDisks = new Pair[vmdkDatastorePathChain.length - 1];
            for (int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
                parentDisks[i] = vmdkDatastorePathChain[i + 1];

            setParentBackingInfo(backingInfo, parentDisks);
        }

        disk.setBacking(backingInfo);

        int ideControllerKey = vmMo.getIDEDeviceControllerKey();
        if (controllerKey < 0)
            controllerKey = ideControllerKey;
        if (deviceNumber < 0) {
            deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
            if (controllerKey != ideControllerKey && isReservedScsiDeviceNumber(deviceNumber))
                deviceNumber++;
        }

        disk.setControllerKey(controllerKey);
        disk.setKey(-contextNumber);
        disk.setUnitNumber(deviceNumber);

        VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
        connectInfo.setConnected(true);
        connectInfo.setStartConnected(true);
        disk.setConnectable(connectInfo);

        return disk;
    }
View Full Code Here

        int ideControllerKey = getIDEDeviceControllerKey();
        if (controllerKey < 0) {
            controllerKey = ideControllerKey;
        }

        VirtualDisk newDisk = new VirtualDisk();
        if (diskType == VirtualDiskType.THIN || diskType == VirtualDiskType.PREALLOCATED || diskType == VirtualDiskType.EAGER_ZEROED_THICK) {

            VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
            backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
            if (diskType == VirtualDiskType.THIN) {
                backingInfo.setThinProvisioned(true);
            } else {
                backingInfo.setThinProvisioned(false);
            }

            if (diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
                backingInfo.setEagerlyScrub(true);
            } else {
                backingInfo.setEagerlyScrub(false);
            }

            backingInfo.setDatastore(morDs);
            backingInfo.setFileName(vmdkDatastorePath);
            newDisk.setBacking(backingInfo);
        } else if (diskType == VirtualDiskType.RDM || diskType == VirtualDiskType.RDMP) {
            VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
            if (diskType == VirtualDiskType.RDM) {
                backingInfo.setCompatibilityMode("virtualMode");
            } else {
                backingInfo.setCompatibilityMode("physicalMode");
            }
            backingInfo.setDeviceName(rdmDeviceName);
            if (diskType == VirtualDiskType.RDM) {
                backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
            }

            backingInfo.setDatastore(morDs);
            backingInfo.setFileName(vmdkDatastorePath);
            newDisk.setBacking(backingInfo);
        }

        int deviceNumber = getNextDeviceNumber(controllerKey);
        if (controllerKey != ideControllerKey && VmwareHelper.isReservedScsiDeviceNumber(deviceNumber))
            deviceNumber++;

        newDisk.setControllerKey(controllerKey);
        newDisk.setKey(-deviceNumber);
        newDisk.setUnitNumber(deviceNumber);
        newDisk.setCapacityInKB(sizeInMb * 1024);

        VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();

        deviceConfigSpec.setDevice(newDisk);
View Full Code Here

    }

    public VirtualDisk getDiskDeviceByBusName(List<VirtualDevice> allDevices, String busName) throws Exception {
        for (VirtualDevice device : allDevices) {
            if (device instanceof VirtualDisk) {
                VirtualDisk disk = (VirtualDisk)device;
                String diskBusName = getDeviceBusName(allDevices, disk);
                if (busName.equalsIgnoreCase(diskBusName))
                    return disk;
            }
        }
View Full Code Here

TOP

Related Classes of com.vmware.vim25.VirtualDisk

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.