예제 #1
0
void
MatahariAgentImpl::registerAgent(void)
{
    qmf::Schema data_Agent(qmf::SCHEMA_TYPE_DATA,
                           "org.matahariproject", "Agent");
    {
        qmf::SchemaProperty prop("hostname", qmf::SCHEMA_DATA_STRING);
        prop.setAccess(qmf::ACCESS_READ_ONLY);
        prop.setIndex(true);
        prop.setDesc("Hostname");
        data_Agent.addProperty(prop);
    }
    {
        qmf::SchemaProperty prop("uuid", qmf::SCHEMA_DATA_STRING);
        prop.setAccess(qmf::ACCESS_READ_ONLY);
        prop.setIndex(true);
        prop.setDesc("Filesystem Host UUID");
        data_Agent.addProperty(prop);
    }

    _agent_session.registerSchema(data_Agent);

    _agent_instance = qmf::Data(data_Agent);
    _agent_instance.setProperty("uuid", mh_uuid());
    _agent_instance.setProperty("hostname", mh_hostname());
    _agent_session.addData(_agent_instance);
}
예제 #2
0
int
SrvAgent::setup(qmf::AgentSession session)
{
#ifdef __linux__
    standards.push_back("ocf");
#endif
    standards.push_back("lsb");
#ifndef WIN32
    standards.push_back("windows");
#endif

    _package.configure(session);

    _services = qmf::Data(_package.data_Services);

    _services.setProperty("uuid", mh_uuid());
    _services.setProperty("hostname", mh_hostname());

    session.addData(_services, "Services");

    _resources = qmf::Data(_package.data_Resources);

    _resources.setProperty("uuid", mh_uuid());
    _resources.setProperty("hostname", mh_hostname());

    session.addData(_resources, "Resources");

    return 0;
}
예제 #3
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;
}
int
NetAgent::setup(qmf::AgentSession session)
{
    _package.configure(session);
    _instance = qmf::Data(_package.data_Network);

    _instance.setProperty("hostname", mh_hostname());
    _instance.setProperty("uuid", mh_uuid());

    session.addData(_instance, NETWORK_NAME);
    return 0;
}
예제 #5
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;
}
예제 #6
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;
}
예제 #8
0
void
MatahariObject::withdraw(qmf::AgentSession& session)
{
    mh_debug("Withdrawing object %s", getAddr().getName().c_str());
    session.delData(getAddr());
}
예제 #9
0
void
MatahariObject::publish(qmf::AgentSession& session)
{
    session.addData(_instance);
    mh_debug("Published object %s", getAddr().getName().c_str());
}