Search in sources :

Example 11 with HostStorageAPI

use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.

the class RefreshStorage method execute.

@Override
public void execute() throws Exception {
    debug("Executing: %s", getDetail());
    for (HostSystem host : hosts) {
        try {
            HostStorageAPI storageAPI = new HostStorageAPI(host);
            storageAPI.refreshStorage();
        } catch (Exception e) {
            logWarn("RefreshStorage.detail.error", host.getName());
        }
    }
}
Also used : HostSystem(com.vmware.vim25.mo.HostSystem) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI)

Example 12 with HostStorageAPI

use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.

the class UnmountVmfsDatastore method tryExecute.

@Override
protected Void tryExecute() {
    final String dataStoreName = datastore.getName();
    for (HostFileSystemMountInfo mount : new HostStorageAPI(host).getStorageSystem().getFileSystemVolumeInfo().getMountInfo()) {
        HostFileSystemVolume mountVolume = mount.getVolume();
        if (mountVolume == null) {
            warn("No volume attached to mount : " + mount.getMountInfo().getPath());
            continue;
        }
        if (mount.getVolume() instanceof HostVmfsVolume && dataStoreName.equals(mount.getVolume().getName())) {
            HostVmfsVolume volume = (HostVmfsVolume) mountVolume;
            String vmfsUuid = volume.getUuid();
            info("Unmounting volume : " + vmfsUuid);
            try {
                new HostStorageAPI(host).getStorageSystem().unmountVmfsVolume(vmfsUuid);
            } catch (RemoteException e) {
                throw new VMWareException(e);
            }
        }
    }
    return null;
}
Also used : HostVmfsVolume(com.vmware.vim25.HostVmfsVolume) HostFileSystemVolume(com.vmware.vim25.HostFileSystemVolume) RemoteException(java.rmi.RemoteException) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI) HostFileSystemMountInfo(com.vmware.vim25.HostFileSystemMountInfo) VMWareException(com.iwave.ext.vmware.VMWareException)

Example 13 with HostStorageAPI

use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.

the class HostRescanDeviceController method getRescanAdapter.

private HostRescanAdapter getRescanAdapter(Host host) {
    if (HostType.Linux.name().equalsIgnoreCase(host.getType())) {
        return new LinuxSystemCLI(host.getHostName(), host.getPortNumber(), host.getUsername(), host.getPassword());
    } else if (HostType.AIX.name().equalsIgnoreCase(host.getType())) {
        return new AixSystem(host.getHostName(), host.getPortNumber(), host.getUsername(), host.getPassword());
    } else if (HostType.HPUX.name().equalsIgnoreCase(host.getType())) {
        return new HpuxSystem(host.getHostName(), host.getPortNumber(), host.getUsername(), host.getPassword());
    } else if (HostType.Windows.name().equalsIgnoreCase(host.getType())) {
        List<AuthnProvider> authProviders = new ArrayList<AuthnProvider>();
        for (URI authProviderId : getDbClient().queryByType(AuthnProvider.class, true)) {
            AuthnProvider authProvider = getDbClient().queryObject(AuthnProvider.class, authProviderId);
            authProviders.add(authProvider);
        }
        KerberosUtil.initializeKerberos(authProviders);
        return WindowsHostDiscoveryAdapter.createWindowsSystem(host);
    } else if (HostType.Esx.name().equalsIgnoreCase(host.getType())) {
        if (host.getUsername() != null && host.getPassword() != null) {
            VCenterAPI vcenterAPI = EsxHostDiscoveryAdapter.createVCenterAPI(host);
            List<HostSystem> hostSystems = vcenterAPI.listAllHostSystems();
            if (hostSystems != null && !hostSystems.isEmpty()) {
                return new HostStorageAPI(hostSystems.get(0));
            } else {
                return null;
            }
        } else if (host.getVcenterDataCenter() != null) {
            // Lookup the vcenter datacenter and vcenter to retreive the HostSystem
            VcenterDataCenter dataCenter = dbClient.queryObject(VcenterDataCenter.class, host.getVcenterDataCenter());
            if (dataCenter == null || dataCenter.getInactive()) {
                throw DeviceControllerException.exceptions.objectNotFound(host.getVcenterDataCenter());
            }
            Vcenter vcenter = dbClient.queryObject(Vcenter.class, dataCenter.getVcenter());
            if (vcenter == null || vcenter.getInactive()) {
                throw DeviceControllerException.exceptions.objectNotFound(dataCenter.getVcenter());
            }
            VCenterAPI vCenterAPI = VcenterDiscoveryAdapter.createVCenterAPI(vcenter);
            String datacenterName = dataCenter.getLabel();
            HostSystem hostSystem = vCenterAPI.findHostSystem(datacenterName, host.getHostName());
            if (hostSystem != null) {
                return new HostStorageAPI(hostSystem);
            } else {
                return null;
            }
        }
    } else {
        // Unanticipated host type
        return null;
    }
    return null;
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) Vcenter(com.emc.storageos.db.client.model.Vcenter) AuthnProvider(com.emc.storageos.db.client.model.AuthnProvider) URI(java.net.URI) HpuxSystem(com.emc.hpux.HpuxSystem) AixSystem(com.emc.aix.AixSystem) HostSystem(com.vmware.vim25.mo.HostSystem) ArrayList(java.util.ArrayList) List(java.util.List) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI)

