Search in sources :

Example 1 with LinuxSystemCLI

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

the class LinuxHostDiscoveryAdapter method getVersions.

protected List<LinuxVersion> getVersions(Host host) {
    LinuxSystemCLI cli = createLinuxCLI(host);
    List<LinuxVersion> versions = new ArrayList<LinuxVersion>();
    LinuxVersionCommand[] commands = { new GetSuSEVersionCommand(), new GetRedhatVersionCommandOne(), new GetRedhatVersionCommandTwo(), new GetRedhatVersionCommandThree(), new GetLinuxVersionLSBReleaseCommand() };
    for (LinuxVersionCommand command : commands) {
        try {
            cli.executeCommand(command);
            LinuxVersion version = command.getResults();
            if (version != null) {
                versions.add(version);
            }
        } catch (CommandException e) {
            warn("Could not retrieve linux version", e);
        }
    }
    if (versions.isEmpty()) {
        error("Could not determine version of linux host %s", host.getLabel());
        versions.add(new LinuxVersion(LinuxDistribution.UNKNOWN, ""));
    }
    return versions;
}
Also used : GetSuSEVersionCommand(com.iwave.ext.linux.command.version.GetSuSEVersionCommand) GetRedhatVersionCommandOne(com.iwave.ext.linux.command.version.GetRedhatVersionCommandOne) LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) LinuxVersionCommand(com.iwave.ext.linux.command.version.LinuxVersionCommand) ArrayList(java.util.ArrayList) GetRedhatVersionCommandThree(com.iwave.ext.linux.command.version.GetRedhatVersionCommandThree) GetRedhatVersionCommandTwo(com.iwave.ext.linux.command.version.GetRedhatVersionCommandTwo) CommandException(com.iwave.ext.command.CommandException) LinuxVersion(com.iwave.ext.linux.model.LinuxVersion) GetLinuxVersionLSBReleaseCommand(com.iwave.ext.linux.command.version.GetLinuxVersionLSBReleaseCommand)

Example 2 with LinuxSystemCLI

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

the class LinuxHostDiscoveryAdapter method discoverIpInterfaces.

@Override
protected void discoverIpInterfaces(Host host, List<IpInterface> oldIpInterfaces) {
    LinuxSystemCLI linux = createLinuxCLI(host);
    for (IPInterface nic : linux.listIPInterfaces()) {
        if (StringUtils.isNotBlank(nic.getIpAddress())) {
            IpInterface ipInterface = getOrCreateIpInterface(oldIpInterfaces, nic.getIpAddress());
            discoverIp4Interface(host, ipInterface, nic);
        }
        if (StringUtils.isNotBlank(nic.getIP6Address())) {
            IpInterface ipInterface = getOrCreateIpInterface(oldIpInterfaces, StringUtils.substringBefore(nic.getIP6Address(), "/"));
            discoverIp6Interface(host, ipInterface, nic);
        }
    }
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) IpInterface(com.emc.storageos.db.client.model.IpInterface) IPInterface(com.iwave.ext.linux.model.IPInterface)

Example 3 with LinuxSystemCLI

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

the class CephStorageDevice method mapVolumes.

/**
 * Map volumes to hosts on the hosts themselves.
 *
 * @param storage
 *            [in] - Storage System object
 * @param volumeMap
 *            [in] - Volume URI to Integer LUN map
 * @param initiators
 *            [in] - Collection of Initiator objects
 * @param completer
 *            [in] - TaskCompleter
 */
