Search in sources :

Example 1 with HostUnresolvedVmfsExtent

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

the class VmwareStorageProcessor method getExtentsMatching.

private List<HostUnresolvedVmfsExtent> getExtentsMatching(List<HostUnresolvedVmfsExtent> extents, String naa) {
    List<HostUnresolvedVmfsExtent> matchingExtents = new ArrayList<>();
    if (extents != null) {
        for (HostUnresolvedVmfsExtent extent : extents) {
            s_logger.debug(String.format("HostUnresolvedVmfsExtent details: [devicePath: %s, ordinal: %s, reason: %s, isHeadExtent: %s].", extent.getDevicePath(), extent.getOrdinal(), extent.getReason(), extent.isIsHeadExtent()));
            String extentDevicePath = extent.getDevicePath();
            if (extentDevicePath.contains(naa)) {
                matchingExtents.add(extent);
            }
        }
    }
    return matchingExtents;
}
Also used : HostUnresolvedVmfsExtent(com.vmware.vim25.HostUnresolvedVmfsExtent) ArrayList(java.util.ArrayList)

Example 2 with HostUnresolvedVmfsExtent

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

the class VmwareStorageProcessor method resignature.

@Override
public ResignatureAnswer resignature(ResignatureCommand cmd) {
    final Map<String, String> details = cmd.getDetails();
    String scsiNaaDeviceId = details.get(DiskTO.SCSI_NAA_DEVICE_ID);
    if (scsiNaaDeviceId == null || scsiNaaDeviceId.trim().length() == 0) {
        throw new CloudRuntimeException("The 'scsiNaaDeviceId' needs to be specified when resignaturing a VMware datastore.");
    }
    final String iScsiName = details.get(DiskTO.IQN);
    final String datastoreName = getMaximumDatastoreName(VmwareResource.getDatastoreName(iScsiName));
    String vmdk = null;
    try {
        VmwareContext context = hostService.getServiceContext(null);
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
        ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
        ClusterMO clusterMO = new ClusterMO(context, morCluster);
        List<Pair<ManagedObjectReference, String>> lstHosts = clusterMO.getClusterHosts();
        // add iSCSI connection to host
        final String storageHost = details.get(DiskTO.STORAGE_HOST);
        final int storagePortNumber = Integer.parseInt(details.get(DiskTO.STORAGE_PORT));
        final String chapInitiatorUsername = details.get(DiskTO.CHAP_INITIATOR_USERNAME);
        final String chapInitiatorSecret = details.get(DiskTO.CHAP_INITIATOR_SECRET);
        final String chapTargetUsername = details.get(DiskTO.CHAP_TARGET_USERNAME);
        final String chapTargetSecret = details.get(DiskTO.CHAP_TARGET_SECRET);
        HostDiscoveryMethod hostDiscoveryMethod = getHostDiscoveryMethod(context, storageHost, lstHosts);
        List<HostMO> hostsUsingStaticDiscovery = hostDiscoveryMethod.getHostsUsingStaticDiscovery();
        if (hostsUsingStaticDiscovery != null && hostsUsingStaticDiscovery.size() > 0) {
            List<HostInternetScsiHbaStaticTarget> lstTargets = getTargets(storageHost, storagePortNumber, trimIqn(iScsiName), chapInitiatorUsername, chapInitiatorSecret, chapTargetUsername, chapTargetSecret);
            addRemoveInternetScsiTargetsToAllHosts(true, lstTargets, hostsUsingStaticDiscovery);
        }
        rescanAllHosts(context, lstHosts, true, true);
        // perform resignature operation
        HostMO hostMO = new HostMO(context, lstHosts.get(0).first());
        HostDatastoreSystemMO hostDatastoreSystem = hostMO.getHostDatastoreSystemMO();
        List<HostUnresolvedVmfsVolume> hostUnresolvedVmfsVolumes = hostDatastoreSystem.queryUnresolvedVmfsVolumes();
        if (hostUnresolvedVmfsVolumes == null || hostUnresolvedVmfsVolumes.size() == 0) {
            throw new CloudRuntimeException("Unable to locate any snapshot datastores");
        }
        boolean foundExtent = false;
        for (HostUnresolvedVmfsVolume hostUnresolvedVmfsVolume : hostUnresolvedVmfsVolumes) {
            List<HostUnresolvedVmfsExtent> extents = hostUnresolvedVmfsVolume.getExtent();
            List<HostUnresolvedVmfsExtent> matchingExtents = getExtentsMatching(extents, scsiNaaDeviceId);
            if (matchingExtents.size() >= 1) {
                String extentDevicePath = matchingExtents.get(0).getDevicePath();
                HostResignatureRescanResult hostResignatureRescanResult = resignatureDatastore(hostDatastoreSystem, extentDevicePath);
                if (hostResignatureRescanResult == null) {
                    throw new CloudRuntimeException("'hostResignatureRescanResult' should not be 'null'.");
                }
                ManagedObjectReference morDs = hostResignatureRescanResult.getResult();
                if (morDs == null) {
                    throw new CloudRuntimeException("'morDs' should not be 'null'.");
                }
                DatastoreMO datastoreMO = new DatastoreMO(context, morDs);
                boolean isOnlyForTemplate = Boolean.parseBoolean(details.get(DiskTO.TEMPLATE_RESIGN));
                // then rename the datastore.
                if (isOnlyForTemplate) {
                    vmdk = details.get(DiskTO.VMDK);
                } else {
                    vmdk = cleanUpDatastore(cmd, hostDatastoreSystem, datastoreMO, details);
                }
                if (renameDatastore(context, morDs, datastoreName, lstHosts)) {
                    foundExtent = true;
                    break;
                }
            }
        }
        removeVmfsDatastore(cmd, hyperHost, datastoreName, storageHost, storagePortNumber, trimIqn(iScsiName), lstHosts);
        if (!foundExtent) {
            throw new CloudRuntimeException("Unable to locate the applicable extent");
        }
        final ResignatureAnswer answer = new ResignatureAnswer();
        final long volumeSize = Long.parseLong(details.get(DiskTO.VOLUME_SIZE));
        answer.setSize(volumeSize);
        answer.setPath("[" + datastoreName + "] " + vmdk);
        answer.setFormat(ImageFormat.OVA);
        return answer;
    } catch (Exception ex) {
        s_logger.error(String.format("Command %s failed due to: [%s].", cmd.getClass().getSimpleName(), ex.getMessage()), ex);
        throw new CloudRuntimeException(ex.getMessage());
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostUnresolvedVmfsVolume(com.vmware.vim25.HostUnresolvedVmfsVolume) HostDatastoreSystemMO(com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Pair(com.cloud.utils.Pair) HostInternetScsiHbaStaticTarget(com.vmware.vim25.HostInternetScsiHbaStaticTarget) HostResignatureRescanResult(com.vmware.vim25.HostResignatureRescanResult) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) HostUnresolvedVmfsExtent(com.vmware.vim25.HostUnresolvedVmfsExtent) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

HostUnresolvedVmfsExtent (com.vmware.vim25.HostUnresolvedVmfsExtent)2 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 HostDatastoreSystemMO (com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO)1 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 Pair (com.cloud.utils.Pair)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 HostInternetScsiHbaStaticTarget (com.vmware.vim25.HostInternetScsiHbaStaticTarget)1 HostResignatureRescanResult (com.vmware.vim25.HostResignatureRescanResult)1 HostUnresolvedVmfsVolume (com.vmware.vim25.HostUnresolvedVmfsVolume)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 ResignatureAnswer (org.apache.cloudstack.storage.command.ResignatureAnswer)1