Search in sources :

Example 1 with VmfsDatastoreOption

use of com.vmware.vim25.VmfsDatastoreOption in project coprhd-controller by CoprHD.

the class VcenterApiClient method createDatastore.

public String createDatastore(String datacenterName, String clusterNameOrMoRef, String hostname, String volumeUuid, String datastoreName) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
    try {
        _log.info("Request to create datastore on volume " + volumeUuid + " host " + hostname + " to datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
        HostSystem hostSystem = (HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostname, true).get("HostSystem");
        if (volumeUuid == null || volumeUuid.trim().equals("")) {
            _log.error("Volume UUID not specified");
            throw new VcenterSystemException("Volume UUID not specified");
        }
        Datastore[] datastores = hostSystem.getDatastores();
        if (datastores != null && datastores.length > 0) {
            _log.info("Check host " + hostname + " for existing datastore on volume " + volumeUuid);
            String specifiedVolumeDevicePath = null;
            HostStorageSystem hostStorageSystem = hostSystem.getHostStorageSystem();
            HostStorageDeviceInfo hostStorageDeviceInfo = hostStorageSystem.getStorageDeviceInfo();
            ScsiLun[] hostScsiLuns = hostStorageDeviceInfo.getScsiLun();
            for (ScsiLun scsiLun : hostScsiLuns) {
                if (scsiLun instanceof HostScsiDisk) {
                    HostScsiDisk hostScsiDisk = (HostScsiDisk) scsiLun;
                    if (hostScsiDisk.getUuid().toLowerCase().contains(volumeUuid.toLowerCase())) {
                        _log.info("Found disk " + hostScsiDisk.getUuid() + " on " + hostname + " for volume UUID " + volumeUuid);
                        specifiedVolumeDevicePath = hostScsiDisk.getDevicePath();
                        break;
                    }
                }
            }
            // datastore already exists.
            if (specifiedVolumeDevicePath != null) {
                for (Datastore datastore : datastores) {
                    if (datastore.getInfo() instanceof VmfsDatastoreInfo) {
                        VmfsDatastoreInfo vmfsDatastoreInfo = (VmfsDatastoreInfo) datastore.getInfo();
                        _log.info("Found datastore " + vmfsDatastoreInfo.getName() + " " + vmfsDatastoreInfo.getVmfs().getUuid());
                        String diskName = vmfsDatastoreInfo.getVmfs().getExtent()[0].getDiskName();
                        _log.info("Found datastore " + vmfsDatastoreInfo.getName() + " on disk " + diskName);
                        String devicePath = "/vmfs/devices/disks/" + diskName;
                        if (devicePath.equalsIgnoreCase(specifiedVolumeDevicePath)) {
                            _log.info("Datastore " + vmfsDatastoreInfo.getName() + " " + devicePath + " " + datastore.getMOR().getVal() + " already present");
                            return datastore.getMOR().getVal();
                        }
                    }
                }
            }
        }
        _log.info("Search for candidate disk via host " + hostname);
        HostDatastoreSystem hostDatastoreSystem = hostSystem.getHostDatastoreSystem();
        HostScsiDisk[] hostScsiDisks = hostDatastoreSystem.queryAvailableDisksForVmfs(null);
        HostScsiDisk candidateHostScsiDisk = null;
        for (HostScsiDisk hostScsiDisk : hostScsiDisks) {
            _log.info("Found disk " + hostScsiDisk.getDevicePath() + " " + hostScsiDisk.getUuid());
            if (hostScsiDisk.getUuid().toLowerCase().contains(volumeUuid.toLowerCase())) {
                candidateHostScsiDisk = hostScsiDisk;
                break;
            }
        }
        if (candidateHostScsiDisk == null) {
            _log.error("Disk " + volumeUuid + " not found - Ensure underlying storage properly configured and disk accessible to host");
            throw new VcenterSystemException("Disk " + volumeUuid + " not found - Ensure underlying storage properly configured and disk accessible to host");
        }
        String devicePath = candidateHostScsiDisk.getDevicePath();
        _log.info("Create datastore via host " + hostname + " on disk " + devicePath);
        VmfsDatastoreOption[] vmfsDatastoreOption = hostDatastoreSystem.queryVmfsDatastoreCreateOptions(devicePath);
        VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec = (VmfsDatastoreCreateSpec) vmfsDatastoreOption[0].getSpec();
        vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);
        // TODO externalize
        vmfsDatastoreCreateSpec.getVmfs().setBlockSizeMb(1);
        Datastore datastore = null;
        try {
            datastore = hostDatastoreSystem.createVmfsDatastore(vmfsDatastoreCreateSpec);
        } catch (HostConfigFault hcf) {
            _log.info("HostConfigFault creating datastore on disk " + devicePath + " thus retry");
            if (hcf.getFaultMessage() != null && hcf.getFaultMessage().length > 0 && hcf.getFaultMessage()[0] != null) {
                String errorMessage = hcf.getFaultMessage()[0].toString();
                _log.error("HostConfigFault details are " + errorMessage);
            }
            datastore = hostDatastoreSystem.createVmfsDatastore(vmfsDatastoreCreateSpec);
        }
        if (datastore == null) {
            // Should not happen
            _log.error("Datastore null after create");
            throw new VcenterSystemException("Error creating datastore");
        }
        return datastore.getMOR().getVal();
    } catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("Exception creating datastore: " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : VmfsDatastoreInfo(com.vmware.vim25.VmfsDatastoreInfo) VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption) VmfsDatastoreCreateSpec(com.vmware.vim25.VmfsDatastoreCreateSpec) ScsiLun(com.vmware.vim25.ScsiLun) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) HostStorageSystem(com.vmware.vim25.mo.HostStorageSystem) HostStorageDeviceInfo(com.vmware.vim25.HostStorageDeviceInfo) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) Datastore(com.vmware.vim25.mo.Datastore) HostSystem(com.vmware.vim25.mo.HostSystem) HostScsiDisk(com.vmware.vim25.HostScsiDisk) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) HostDatastoreSystem(com.vmware.vim25.mo.HostDatastoreSystem) HostConfigFault(com.vmware.vim25.HostConfigFault)

