Search in sources :

Example 1 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem in project cloudstack by apache.

the class VmwareStorageProcessor method addRemoveInternetScsiTargetsToAllHosts.

private void addRemoveInternetScsiTargetsToAllHosts(final boolean add, final List<HostInternetScsiHbaStaticTarget> targets, List<HostMO> hosts) throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(hosts.size());
    final List<Exception> exceptions = new ArrayList<Exception>();
    for (HostMO host : hosts) {
        HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
        boolean iScsiHbaConfigured = false;
        for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
            if (hba instanceof HostInternetScsiHba) {
                // just finding an instance of HostInternetScsiHba means that we have found at least one configured iSCSI HBA
                // at least one iSCSI HBA must be configured before a CloudStack user can use this host for iSCSI storage
                iScsiHbaConfigured = true;
                final String iScsiHbaDevice = hba.getDevice();
                final HostStorageSystemMO hss = hostStorageSystem;
                executorService.submit(new Thread() {

                    @Override
                    public void run() {
                        try {
                            if (add) {
                                hss.addInternetScsiStaticTargets(iScsiHbaDevice, targets);
                            } else {
                                hss.removeInternetScsiStaticTargets(iScsiHbaDevice, targets);
                            }
                            hss.rescanHba(iScsiHbaDevice);
                            hss.rescanVmfs();
                        } catch (Exception ex) {
                            synchronized (exceptions) {
                                exceptions.add(ex);
                            }
                        }
                    }
                });
            }
        }
        if (!iScsiHbaConfigured) {
            throw new Exception("An iSCSI HBA must be configured before a host can use iSCSI storage.");
        }
    }
    executorService.shutdown();
    if (!executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) {
        throw new Exception("The system timed out before completing the task 'rescanAllHosts'.");
    }
    if (exceptions.size() > 0) {
        throw new Exception(exceptions.get(0).getMessage());
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHba(com.vmware.vim25.HostInternetScsiHba) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) HostHostBusAdapter(com.vmware.vim25.HostHostBusAdapter) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 2 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem in project cloudstack by apache.

the class VmwareResource method getIqn.

private String getIqn() {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        if (hyperHost instanceof HostMO) {
            HostMO host = (HostMO) hyperHost;
            HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
            for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
                if (hba instanceof HostInternetScsiHba) {
                    return ((HostInternetScsiHba) hba).getIScsiName();
                }
            }
        }
    } catch (Exception ex) {
        s_logger.info("Could not locate an IQN for this host.");
    }
    return null;
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHba(com.vmware.vim25.HostInternetScsiHba) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) HostHostBusAdapter(com.vmware.vim25.HostHostBusAdapter) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 3 with HostStorageSystem

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

the class VcenterApiClient method checkVMsOnHostVolume.

/**
 * Verifies if the host can see the volume, if so then check for VMs (powered on/off)
 * on the datastore identified for the given volume wwn.
 *
 * @param datacenterName {@link String} name of the dataCenter
 * @param clusterNameOrMoRef {@link String} name of the cluster
 * @param hostName {@link String} name of the host
 * @param volumewwn {@link String} volume wwn
 * @return true when there are any VMs on the datastore identified by the volume wwn, otherwise false
 * @throws VcenterSystemException
 * @throws VcenterObjectNotFoundException
 * @throws VcenterObjectConnectionException
 */
