Search in sources :

Example 1 with HostResignatureRescanResult

use of com.vmware.vim25.HostResignatureRescanResult 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)

Example 2 with HostResignatureRescanResult

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

the class HostDatastoreSystemMO method resignatureUnresolvedVmfsVolume.

public HostResignatureRescanResult resignatureUnresolvedVmfsVolume(HostUnresolvedVmfsResignatureSpec resolutionSpec) throws Exception {
    ManagedObjectReference task = _context.getService().resignatureUnresolvedVmfsVolumeTask(_mor, resolutionSpec);
    boolean result = _context.getVimClient().waitForTask(task);
    if (result) {
        _context.waitForTaskProgressDone(task);
        TaskMO taskMO = new TaskMO(_context, task);
        return (HostResignatureRescanResult) taskMO.getTaskInfo().getResult();
    } else {
        throw new Exception("Unable to register vm due to " + TaskMO.getTaskFailureInfo(_context, task));
    }
}
Also used : HostResignatureRescanResult(com.vmware.vim25.HostResignatureRescanResult) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

HostResignatureRescanResult (com.vmware.vim25.HostResignatureRescanResult)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)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 HostUnresolvedVmfsExtent (com.vmware.vim25.HostUnresolvedVmfsExtent)1 HostUnresolvedVmfsVolume (com.vmware.vim25.HostUnresolvedVmfsVolume)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 RemoteException (java.rmi.RemoteException)1 ResignatureAnswer (org.apache.cloudstack.storage.command.ResignatureAnswer)1