Ejemplo n.º 1
0
gboolean
SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event,
                          gpointer user_data)
{
    static const int default_timeout_ms = 60000;
    const std::string& methodName(event.getMethodName());
    if (event.getType() != qmf::AGENT_METHOD) {
        return TRUE;
    }

    qpid::types::Variant::Map& args = event.getArguments();

    if (methodName == "list") {
        _qtype::Variant::List s_list;
        GList *gIter = NULL;
        GList *services = services_list();

        for (gIter = services; gIter != NULL; gIter = gIter->next) {
            s_list.push_back((const char *) gIter->data);
        }

        event.addReturnArgument("agents", s_list);

    } else if (methodName == "enable" || methodName == "disable") {
        svc_action_t *op = services_action_create(
	    args["name"].asString().c_str(), methodName.c_str(), 0,
	    default_timeout_ms);

        action_async(SRV_SERVICES, session, event, op, false);
	return TRUE;

    } else if (methodName == "start"
	       || methodName == "stop"
	       || methodName == "status") {
        svc_action_t *op = services_action_create(
                args["name"].asString().c_str(), methodName.c_str(), 0, args["timeout"].asInt32());

        action_async(SRV_SERVICES, session, event, op, true);
	return TRUE;

    } else {
        session.raiseException(event, MH_NOT_IMPLEMENTED);
        return TRUE;
    }

    session.methodSuccess(event);
    return TRUE;
}
Ejemplo n.º 2
0
bool
VolumeWrap::handleMethod(qmf::AgentSession& session, qmf::AgentEvent& event)
{
    int ret;

    if (*this != event.getDataAddr()) {
        return false;
    }

    const std::string& methodName(event.getMethodName());
    qpid::types::Variant::Map args(event.getArguments());

    if (methodName == "getXMLDesc") {
        const char *desc = virStorageVolGetXMLDesc(_volume_ptr, 0);
        if (!desc) {
            std::string err = FORMAT_ERR(_conn, "Error getting xml description for volume (virStorageVolGetXMLDesc).", &ret);
            raiseException(session, event, err, STATUS_USER + ret);
        } else {
            event.addReturnArgument("description", desc);
            session.methodSuccess(event);
        }
        return true;
    }

    if (methodName == "delete") {
        ret = virStorageVolDelete(_volume_ptr, 0);
        if (ret < 0) {
            std::string err = FORMAT_ERR(_conn, "Error deleting storage volume (virStorageVolDelete).", &ret);
            raiseException(session, event, err, STATUS_USER + ret);
        } else {
            update();
            session.methodSuccess(event);
        }
        return true;
    }

    raiseException(session, event,
                   ERROR_UNKNOWN_METHOD, STATUS_UNKNOWN_METHOD);
    return true;
}
Ejemplo n.º 3
0
gboolean
SrvAgent::invoke_resources(qmf::AgentSession session, qmf::AgentEvent event,
                           gpointer user_data)
{
    const std::string& methodName(event.getMethodName());
    if (event.getType() != qmf::AGENT_METHOD) {
        return TRUE;
    }

    qpid::types::Variant::Map& args = event.getArguments();

    if (methodName == "list_standards") {
        event.addReturnArgument("standards", standards);

    } else if (methodName == "list_providers") {
        GList *gIter = NULL;
        GList *providers = NULL;
        _qtype::Variant::List p_list;

	providers = resources_list_providers(args["standard"].asString().c_str());
        for (gIter = providers; gIter != NULL; gIter = gIter->next) {
            p_list.push_back((const char *) gIter->data);
        }
        event.addReturnArgument("providers", p_list);

    } else if (methodName == "list") {
        GList *gIter = NULL;
        GList *agents = NULL;
	const char *standard = "ocf";
	const char *provider = "heartbeat";
        _qtype::Variant::List t_list;

	if(args.count("standard") > 0) {
	    standard = args["standard"].asString().c_str();
	}
	if(args.count("provider") > 0) {
	    provider = args["provider"].asString().c_str();
	}

	agents = resources_list_agents(standard, provider);
        for (gIter = agents; gIter != NULL; gIter = gIter->next) {
            t_list.push_back((const char *) gIter->data);
        }
        event.addReturnArgument("agents", t_list);

    } else if (methodName == "invoke") {
	svc_action_t *op = NULL;
	bool valid_standard = false;
	_qtype::Variant::List::iterator iter;
	_qtype::Variant::Map map;

	if(args.count("parameters") == 1) {
	    map = args["parameters"].asMap();
	}
	
	GHashTable *params = qmf_map_to_hash(map);

	int32_t interval = 0;
	int32_t timeout = 60000;
	const char *agent = NULL;
	const char *standard = "ocf";
	const char *provider = "heartbeat";

	for ( iter=standards.begin() ; iter != standards.end(); iter++ ) {
	    if(args["standard"].asString() == (*iter).asString()) {
		valid_standard = true;
		break;
	    }
	}

	if(valid_standard == false) {
	    mh_err("%s is not a known resource standard", args["standard"].asString().c_str());
	    session.raiseException(event, MH_NOT_IMPLEMENTED);
	    return TRUE;
	}

	if(args.count("standard") > 0) {
	    standard = args["standard"].asString().c_str();
	}
	if(args.count("provider") > 0) {
	    provider = args["provider"].asString().c_str();
	}
	if(args.count("agent") > 0) {
	    agent = args["agent"].asString().c_str();
	} else {
	    agent = args["name"].asString().c_str();	    
	}

	if(args.count("interval") > 0) {
	    interval = args["interval"].asInt32();
	}
	if(args.count("timeout") > 0) {
	    timeout = args["timeout"].asInt32();
	}

	op = resources_action_create(
	    args["name"].asString().c_str(),
	    standard, provider, agent,
	    args["action"].asString().c_str(),
	    interval, timeout, params);

	if(args.count("expected-rc") == 1) {
	    op->expected_rc = args["expected-rc"].asInt32();
	}
	
	action_async(SRV_RESOURCES, session, event, op, true);
	return TRUE;
	
    } else if (methodName == "cancel") {
        services_action_cancel(
                args["name"].asString().c_str(),
                args["action"].asString().c_str(),
                args["interval"].asInt32());

    } else {
        session.raiseException(event, MH_NOT_IMPLEMENTED);
        return TRUE;
    }

    session.methodSuccess(event);
    return TRUE;
}
gboolean
NetAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event,
                 gpointer user_data)
{
    if (event.getType() != qmf::AGENT_METHOD) {
        return TRUE;
    }

    const std::string& methodName(event.getMethodName());
    qpid::types::Variant::Map& args = event.getArguments();

    if (methodName == "list") {
        GList *plist = NULL;
        GList *interface_list = NULL;

        _qtype::Variant::List s_list;

        interface_list = mh_network_get_interfaces();
        for (plist = g_list_first(interface_list); plist;
             plist = g_list_next(plist)) {
            struct mh_network_interface *iface =
                        static_cast<struct mh_network_interface *>(plist->data);
            s_list.push_back(mh_network_interface_get_name(iface));
        }
        g_list_free_full(interface_list, mh_network_interface_destroy);
        event.addReturnArgument("iface_map", s_list);
    } else if (methodName == "start") {
        int rc = interface_status(
                args["iface"].asString().c_str());

        if (rc == 1) {
            mh_network_start(args["iface"].asString().c_str());
            rc = interface_status(
                    args["iface"].asString().c_str());
        }
        event.addReturnArgument("status", rc);
    } else if (methodName == "stop") {
        int rc = interface_status(
                args["iface"].asString().c_str());
        if (rc == 0) {
            mh_network_stop(args["iface"].asString().c_str());
            rc = interface_status(
                    args["iface"].asString().c_str());
        }
        event.addReturnArgument("status", rc);
    } else if (methodName == "status") {
        event.addReturnArgument("status", interface_status(
                args["iface"].asString().c_str()));
    } else if (methodName == "get_ip_address") {
        char buf[64];
        event.addReturnArgument("ip", mh_network_get_ip_address(
                args["iface"].asString().c_str(),
                buf, sizeof(buf)));
    } else if (methodName == "get_mac_address") {
        char buf[32];
        event.addReturnArgument("mac", mh_network_get_mac_address(
                args["iface"].asString().c_str(),
                buf, sizeof(buf)));
    } else {
        session.raiseException(event, mh_result_to_str(MH_RES_NOT_IMPLEMENTED));
        goto bail;
    }

    session.methodSuccess(event);

bail:
    return TRUE;
}