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());
}
}
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));
}
}
Aggregations