private void mapVolumes(StorageSystem storage, Map<URI, Integer> volumeMap, Collection<Initiator> initiators, TaskCompleter completer) {
    _log.info("mapVolumes: volumeMap: {}", volumeMap);
    _log.info("mapVolumes: initiators: {}", initiators);
    try {
        for (Map.Entry<URI, Integer> volMapEntry : volumeMap.entrySet()) {
            URI objectUri = volMapEntry.getKey();
            BlockObject object = Volume.fetchExportMaskBlockObject(_dbClient, objectUri);
            String monitorAddress = storage.getSmisProviderIP();
            String monitorUser = storage.getSmisUserName();
            String monitorKey = storage.getSmisPassword();
            RBDMappingOptions rbdOptions = new RBDMappingOptions(object);
            for (Initiator initiator : initiators) {
                Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                if (initiator.getProtocol().equalsIgnoreCase(HostInterface.Protocol.RBD.name())) {
                    _log.info(String.format("mapVolume: host %s pool %s volume %s", host.getHostName(), rbdOptions.poolName, rbdOptions.volumeName));
                    LinuxSystemCLI linuxClient = getLinuxClient(host);
                    linuxClient.mapRBD(monitorAddress, monitorUser, monitorKey, rbdOptions.poolName, rbdOptions.volumeName, rbdOptions.snapshotName);
                } else {
                    String msg = String.format("Unexpected initiator protocol %s, port %s, pool %s, volume %s", initiator.getProtocol(), initiator.getInitiatorPort(), rbdOptions.poolName, rbdOptions.volumeName);
                    ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", msg);
                    completer.error(_dbClient, code);
                    return;
                }
            }
        }
        completer.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", 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) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 4 with LinuxSystemCLI

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

the class VPlexPerpetualCSVFileCollector method collect.

@Override
public void collect(AccessProfile accessProfile, Map<String, Object> context) {
    init();
    DbClient dbClient = (DbClient) context.get(Constants.dbClient);
    // Get which VPlex array that this applies to
    URI storageSystemURI = accessProfile.getSystemId();
    StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, storageSystemURI);
    if (storageSystem == null) {
        log.error("Could not find StorageSystem '{}' in DB", storageSystemURI);
        return;
    }
    StringSet providerIds = storageSystem.getProviders();
    for (String providerId : providerIds) {
        StorageProvider provider = dbClient.queryObject(StorageProvider.class, URI.create(providerId));
        LinuxSystemCLI cli = new LinuxSystemCLI(provider.getIPAddress(), provider.getUserName(), provider.getPassword());
        ListVPlexPerpetualCSVFileNames listDataFileNamesCmd = new ListVPlexPerpetualCSVFileNames();
        cli.executeCommand(listDataFileNamesCmd);
        // Process each of the data files that we found on the VPlex management station
        List<String> fileNames = listDataFileNamesCmd.getResults();
        for (String fileName : fileNames) {
            log.info("Processing VPLEX performance statistics file {}", fileName);
            // Extract and hold the data for this data file
            ReadAndParseVPlexPerpetualCSVFile readDataFile = new ReadAndParseVPlexPerpetualCSVFile(fileName);
            cli.executeCommand(readDataFile);
            VPlexPerpetualCSVFileData fileData = readDataFile.getResults();
            // Read the headers and extract those metric names that we're interested in and to which
            // DataObject (StorageHADomain or StoragePort) that it should be associated with. This
            // will be used as a way to look up the object when processing the actual metric data
            Map<String, MetricHeaderInfo> metricNamesToHeaderInfo = processCSVFileDataHeader(dbClient, storageSystem, fileData.getDirectorName(), fileData.getHeaders());
            List<Map<String, String>> dataLines = fileData.getDataLines();
            int lineCount = dataLines.size();
            // There is at least one data point
            if (lineCount > 1) {
                // Determine the last time that metrics were collected.
                Long lastCollectionTimeUTC = getLastCollectionTime(metricNamesToHeaderInfo);
                // Try to find the index into dataLines based on the last collection time.
                // What we're trying to do here is determine the maximum value for the metrics
                // from the last collection time in ViPR, until the last data line in the file.
                int start = fileData.getDataIndexForTime(lastCollectionTimeUTC);
                // Have a mapping of metrics to their maximum value found in the dataLines
                Map<String, Double> maxValues = findMaxMetricValues(dataLines, start, lineCount);
                // Process the metrics for this file
                Map<String, String> last = dataLines.get(lineCount - 1);
                processDirectorStats(metricNamesToHeaderInfo, maxValues, last);
                processPortStats(context, metricNamesToHeaderInfo, maxValues, last);
            }
            // Clean up fileData resources
            fileData.close();
        }
        // Clean out the cache data, so that it's not laying around
        clearCaches();
    }
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) DbClient(com.emc.storageos.db.client.DbClient) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 5 with LinuxSystemCLI

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

the class VPlexMeteringTest method testReadingDataFiles.

@Test
public void testReadingDataFiles() {
    LinuxSystemCLI cli = new LinuxSystemCLI(HOST, USERNAME, PASSWORD);
    ListVPlexPerpetualCSVFileNames listDataFileNamesCmd = new ListVPlexPerpetualCSVFileNames();
    cli.executeCommand(listDataFileNamesCmd);
    List<String> filenames = listDataFileNamesCmd.getResults();
    Assert.assertFalse("Expected to find file names", filenames.isEmpty());
    for (String filename : filenames) {
        ReadAndParseVPlexPerpetualCSVFile readDataFile = new ReadAndParseVPlexPerpetualCSVFile(filename);
        cli.executeCommand(readDataFile);
        VPlexPerpetualCSVFileData fileData = readDataFile.getResults();
        Assert.assertNotNull("Expect file data to be non-null", fileData);
        out("For file {} these are the headers:\n{}", filename, Joiner.on('\n').join(fileData.getHeaders()));
        List<Map<String, String>> dataLines = fileData.getDataLines();
        Assert.assertTrue("Expect file data to have data values", !dataLines.isEmpty());
        out("For file {} there are {} data lines", filename, dataLines.size());
        fileData.close();
    }
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) ListVPlexPerpetualCSVFileNames(com.emc.storageos.volumecontroller.impl.plugins.metering.vplex.ListVPlexPerpetualCSVFileNames) ReadAndParseVPlexPerpetualCSVFile(com.emc.storageos.volumecontroller.impl.plugins.metering.vplex.ReadAndParseVPlexPerpetualCSVFile) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) VPlexPerpetualCSVFileData(com.emc.storageos.volumecontroller.impl.plugins.metering.vplex.VPlexPerpetualCSVFileData) Test(org.junit.Test)

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