Example #1
0
// Retrieve the AMDbObjectAttribute for a given \c object and \c key
QString AMDbObjectSupport::dbObjectAttribute(const QMetaObject* mo, const QString& key) {
	int i = mo->indexOfClassInfo("AMDbObject_Attributes");
	if(i < 0) {
		//qdebug() << "AMDBOBJECT" << mo->className() << ": no dbobject attributes set";
		return QString();
	}
	QString allAttributes( mo->classInfo(i).value() );
	QStringList attributeList = allAttributes.split(QChar(';'), QString::SkipEmptyParts);// split attributes by semicolon
	// search for a matching attribute:
	for(int i=0; i<attributeList.count(); i++) {
		if(attributeList.at(i).trimmed().startsWith(key+"="))
			return attributeList.at(i).section(QChar('='), 1);// return section after "key=".
	}
	//qdebug() << "AMDBOBJECT" << mo->className() << ": could not find object attribute " << key;
	return QString();
}
Example #2
0
// Retrieve an object's property attribute for a given \c object, \c propertyName, and \c key. Returns empty string if not set.
QString AMDbObjectSupport::dbPropertyAttribute(const QMetaObject* mo, const QString& propertyName, const QString& key) {
	int i = mo->indexOfClassInfo(propertyName.toAscii().constData());
	if(i < 0) {
		//qdebug() << "AMDBOBJECT" << mo->className() << ": no property attributes set for " << propertyName;
		return QString();	// property attributes not found for this property
	}
	QString allAttributes( mo->classInfo(i).value() );
	QStringList attributeList = allAttributes.split(QChar(';'), QString::SkipEmptyParts);// split attributes by semicolon
	// search for matching attribute:
	for(int i=0; i<attributeList.count(); i++) {
		if(attributeList.at(i).startsWith(key+"="))
			return attributeList.at(i).section(QChar('='), 1);// return section after "key=".
	}
	//qdebug() << "AMDBOBJECT" << mo->className() << ": could not find property attribute " << propertyName << key;

	return QString();
}
Example #3
0
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;
}