Search in sources :

Example 11 with LinuxSystemCLI

use of com.iwave.ext.linux.LinuxSystemCLI in project coprhd-controller by CoprHD.

the class LinuxHostDiscoveryAdapter method discoverInitiators.

@Override
protected void discoverInitiators(Host host, List<Initiator> oldInitiators, HostStateChange changes) {
    LinuxSystemCLI linux = createLinuxCLI(host);
    List<Initiator> addedInitiators = Lists.newArrayList();
    try {
        for (HBAInfo hba : linux.listHBAs()) {
            Initiator initiator;
            String wwpn = SanUtils.normalizeWWN(hba.getWwpn());
            if (findInitiatorByPort(oldInitiators, wwpn) == null) {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, wwpn);
                addedInitiators.add(initiator);
            } else {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, wwpn);
            }
            discoverFCInitiator(host, initiator, hba);
        }
    } catch (DeviceControllerException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to list FC Ports, skipping");
    }
    try {
        for (String iqn : linux.listIQNs()) {
            Initiator initiator;
            if (findInitiatorByPort(oldInitiators, iqn) == null) {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, iqn);
                addedInitiators.add(initiator);
            } else {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, iqn);
            }
            discoverISCSIInitiator(host, initiator, iqn);
        }
    } catch (DeviceControllerException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to list iSCSI Ports, skipping");
    }
    try {
        String cephPseudoPort = String.format("rbd:%s", linux.getMachineId());
        Initiator initiator;
        if (findInitiatorByPort(oldInitiators, cephPseudoPort) == null) {
            initiator = getOrCreateInitiator(host.getId(), oldInitiators, cephPseudoPort);
            addedInitiators.add(initiator);
        } else {
            initiator = getOrCreateInitiator(host.getId(), oldInitiators, cephPseudoPort);
        }
        discoverRBDInitiator(host, initiator, cephPseudoPort);
    } catch (DeviceControllerException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to create RBD pseudo port, skipping");
    }
    // update export groups with new initiators if host is in use.
    if (!addedInitiators.isEmpty()) {
        Collection<URI> addedInitiatorIds = Lists.newArrayList(Collections2.transform(addedInitiators, CommonTransformerFunctions.fctnDataObjectToID()));
        changes.setNewInitiators(addedInitiatorIds);
    }
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) HBAInfo(com.iwave.ext.linux.model.HBAInfo) Initiator(com.emc.storageos.db.client.model.Initiator) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) URI(java.net.URI) MultipathException(com.iwave.ext.linux.command.MultipathException) PowerPathException(com.iwave.ext.linux.command.powerpath.PowerPathException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) CompatibilityException(com.emc.storageos.computesystemcontroller.exceptions.CompatibilityException) CommandException(com.iwave.ext.command.CommandException) JSchException(com.jcraft.jsch.JSchException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 12 with LinuxSystemCLI

use of com.iwave.ext.linux.LinuxSystemCLI in project coprhd-controller by CoprHD.

the class CephStorageDevice method getLinuxClient.

/**
 * Initialize Linux host CLI for given host
 *
 * @param host
 *            [in] - Host object
 * @return Linux host CLI
 */
private LinuxSystemCLI getLinuxClient(Host host) {
    LinuxSystemCLI cli = new LinuxSystemCLI();
    cli.setHost(host.getHostName());
    cli.setPort(host.getPortNumber());
    cli.setUsername(host.getUsername());
    cli.setPassword(host.getPassword());
    cli.setHostId(host.getId());
    return cli;
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI)

Example 13 with LinuxSystemCLI

use of com.iwave.ext.linux.LinuxSystemCLI in project coprhd-controller by CoprHD.

the class CephStorageDevice method unmapVolumes.

/**
 * Unmap volumes from hosts on the hosts themselves.
 *
 * @param storage
 *            [in] - StorageSystem object
 * @param volumeURIs
 *            [in] - Collection of Volume URIs
 * @param initiators
 *            [in] - Collection of Initiator objects
 * @param completer
 *            [in] - TaskCompleter
 */
private void unmapVolumes(StorageSystem storage, List<URI> volumeURIs, Collection<Initiator> initiators, TaskCompleter completer) {
    _log.info("unmapVolumes: volumeURIs: {}", volumeURIs);
    _log.info("unmapVolumes: initiators: {}", initiators);
    try {
        for (URI uri : volumeURIs) {
            BlockObject object = BlockObject.fetch(_dbClient, uri);
            if (object == null) {
                _log.warn("Attempted to unmap BlockObject {}, which is empty", uri);
                continue;
            }
            if (object.getInactive()) {
                _log.warn("Attempted to unmap BlockObject {}, which is inactive", uri);
                continue;
            }
            RBDMappingOptions rbdOptions = new RBDMappingOptions(object);
            for (Initiator initiator : initiators) {
                Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                String port = initiator.getInitiatorPort();
                if (initiator.getProtocol().equalsIgnoreCase(HostInterface.Protocol.RBD.name())) {
                    LinuxSystemCLI linuxClient = getLinuxClient(host);
                    linuxClient.unmapRBD(rbdOptions.poolName, rbdOptions.volumeName, rbdOptions.snapshotName);
                } else {
                    String msgPattern = "Unexpected initiator protocol %s for port %s and uri %s";
                    String msg = String.format(msgPattern, initiator.getProtocol(), port, uri);
                    ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("unmapVolumes", msg);
                    completer.error(_dbClient, code);
                    return;
                }
            }
        }
        completer.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("unmapVolumes", e.getMessage());
        completer.error(_dbClient, code);
    }
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) Initiator(com.emc.storageos.db.client.model.Initiator) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 14 with LinuxSystemCLI

use of com.iwave.ext.linux.LinuxSystemCLI in project coprhd-controller by CoprHD.

the class LinuxHostConnectionValidator method validateConnection.

@Override
public boolean validateConnection(HostParam hostParam, Host existingHost) {
    HostType hostType = HostType.valueOf(hostParam.getType());
    if (getType().equals(hostType) == false) {
        throw new IllegalStateException(String.format("Invalid HostType [%s]", hostParam.getType()));
    }
    String password = hostParam.getPassword();
    if (password == null && existingHost != null) {
        password = existingHost.getPassword();
    }
    LinuxSystemCLI cli = new LinuxSystemCLI(hostParam.getHostName(), hostParam.getPortNumber(), hostParam.getUserName(), password);
    try {
        cli.listMountPoints();
        return true;
    } catch (Exception e) {
        log.error(String.format("Error Validating Host %s", hostParam.getName()), e);
    }
    return false;
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) HostType(com.emc.storageos.db.client.model.Host.HostType)

Example 15 with LinuxSystemCLI

use of com.iwave.ext.linux.LinuxSystemCLI 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)

Aggregations

LinuxSystemCLI (com.iwave.ext.linux.LinuxSystemCLI)16 URI (java.net.URI)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 Initiator (com.emc.storageos.db.client.model.Initiator)3 ListVPlexPerpetualCSVFileNames (com.emc.storageos.volumecontroller.impl.plugins.metering.vplex.ListVPlexPerpetualCSVFileNames)3 CommandException (com.iwave.ext.command.CommandException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Test (org.junit.Test)3 CompatibilityException (com.emc.storageos.computesystemcontroller.exceptions.CompatibilityException)2 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 Host (com.emc.storageos.db.client.model.Host)2 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)2 ReadAndParseVPlexPerpetualCSVFile (com.emc.storageos.volumecontroller.impl.plugins.metering.vplex.ReadAndParseVPlexPerpetualCSVFile)2 VPlexPerpetualCSVFileData (com.emc.storageos.volumecontroller.impl.plugins.metering.vplex.VPlexPerpetualCSVFileData)2 MultipathException (com.iwave.ext.linux.command.MultipathException)2 PowerPathException (com.iwave.ext.linux.command.powerpath.PowerPathException)2 IPInterface (com.iwave.ext.linux.model.IPInterface)2 JSchException (com.jcraft.jsch.JSchException)2