Example 14 with HostStorageAPI

use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.

the class ComputeSystemControllerImpl method unmountAndDetach.

/**
 * Unmounts and detaches every datastore and disk associated with the volumes in the export group.
 * For each volume in the export group, the backed datastore is unmounted and the associated disk is detached from
 * 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 unmountAndDetach(URI exportGroupId, 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);
        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 validate");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
        Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
        if (exportGroup != null && exportGroup.getVolumes() != null) {
            for (String volume : exportGroup.getVolumes().keySet()) {
                BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
                if (blockObject != null) {
                    Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
                    if (datastore != null) {
                        if (VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
                            boolean storageIOControlEnabled = datastore.getIormConfiguration().isEnabled();
                            if (storageIOControlEnabled) {
                                setStorageIOControl(api, datastore, false);
                            }
                            _log.info("Unmount datastore " + datastore.getName() + " from host " + esxHost.getLabel());
                            storageAPI.unmountVmfsDatastore(datastore);
                            if (storageIOControlEnabled) {
                                setStorageIOControl(api, datastore, true);
                            }
                        } else {
                            _log.info("Datastore " + datastore.getName() + " is not mounted on host " + esxHost.getLabel() + ". Skipping unmounting of datastore.");
                        }
                    }
                }
                // VBDU TODO: COP-28459, If datastore doesn't match, why do we need to run DetachSCSILun() ?
                // Test mechanism to invoke a failure. No-op on production systems.
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_030);
                for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
                    if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
                        if (!VMwareUtils.isDiskOff(entry)) {
                            _log.info("Detach SCSI Lun " + entry.getCanonicalName() + " from host " + esxHost.getLabel());
                            storageAPI.detachScsiLun(entry);
                        } else {
                            _log.info("SCSI Lun " + entry.getCanonicalName() + " is not in a valid state to detach");
                        }
                    }
                }
                storageAPI.refreshStorage();
                // Test mechanism to invoke a failure. No-op on production systems.
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_031);
            }
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception ex) {
        _log.error(ex.getMessage(), ex);
        WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Datastore(com.vmware.vim25.mo.Datastore) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostScsiDisk(com.vmware.vim25.HostScsiDisk) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 15 with HostStorageAPI

use of com.iwave.ext.vmware.HostStorageAPI in project coprhd-controller by CoprHD.

the class FindLunsBackingDatastore method executeTask.

@Override
public Set<String> executeTask() throws Exception {
    List<HostScsiDisk> disks = new HostStorageAPI(host).listDisks(datastore);
    Set<String> luns = Sets.newHashSet();
    for (HostScsiDisk disk : disks) {
        if (!validateCanonicalPrefix(disk.getCanonicalName())) {
            logError("FindLunsBackingDatastore.failure.invalidprefix", disk.getCanonicalName());
        }
        String volumeWwn = VMwareUtils.getDiskWwn(disk);
        if (StringUtils.isNotBlank(volumeWwn)) {
            luns.add(volumeWwn);
        }
    }
    return luns;
}
Also used : HostScsiDisk(com.vmware.vim25.HostScsiDisk) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI)

Aggregations

HostStorageAPI (com.iwave.ext.vmware.HostStorageAPI)16 HostSystem (com.vmware.vim25.mo.HostSystem)8 HostScsiDisk (com.vmware.vim25.HostScsiDisk)5 RemoteException (java.rmi.RemoteException)5 Vcenter (com.emc.storageos.db.client.model.Vcenter)4 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)4 VCenterAPI (com.iwave.ext.vmware.VCenterAPI)4 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)3 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)3 Host (com.emc.storageos.db.client.model.Host)3 ClientControllerException (com.emc.storageos.exceptions.ClientControllerException)3 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)3 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)3 ControllerException (com.emc.storageos.volumecontroller.ControllerException)3 WorkflowException (com.emc.storageos.workflow.WorkflowException)3 Datastore (com.vmware.vim25.mo.Datastore)3 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)2 VMWareException (com.iwave.ext.vmware.VMWareException)2