Example 2 with VmfsDatastoreOption

use of com.vmware.vim25.VmfsDatastoreOption in project coprhd-controller by CoprHD.

the class HostStorageAPI method pickBestExpandSpec.

/**
 * Picks the best expand spec. This picks an expand spec that uses the given disk.
 *
 * @param disk the disk that was expanded.
 * @param expandOptions the available expand options.
 * @return the expand spec.
 */
public VmfsDatastoreExpandSpec pickBestExpandSpec(HostScsiDisk disk, List<VmfsDatastoreOption> expandOptions) {
    if ((expandOptions == null) || expandOptions.isEmpty()) {
        return null;
    }
    for (VmfsDatastoreOption option : expandOptions) {
        VmfsDatastoreExpandSpec spec = (VmfsDatastoreExpandSpec) option.getSpec();
        String diskName = spec.getExtent().getDiskName();
        if (StringUtils.equals(diskName, disk.getCanonicalName())) {
            return spec;
        }
    }
    return null;
}
Also used : VmfsDatastoreExpandSpec(com.vmware.vim25.VmfsDatastoreExpandSpec) VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption)

Example 3 with VmfsDatastoreOption

use of com.vmware.vim25.VmfsDatastoreOption in project cloudstack by apache.

the class HostDatastoreSystemMO method createVmfsDatastore.

public ManagedObjectReference createVmfsDatastore(String datastoreName, HostScsiDisk hostScsiDisk) throws Exception {
    // just grab the first instance of VmfsDatastoreOption
    VmfsDatastoreOption vmfsDatastoreOption = _context.getService().queryVmfsDatastoreCreateOptions(_mor, hostScsiDisk.getDevicePath(), 5).get(0);
    VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec = (VmfsDatastoreCreateSpec) vmfsDatastoreOption.getSpec();
    // set the name of the datastore to be created
    vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);
    return _context.getService().createVmfsDatastore(_mor, vmfsDatastoreCreateSpec);
}
Also used : VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption) VmfsDatastoreCreateSpec(com.vmware.vim25.VmfsDatastoreCreateSpec)

