use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method rescanHostStorage.
/**
* Rescans HBAs and storage system for an ESX host
*
* @param hostId the host id
* @param vCenterId the vcenter id
* @param vcenterDatacenter the vcenter datacenter id
* @param stepId the workflow step
*/
public void rescanHostStorage(URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
Host esxHost = _dbClient.queryObject(Host.class, hostId);
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
if (hostSystem == null) {
_log.info("Not able to find host {} in vCenter. Unable to refresh HBAs", esxHost.getLabel());
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
storageAPI.refreshStorage();
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method attachAndMount.
/**
* Attaches and mounts every disk and datastore associated with the volumes in the export group.
* For each volume in the export group, the associated disk is attached to the host and any datastores backed by the
* volume are mounted
* to the host.
*
* @param exportGroupId
* export group that contains volumes
* @param hostId
* host to attach and mount to
* @param vcenterId
* vcenter that the host belongs to
* @param vcenterDatacenter
* vcenter datacenter that the host belongs to
* @param stepId
* the id of the workflow step
*/
public void attachAndMount(URI exportGroupId, URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_054);
Host esxHost = _dbClient.queryObject(Host.class, hostId);
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
if (hostSystem == null) {
_log.info("Not able to find host " + esxHost.getLabel() + " in vCenter. Unable to attach disks and mount datastores");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
if (exportGroup != null && exportGroup.getVolumes() != null) {
_log.info("Refreshing storage");
storageAPI.refreshStorage();
Set<BlockObject> blockObjects = Sets.newHashSet();
for (String volume : exportGroup.getVolumes().keySet()) {
BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
blockObjects.add(blockObject);
for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
if (VMwareUtils.isDiskOff(entry)) {
_log.info("Attach SCSI Lun " + entry.getCanonicalName() + " on host " + esxHost.getLabel());
storageAPI.attachScsiLun(entry);
}
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_055);
break;
}
}
}
int retries = 0;
while (retries++ < MAXIMUM_RESCAN_ATTEMPTS && !blockObjects.isEmpty()) {
_log.info("Rescanning VMFS for host " + esxHost.getLabel());
storageAPI.getStorageSystem().rescanVmfs();
_log.info("Waiting for {} milliseconds before checking for datastores", RESCAN_DELAY_MS);
Thread.sleep(RESCAN_DELAY_MS);
_log.info("Looking for datastores for {} volumes", blockObjects.size());
Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
Iterator<BlockObject> objectIterator = blockObjects.iterator();
while (objectIterator.hasNext()) {
BlockObject blockObject = objectIterator.next();
if (blockObject != null) {
Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
if (datastore != null && VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
_log.info("Datastore {} is already mounted on {}", datastore.getName(), esxHost.getLabel());
objectIterator.remove();
} else if (datastore != null && !VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
_log.info("Mounting datastore {} on host {}", datastore.getName(), esxHost.getLabel());
storageAPI.mountDatastore(datastore);
objectIterator.remove();
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_056);
}
}
}
}
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method getWwnDatastoreMap.
/**
* Gets a map of volume wwn to datastore for all datastores that the host has access to
*
* @param host the host
* @return map of volume wwn to datastore
* @throws InvalidProperty
* @throws RuntimeFault
* @throws RemoteException
*/
public Map<String, Datastore> getWwnDatastoreMap(HostSystem host) throws InvalidProperty, RuntimeFault, RemoteException {
Map<String, Datastore> result = Maps.newHashMap();
HostStorageAPI hostApi = new HostStorageAPI(host);
for (Datastore datastore : host.getDatastores()) {
if (datastore.getInfo() instanceof VmfsDatastoreInfo) {
Collection<HostScsiDisk> disks = hostApi.getDisksByPartition(datastore).values();
for (HostScsiDisk disk : disks) {
result.put(VMwareUtils.getDiskWwn(disk), datastore);
}
}
}
return result;
}
use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.
the class EsxHostDiscoveryAdapter method getHostBusAdapters.
/**
* Fetch {@link HostHostBusAdapter} corresponding the {@link HostSystem}
*
* @param host
* {@link HostSystem}
* @return
*/
protected List<HostHostBusAdapter> getHostBusAdapters(HostSystem host) {
List<HostHostBusAdapter> hostBusAdapters = Lists.newArrayList();
HostStorageAPI storageAPI = new HostStorageAPI(host);
for (HostHostBusAdapter hba : storageAPI.listHostBusAdapters()) {
hostBusAdapters.add(hba);
}
return hostBusAdapters;
}
use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.
the class AddInternetScsiTargets method execute.
@Override
public void execute() throws Exception {
HostStorageAPI hostStorageAPI = new HostStorageAPI(host);
for (String iqn : hbas.keySet()) {
HostHostBusAdapter hba = hbas.get(iqn);
if (hba instanceof HostInternetScsiHba) {
debug("Adding iSCSI send targets %s for HBA %s [%s]", StringUtils.join(addresses, ", "), hba.getDevice(), iqn);
hostStorageAPI.addInternetScsiSendTargets((HostInternetScsiHba) hba, addresses);
}
}
hostStorageAPI.rescanHBAs();
}
Aggregations