public boolean checkVMsOnHostVolume(String datacenterName, String clusterNameOrMoRef, String hostName, String volumewwn) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
    boolean isVMsPresent = false;
    try {
        _log.info("Request to check VMs on volume " + volumewwn + " host " + hostName + " to datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
        HostSystem hostSystem = (HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostName, false).get("HostSystem");
        if (volumewwn == null || volumewwn.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("Found {} datastores for host {}", datastores.length, hostName);
            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;
                    // Check if host is able to see the specified volume
                    if (hostScsiDisk.getUuid().toLowerCase().contains(volumewwn.toLowerCase())) {
                        _log.info("Found disk " + hostScsiDisk.getUuid() + " on " + hostName + " for volume UUID " + volumewwn);
                        specifiedVolumeDevicePath = hostScsiDisk.getDevicePath();
                        break;
                    }
                }
            }
            if (specifiedVolumeDevicePath != null) {
                Datastore bootVolDatastore = null;
                for (Datastore datastore : datastores) {
                    _log.info("Find existing datastore on volume " + volumewwn + " for host " + hostName);
                    if (datastore.getInfo() instanceof VmfsDatastoreInfo) {
                        VmfsDatastoreInfo vmfsDatastoreInfo = (VmfsDatastoreInfo) datastore.getInfo();
                        String diskName = vmfsDatastoreInfo.getVmfs().getExtent()[0].getDiskName();
                        if (specifiedVolumeDevicePath.contains(diskName) && diskName.contains(volumewwn.toLowerCase())) {
                            _log.info("Found datastore " + vmfsDatastoreInfo.getName() + " on disk " + diskName);
                            bootVolDatastore = datastore;
                            break;
                        }
                    }
                }
                if (bootVolDatastore != null) {
                    if (CollectionUtils.isNotEmpty(Arrays.asList(bootVolDatastore.getVms()))) {
                        isVMsPresent = true;
                        _log.info("Found {} VMs on the datastore {}", bootVolDatastore.getVms().length, bootVolDatastore.getName());
                    } else {
                        _log.info("No VMs found on datastore {}", bootVolDatastore.getName());
                    }
                } else {
                    _log.warn("Could not find datastore for host {} on volume wwn {}", hostName, volumewwn);
                }
            } else {
                _log.warn("Could not find disk on host {} for volume UUID {}", hostName, volumewwn);
            }
        } else {
            _log.info("No datastores found for host {}, hence inferring that no VMs are present on the given volume wwn {}", hostName, volumewwn);
        }
    } catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
        _log.error("Vcenter exception checkVMsOnHostVolume : {}", e);
        throw e;
    } catch (Exception e) {
        _log.error("Exception checkVMsOnHostVolume : {}", e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
    return isVMsPresent;
}
Also used : VmfsDatastoreInfo(com.vmware.vim25.VmfsDatastoreInfo) 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)

Example 4 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem 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 5 with HostStorageSystem

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

the class HostStorageAPI method setMultipathPolicy.

/**
 * Sets the multipath policy on the given lun
 *
 * @param lun the lun to set the policy on
 * @param multipathPolicy name of the multipath policy
 */
public void setMultipathPolicy(HostScsiDisk lun, String multipathPolicy) {
    try {
        HostStorageSystem storageSystem = getStorageSystem();
        HostMultipathInfoLogicalUnitPolicy policy = createMultipathPolicy(multipathPolicy);
        storageSystem.setMultipathLunPolicy(lun.getUuid(), policy);
    } catch (HostConfigFault e) {
        throw new VMWareException(e);
    } catch (NotFound e) {
        throw new VMWareException(e);
    } catch (RuntimeFault e) {
        throw new VMWareException(e);
    } catch (RemoteException e) {
        throw new VMWareException(e);
    }
}
Also used : HostStorageSystem(com.vmware.vim25.mo.HostStorageSystem) HostMultipathInfoLogicalUnitPolicy(com.vmware.vim25.HostMultipathInfoLogicalUnitPolicy) RuntimeFault(com.vmware.vim25.RuntimeFault) RemoteException(java.rmi.RemoteException) HostConfigFault(com.vmware.vim25.HostConfigFault) NotFound(com.vmware.vim25.NotFound)

Aggregations

RemoteException (java.rmi.RemoteException)10 HostStorageSystem (com.vmware.vim25.mo.HostStorageSystem)8 HostConfigFault (com.vmware.vim25.HostConfigFault)7 RuntimeFault (com.vmware.vim25.RuntimeFault)6 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)5 HostStorageSystemMO (com.cloud.hypervisor.vmware.mo.HostStorageSystemMO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 HostHostBusAdapter (com.vmware.vim25.HostHostBusAdapter)4 HostInternetScsiHba (com.vmware.vim25.HostInternetScsiHba)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ArrayList (java.util.ArrayList)4 HostScsiDisk (com.vmware.vim25.HostScsiDisk)3 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)2 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)2 Pair (com.cloud.utils.Pair)2 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)2 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)2 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)2 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)2