/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::mem_config::MemoryConfigurationFactory::getInstance(
		framework::ObjectPath &path,
		framework::attribute_names_t &attributes)
				throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);

	try
	{
		checkAttributes(attributes);
		lib_interface::NvmApi *pApi = lib_interface::NvmApi::getApi();

		// parse InstanceID
		framework::Attribute idAttr = path.getKeyValue(INSTANCEID_KEY);
		std::string instanceId = idAttr.stringValue();

		if (!isValidInstanceId(instanceId))
		{
			throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
		}

		std::string uidStr = instanceId.substr(0, instanceId.length() - 1);
		struct device_discovery deviceDiscovery;
		pApi->getDeviceDiscoveryForDimm(uidStr, deviceDiscovery);

		// ElementName - host name + " NVM allocation setting"
		if (containsAttribute(ELEMENTNAME_KEY, attributes))
		{
			// Get the real host name
			std::string elementName = pApi->getHostName() +
					MEMORYCONFIGURATION_ELEMENTNAME;
			framework::Attribute a(elementName, false);
			pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes);
		}

		populateInstanceDimmInfoFromDiscovery(attributes, pInstance, deviceDiscovery);

		if (isGoalConfig(instanceId))
		{
			populateGoalInstance(attributes, uidStr, pInstance, &deviceDiscovery);
		}
		else
		{
			populateCurrentConfigInstance(attributes, uidStr, pInstance, &deviceDiscovery);
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}
示例#2
0
bool isValidCommonApiAddress(const std::string& commonApiAddress) {
    std::vector<std::string> splittedAddress = split(commonApiAddress, ':');
    if (splittedAddress.size() != 3) {
        return false;
    }
    return isValidDomainName(splittedAddress[0]) && isValidServiceName(splittedAddress[1]) && isValidInstanceId(splittedAddress[2]);
}