From: Adam Stokes <astokes(a)fedoraproject.org>
Sigh... this actually contains the rest of the code I didn't add during the merge
- Config agent will provide a method for telling the Console agent if it was configured or
not. At this time it creates a file /tmp/.mh_configured and tests if this file exists and
responds accordingly.
- Console agent monitors when an Agent connects and will query that agent to make sure it
is of class: Config under package:org.matahariproject. If that is the case it will then
invoke the method configure on the agent which provides the above response.
Pretty straight forward and we can expand on arguements or other methods if needed.
Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
---
src/CMakeLists.txt | 2 +
src/config/CMakeLists.txt | 20 +++++++
src/config/config-qmf.cpp | 99 ++++++++++++++++++++++++++++++++
src/console/CMakeLists.txt | 18 ++++++
src/console/matahari-console.cpp | 84 +++++++++++++++++++++++++++
src/include/matahari/mh_agent_config.h | 33 +++++++++++
src/lib/CMakeLists.txt | 6 ++-
src/lib/mh_agent_config.c | 48 +++++++++++++++
src/schema.xml | 12 +++-
9 files changed, 319 insertions(+), 3 deletions(-)
create mode 100644 src/config/CMakeLists.txt
create mode 100644 src/config/config-qmf.cpp
create mode 100644 src/console/CMakeLists.txt
create mode 100644 src/console/matahari-console.cpp
create mode 100644 src/include/matahari/mh_agent_config.h
create mode 100644 src/lib/mh_agent_config.c
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b55f339..dfc2fa6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -117,6 +117,8 @@ add_subdirectory(lib)
add_subdirectory(host)
add_subdirectory(network)
add_subdirectory(service)
+add_subdirectory(console)
+add_subdirectory(config)
### Installation
install(FILES ${SCHEMAS} DESTINATION share/matahari)
diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt
new file mode 100644
index 0000000..8e4f810
--- /dev/null
+++ b/src/config/CMakeLists.txt
@@ -0,0 +1,20 @@
+set(BASE "config")
+set(BASE_LIB "m${BASE}")
+set(QMF_AGENT "matahari-qmf-${BASE}d")
+
+# QMF daemon
+if(WITH-QMF)
+ add_executable(${QMF_AGENT} ${BASE}-qmf.cpp ${SCHEMA_SOURCES})
+ target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon mcommon_qmf)
+
+ target_link_libraries(${QMF_AGENT} ${QPIDCOMMON_LIBRARY} ${QPIDCLIENT_LIBRARY}
${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ if(QPIDTYPES_LIBRARY)
+ target_link_libraries(${QMF_AGENT} ${QPIDTYPES_LIBRARY})
+ endif(QPIDTYPES_LIBRARY)
+
+ if(WIN32)
+ target_link_libraries(${QMF_AGENT} wsock32)
+ endif(WIN32)
+
+ install(TARGETS ${QMF_AGENT} DESTINATION sbin)
+endif(WITH-QMF)
diff --git a/src/config/config-qmf.cpp b/src/config/config-qmf.cpp
new file mode 100644
index 0000000..bf8963c
--- /dev/null
+++ b/src/config/config-qmf.cpp
@@ -0,0 +1,99 @@
+/* config-qmf.cpp - Copyright (C) 2011 Red Hat, Inc.
+ * Written by Adam Stokes <astokes(a)fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include "matahari/mh_agent.h"
+
+#include "qmf/org/matahariproject/QmfPackage.h"
+
+#include <qpid/agent/ManagementAgent.h>
+
+extern "C" {
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include "matahari/mh_agent_config.h"
+#include "matahari/logging.h"
+#include "matahari/network.h"
+#include "matahari/host.h"
+#include <sigar.h>
+#include <sigar_format.h>
+};
+
+class ConfigAgent : public MatahariAgent
+{
+private:
+ qmf::org::matahariproject::PackageDefinition _package;
+public:
+ virtual int setup(qmf::AgentSession session);
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
+};
+
+int
+main(int argc, char **argv)
+{
+ ConfigAgent agent;
+ int rc = agent.init(argc, argv, "Config");
+ if (rc == 0) {
+ agent.run();
+ }
+ return rc;
+}
+
+int
+ConfigAgent::setup(qmf::AgentSession session)
+{
+ _package.configure(session);
+ _instance = qmf::Data(_package.data_Config);
+
+ _instance.setProperty("hostname", mh_hostname());
+ _instance.setProperty("uuid", mh_uuid());
+ _instance.setProperty("configured", mh_is_configured());
+
+ _agent_session.addData(_instance);
+ return 0;
+}
+
+gboolean
+ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer
user_data)
+{
+ if (event.getType() != qmf::AGENT_METHOD) {
+ session.methodSuccess(event);
+ return TRUE;
+ }
+
+ const std::string& methodName(event.getMethodName());
+
+ if (methodName == "configure") {
+ int rc = mh_is_configured();
+ event.addReturnArgument("configured", rc);
+ } else {
+ session.raiseException(event, MH_NOT_IMPLEMENTED);
+ goto bail;
+ }
+
+ session.methodSuccess(event);
+
+bail:
+ return TRUE;
+}
diff --git a/src/console/CMakeLists.txt b/src/console/CMakeLists.txt
new file mode 100644
index 0000000..31645ff
--- /dev/null
+++ b/src/console/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(CONSOLE_QMF "matahari-qmf-consoled")
+
+# QMF daemon
+if(WITH-QMF)
+ add_executable(${CONSOLE_QMF} matahari-console.cpp)
+ target_link_libraries(${CONSOLE_QMF} mcommon mcommon_qmf)
+
+ target_link_libraries(${CONSOLE_QMF} ${QPIDCOMMON_LIBRARY} ${QPIDCLIENT_LIBRARY}
${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ if(QPIDTYPES_LIBRARY)
+ target_link_libraries(${CONSOLE_QMF} ${QPIDTYPES_LIBRARY})
+ endif(QPIDTYPES_LIBRARY)
+
+ if(WIN32)
+ target_link_libraries(${CONSOLE_QMF} wsock32)
+ endif(WIN32)
+
+ install(TARGETS ${CONSOLE_QMF} DESTINATION sbin)
+endif(WITH-QMF)
diff --git a/src/console/matahari-console.cpp b/src/console/matahari-console.cpp
new file mode 100644
index 0000000..5b0cf15
--- /dev/null
+++ b/src/console/matahari-console.cpp
@@ -0,0 +1,84 @@
+/* matahari-console.cpp - Copyright (c) 2011 Red Hat, Inc.
+ * Written by Adam Stokes <astokes(a)fedoraproject.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include <qpid/messaging/Connection.h>
+#include <qpid/messaging/Duration.h>
+#include <qmf/ConsoleSession.h>
+#include <qmf/ConsoleEvent.h>
+#include <qmf/Agent.h>
+#include <qmf/Data.h>
+#include <qmf/DataAddr.h>
+#include <qmf/Query.h>
+#include <qpid/types/Variant.h>
+
+#include "qmf/org/matahariproject/QmfPackage.h"
+
+#include <string>
+#include <iostream>
+
+using namespace std;
+using namespace qmf;
+using qpid::types::Variant;
+using qpid::messaging::Duration;
+
+int main(int argc, char** argv)
+{
+ string url("amqp:tcp:127.0.0.1:49000");
+ const string methodName("configure");
+ qpid::types::Variant::Map connectionOptions;
+ qpid::types::Variant::Map dataProperties;
+ string sessionOptions;
+
+ connectionOptions["reconnect"] = false;
+
+ qpid::messaging::Connection connection(url, connectionOptions);
+ connection.open();
+
+ ConsoleSession session(connection, sessionOptions);
+ session.open();
+
+ Agent agent;
+ while (true) {
+ ConsoleEvent event;
+ if(session.nextEvent(event)) {
+ switch(event.getType()) {
+ case CONSOLE_AGENT_ADD:
+ {
+ cout << "Agent added : " <<
event.getAgent().getName() << endl;
+ agent = event.getAgent();
+ ConsoleEvent result(agent.query("{class:Config,
package:'org.matahariproject'}"));
+ if(result.getDataCount() == 1) {
+ const Data& data(result.getData(0));
+ dataProperties = data.getProperties();
+ cout << "data : " << dataProperties
<< endl;
+ ConsoleEvent result(agent.callMethod(methodName,
dataProperties, data.getAddr(), qpid::messaging::Duration(4000)));
+ } else {
+ cout << "No objects in query" << endl;
+ }
+ }
+ break;
+ default: {}
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/include/matahari/mh_agent_config.h
b/src/include/matahari/mh_agent_config.h
new file mode 100644
index 0000000..2e21fe7
--- /dev/null
+++ b/src/include/matahari/mh_agent_config.h
@@ -0,0 +1,33 @@
+/* host.h - Copyright (C) 2009 Red Hat, Inc.
+ * Written by Arjun Roy <arroy(a)redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * \file
+ * \brief Config API
+ * \ingroup coreapi
+ */
+
+#ifndef __MH_CONFIG_H__
+#define __MH_CONFIG_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+
+extern uint32_t mh_is_configured(void);
+
+#endif // __MH_CONFIG_H__
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 2538517..38485d3 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -1,6 +1,6 @@
# Library
-set(LIBS mcommon mhost mnetwork mservice)
+set(LIBS mcommon mhost mnetwork mservice mconfig)
include_directories(${pcre_INCLUDE_DIRS})
add_library (mcommon SHARED utilities.c mainloop.c)
@@ -19,6 +19,10 @@ add_library (mservice SHARED services.c services_${VARIANT}.c)
set_target_properties(mservice PROPERTIES SOVERSION 0.0.1)
target_link_libraries(mservice ${pcre_LIBRARIES} mcommon ${SIGAR} ${glib_LIBRARIES})
+add_library (mconfig SHARED mh_agent_config.c)
+set_target_properties(mconfig PROPERTIES SOVERSION 0.0.1)
+target_link_libraries(mconfig ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
+
if(WIN32)
foreach (lib ${LIBS})
target_link_libraries(${lib} wsock32)
diff --git a/src/lib/mh_agent_config.c b/src/lib/mh_agent_config.c
new file mode 100644
index 0000000..a38b5c0
--- /dev/null
+++ b/src/lib/mh_agent_config.c
@@ -0,0 +1,48 @@
+/* mh_agent_config.c - Copyright (C) 2011 Red Hat, Inc.
+ * Written by Adam Stokes <astokes(a)fedoraproject.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include "matahari/mh_agent_config.h"
+#include "matahari/logging.h"
+
+MH_TRACE_INIT_DATA(mh_config);
+
+uint32_t mh_is_configured(void)
+{
+ int config_file_exist = 0;
+ const char *filename = "/tmp/.mh_configured";
+ const char *contents = "I've been configured.";
+
+ if(!g_file_test(filename, G_FILE_TEST_EXISTS)) {
+ if(!g_file_set_contents(filename, contents, -1, NULL)) {
+ mh_log(LOG_DEBUG, "Unable to create file.");
+ }
+ config_file_exist = 1;
+ } else {
+ config_file_exist = 1;
+ }
+ return config_file_exist;
+}
diff --git a/src/schema.xml b/src/schema.xml
index ea82e4f..8446490 100644
--- a/src/schema.xml
+++ b/src/schema.xml
@@ -90,7 +90,7 @@
<arg name="iface" dir="I" type="sstr"
/>
<arg name="status" dir="O" type="uint32"
/>
</method>
- <method name="get_ip_address" desc="Obtain ip addressof a network
interface">
+ <method name="get_ip_address" desc="Obtain ip address of a network
interface">
<arg name="iface" dir="I" type="sstr"
/>
<arg name="ip" dir="O" type="sstr"
/>
</method>
@@ -243,5 +243,13 @@
<arg name="timeout" dir="O" type="uint32"
/>
</method-->
</class>
-
+
+ <event name="configure_me" args="ip,sequence,timestamp" />
+
+ <class name="Config">
+ <property name="uuid" type="sstr" access="RO"
desc="Host UUID" />
+ <property name="hostname" type="sstr" access="RO"
desc="Hostname" index="y"/>
+ <property name="configured" type="uint32"
access="RO" desc="Am I configured?" />
+ <method name="configure" desc="Send configure method"
/>
+ </class>
</schema>
--
1.7.4.4