示例#1
0
framework::ResultBase *CreateGoalCommand::execute(const framework::ParsedCommand &parsedCommand)
{
    LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
    m_pResult = m_parser.parse(parsedCommand);

    if (m_pResult == NULL)
    {
        try
        {
            setupRequestBuilder();
            const core::memory_allocator::MemoryAllocationRequest &request = m_requestBuilder.build();
            core::memory_allocator::MemoryAllocationLayout layout = m_allocator.layout(request);

            if (userReallyLikesThisLayout(layout, m_parser.getUnits()))
            {
                m_allocator.allocate(layout);
                m_pResult = m_showGoalAdapter.showCurrentGoal(m_parser.getUnits());
            }
            else
            {
                m_pResult = new NoChangeResult();
            }
        }
        catch (wbem::framework::Exception &e)
        {
            m_pResult = NvmExceptionToResult(e);
        }
        catch (std::exception &e)
        {
            m_pResult = CoreExceptionToResult(e);
        }
    }

    return m_pResult;
}
示例#2
0
/*
 * For commands that support an optional -namespace target,
 * retrieve the namespace UID(s) of the specified target
 * or all namespace UIDs if not specified.
 */
cli::framework::ErrorResult *cli::nvmcli::WbemToCli::getNamespaces(
        const framework::ParsedCommand &parsedCommand,
        std::vector<std::string> &namespaces)
{
    LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
    framework::ErrorResult *pResult = NULL;
    std::vector<std::string> nsList =
            cli::framework::Parser::getTargetValues(parsedCommand,
                                                    cli::nvmcli::TARGET_NAMESPACE.name);
    try
    {
        // a target value was specified
        if (!nsList.empty())
        {
            std::vector<std::string> allNamespaces =
                    wbem::pmem_config::NamespaceViewFactory::getNamespaceUidList();
            // check each namespace uid, validate it's format if it exists
            for (size_t i = 0; i < nsList.size(); i++)
            {
                if (nsList[i].length() + 1 != COMMON_UID_LEN)
                {
                    pResult = new framework::SyntaxErrorBadValueResult(framework::TOKENTYPE_TARGET,
                                                                       TARGET_NAMESPACE.name, nsList[i]);
                    break;
                }
                else if (std::find(allNamespaces.begin(), allNamespaces.end(), nsList[i]) ==
                         allNamespaces.end())
                {
                	std::string errorString = framework::ResultBase::stringFromArgList(
                			TR(INVALID_NAMESPACEID_ERROR_STR.c_str()), nsList[i].c_str());

                    pResult = new framework::ErrorResult(framework::ErrorResult::ERRORCODE_UNKNOWN,
                    		errorString);
                    break;
                }
                else
                {
                    namespaces.push_back(nsList[i]);
                }
            }
        }
            // no target specified, just get all namespace uids
        else
        {
            namespaces = wbem::pmem_config::NamespaceViewFactory::getNamespaceUidList();
        }
    }
    catch (wbem::framework::Exception &e)
    {
        pResult = NvmExceptionToResult(e);
    }
    return pResult;
}
示例#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;
}