bool cli::framework::UnitsOption::isValid() const { bool validType = false; std::string units = getCapacityUnits(); if (units.empty()) { validType = true; } else if (m_options.find(OPTION_UNITS.name) != m_options.end()) { std::vector<std::string> validUnits; validUnits.push_back("B"); validUnits.push_back("MB"); validUnits.push_back("MiB"); validUnits.push_back("GB"); validUnits.push_back("GiB"); validUnits.push_back("TB"); validUnits.push_back("TiB"); for (std::vector<std::string>::const_iterator iter = validUnits.begin(); iter != validUnits.end(); iter++) { if (stringsIEqual(units, *iter)) { validType = true; break; } } } return validType; }
bool cli::framework::UnitsOption::isEmpty() const { bool emptyUnits = false; if (m_options.find("-units") != m_options.end()) { std::string units = getCapacityUnits(); if (units.empty()) { emptyUnits = true; } } return emptyUnits; }
cli::framework::ResultBase *cli::nvmcli::NamespaceFeature::showPools(cli::framework::ParsedCommand const &parsedCommand) { framework::ResultBase *pResult = NULL; wbem::mem_config::PoolViewFactory poolViewFactory; wbem::framework::attribute_names_t attributes; wbem::framework::instances_t *pInstances = NULL; try { // define default display attributes wbem::framework::attribute_names_t defaultAttributes; defaultAttributes.push_back(wbem::POOLID_KEY); defaultAttributes.push_back(wbem::POOLTYPE_KEY); defaultAttributes.push_back(wbem::CAPACITY_KEY); defaultAttributes.push_back(wbem::FREECAPACITY_KEY); // define all attributes wbem::framework::attribute_names_t allAttributes(defaultAttributes); allAttributes.push_back(wbem::ENCRYPTIONCAPABLE_KEY); allAttributes.push_back(wbem::ENCRYPTIONENABLED_KEY); allAttributes.push_back(wbem::ERASECAPABLE_KEY); allAttributes.push_back(wbem::SOCKETID_KEY); allAttributes.push_back(wbem::APPDIRECTNAMESPACE_MAX_SIZE_KEY); allAttributes.push_back(wbem::APPDIRECTNAMESPACE_MIN_SIZE_KEY); allAttributes.push_back(wbem::APPDIRECTNAMESPACE_COUNT_KEY); allAttributes.push_back(wbem::STORAGENAMESPACE_MAX_SIZE_KEY); allAttributes.push_back(wbem::STORAGENAMESPACE_MIN_SIZE_KEY); allAttributes.push_back(wbem::STORAGENAMESPACE_COUNT_KEY); allAttributes.push_back(wbem::HEALTHSTATE_KEY); allAttributes.push_back(wbem::APP_DIRECT_SETTINGS_KEY); // get the desired attributes wbem::framework::attribute_names_t attributes = GetAttributeNames(parsedCommand.options, defaultAttributes, allAttributes); // make sure we have the Pool id in our display // this would cover the case the user asks for specific display attributes, but they // don't include the physical ID if (!wbem::framework_interface::NvmInstanceFactory::containsAttribute(wbem::POOLID_KEY, attributes)) { attributes.insert(attributes.begin(), wbem::POOLID_KEY); } // create the display filters wbem::framework::attribute_names_t requestedAttributes = attributes; cli::nvmcli::filters_t filters; generateSocketFilter(parsedCommand, requestedAttributes, filters); generatePoolFilter(parsedCommand, requestedAttributes, filters); pInstances = poolViewFactory.getInstances(requestedAttributes); if (pInstances == NULL) { COMMON_LOG_ERROR("PoolViewFactory getInstances returned a NULL instances pointer"); pResult = new framework::ErrorResult(framework::ErrorResult::ERRORCODE_UNKNOWN, TRS(nvmcli::UNKNOWN_ERROR_STR)); } else { // get the desired units of capacity std::string capacityUnits; pResult = getCapacityUnits(parsedCommand, &capacityUnits); if (pResult == NULL) { for (size_t i = 0; i < pInstances->size(); i++) { cli::nvmcli::convertCapacityAttribute((*pInstances)[i], wbem::CAPACITY_KEY, capacityUnits); cli::nvmcli::convertCapacityAttribute((*pInstances)[i], wbem::FREECAPACITY_KEY, capacityUnits); cli::nvmcli::convertCapacityAttribute((*pInstances)[i], wbem::APPDIRECTNAMESPACE_MAX_SIZE_KEY, capacityUnits); cli::nvmcli::convertCapacityAttribute((*pInstances)[i], wbem::APPDIRECTNAMESPACE_MIN_SIZE_KEY, capacityUnits); cli::nvmcli::convertCapacityAttribute((*pInstances)[i], wbem::STORAGENAMESPACE_MAX_SIZE_KEY, capacityUnits); cli::nvmcli::convertCapacityAttribute((*pInstances)[i], wbem::STORAGENAMESPACE_MIN_SIZE_KEY, capacityUnits); } pResult = NvmInstanceToObjectListResult(*pInstances, "Pool", wbem::POOLID_KEY, attributes, filters); // Set layout to table unless the -all or -display option is present if (!framework::parsedCommandContains(parsedCommand, framework::OPTION_DISPLAY) && !framework::parsedCommandContains(parsedCommand, framework::OPTION_ALL)) { pResult->setOutputType(framework::ResultBase::OUTPUT_TEXTTABLE); } } } } catch (wbem::framework::Exception &e) { if (pResult) { delete pResult; pResult = NULL; } pResult = NvmExceptionToResult(e); } if (pInstances) { delete pInstances; } return pResult; }