Example 4 with VmfsDatastoreOption

use of com.vmware.vim25.VmfsDatastoreOption in project coprhd-controller by CoprHD.

the class HostStorageAPI method pickBestCreateSpec.

/**
 * Picks the best create spec from the list of datastore options.
 *
 * @param createOptions the list of create options.
 * @return the best datastore create spec.
 */
public VmfsDatastoreCreateSpec pickBestCreateSpec(List<VmfsDatastoreOption> createOptions) {
    if ((createOptions == null) || createOptions.isEmpty()) {
        return null;
    }
    VmfsDatastoreCreateSpec bestSpec = (VmfsDatastoreCreateSpec) createOptions.get(0).getSpec();
    // Choose the create spec that uses the most recent VMFS version
    for (int i = 1; i < createOptions.size(); i++) {
        VmfsDatastoreOption createOption = createOptions.get(i);
        VmfsDatastoreCreateSpec currentSpec = (VmfsDatastoreCreateSpec) createOption.getSpec();
        if (currentSpec.getVmfs().getMajorVersion() > bestSpec.getVmfs().getMajorVersion()) {
            bestSpec = currentSpec;
        }
    }
    return bestSpec;
}
Also used : VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption) VmfsDatastoreCreateSpec(com.vmware.vim25.VmfsDatastoreCreateSpec)

Example 5 with VmfsDatastoreOption

use of com.vmware.vim25.VmfsDatastoreOption in project coprhd-controller by CoprHD.

the class HostStorageAPI method getVmfsDatastoreCreateSpec.

/**
 * Gets a VMFS datastore create spec for the given disk and datastore name.
 *
 * @param disk the disk.
 * @param datastoreName the datastore name.
 * @return the VMFS datastore create spec.
 */
public VmfsDatastoreCreateSpec getVmfsDatastoreCreateSpec(HostScsiDisk disk, String datastoreName) {
    List<VmfsDatastoreOption> createOptions = queryVmfsDatastoreCreateOptions(disk);
    VmfsDatastoreCreateSpec createSpec = pickBestCreateSpec(createOptions);
    if (createSpec == null) {
        throw new VMWareException("No VMFS datastore create spec. Volume may already contain a datastore.");
    }
    createSpec.getVmfs().setVolumeName(datastoreName);
    return createSpec;
}
Also used : VmfsDatastoreOption(com.vmware.vim25.VmfsDatastoreOption) VmfsDatastoreCreateSpec(com.vmware.vim25.VmfsDatastoreCreateSpec)

Aggregations

VmfsDatastoreOption (com.vmware.vim25.VmfsDatastoreOption)8 VmfsDatastoreCreateSpec (com.vmware.vim25.VmfsDatastoreCreateSpec)4 VmfsDatastoreExpandSpec (com.vmware.vim25.VmfsDatastoreExpandSpec)3 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)1 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)1 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)1 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)1 HostConfigFault (com.vmware.vim25.HostConfigFault)1 HostScsiDisk (com.vmware.vim25.HostScsiDisk)1 HostStorageDeviceInfo (com.vmware.vim25.HostStorageDeviceInfo)1 ScsiLun (com.vmware.vim25.ScsiLun)1 VmfsDatastoreExtendSpec (com.vmware.vim25.VmfsDatastoreExtendSpec)1 VmfsDatastoreInfo (com.vmware.vim25.VmfsDatastoreInfo)1 Datastore (com.vmware.vim25.mo.Datastore)1 HostDatastoreSystem (com.vmware.vim25.mo.HostDatastoreSystem)1 HostStorageSystem (com.vmware.vim25.mo.HostStorageSystem)1 HostSystem (com.vmware.vim25.mo.HostSystem)1