- Full patch with all mentioned changes from ML
Signed-off-by: Adam Stokes astokes@fedoraproject.org --- matahari.spec | 40 ++++---- src/CMakeLists.txt | 2 +- src/include/matahari/mh_agent.h | 3 + src/include/matahari/postboot.h | 34 ------- src/include/matahari/sysconfig.h | 36 ++++++++ src/lib/CMakeLists.txt | 13 ++-- src/lib/postboot.c | 50 ----------- src/lib/sysconfig_linux.c | 148 +++++++++++++++++++++++++++++++ src/postboot/CMakeLists.txt | 30 ------- src/postboot/postboot-console.cpp | 79 ----------------- src/postboot/postboot-qmf.cpp | 101 --------------------- src/postboot/schema.xml | 16 ---- src/sysconfig/CMakeLists.txt | 30 +++++++ src/sysconfig/schema.xml | 35 ++++++++ src/sysconfig/sysconfig-console.cpp | 96 ++++++++++++++++++++ src/sysconfig/sysconfig-qmf.cpp | 163 +++++++++++++++++++++++++++++++++++ src/tests/CMakeLists.txt | 6 +- src/tests/mh_api_postboot.h | 34 ------- src/tests/mh_api_sysconfig.h | 34 +++++++ 19 files changed, 576 insertions(+), 374 deletions(-) delete mode 100644 src/include/matahari/postboot.h create mode 100644 src/include/matahari/sysconfig.h delete mode 100644 src/lib/postboot.c create mode 100644 src/lib/sysconfig_linux.c delete mode 100644 src/postboot/CMakeLists.txt delete mode 100644 src/postboot/postboot-console.cpp delete mode 100644 src/postboot/postboot-qmf.cpp delete mode 100644 src/postboot/schema.xml create mode 100644 src/sysconfig/CMakeLists.txt create mode 100644 src/sysconfig/schema.xml create mode 100644 src/sysconfig/sysconfig-console.cpp create mode 100644 src/sysconfig/sysconfig-qmf.cpp delete mode 100644 src/tests/mh_api_postboot.h create mode 100644 src/tests/mh_api_sysconfig.h
diff --git a/matahari.spec b/matahari.spec index 49f9eca..29703cf 100644 --- a/matahari.spec +++ b/matahari.spec @@ -128,14 +128,14 @@ Requires: %{name}-agent-lib = %{version}-%{release} %description service QMF agent for viewing and controlling system services
-%package postboot +%package sysconfig License: GPLv2+ Summary: QMF agent for post boot configuration services. Group: Applications/System Requires: %{name}-lib = %{version}-%{release} Requires: %{name}-agent-lib = %{version}-%{release}
-%description postboot +%description sysconfig QMF agent/console for providing post boot capabilities.
%package devel @@ -234,24 +234,24 @@ if [ "$1" -ge "1" ]; then /sbin/service matahari-service condrestart >/dev/null 2>&1 || : fi
-#== Postboot +#== sysconfig
-%post postboot -/sbin/service matahari-postboot condrestart -/sbin/service matahari-postboot-console condrestart +%post sysconfig +/sbin/service matahari-sysconfig condrestart +/sbin/service matahari-sysconfig-console condrestart
-%preun postboot +%preun sysconfig if [ $1 = 0 ]; then - /sbin/service matahari-postboot-console stop >/dev/null 2>&1 || : - /sbin/service matahari-postboot stop >/dev/null 2>&1 || : - chkconfig --del matahari-postboot-console - chkconfig --del matahari-postboot + /sbin/service matahari-sysconfig-console stop >/dev/null 2>&1 || : + /sbin/service matahari-sysconfig stop >/dev/null 2>&1 || : + chkconfig --del matahari-sysconfig-console + chkconfig --del matahari-sysconfig fi
-%postun postboot +%postun sysconfig if [ "$1" -ge "1" ]; then - /sbin/service matahari-postboot-console condrestart >/dev/null 2>&1 || : - /sbin/service matahari-postboot condrestart >/dev/null 2>&1 || : + /sbin/service matahari-sysconfig-console condrestart >/dev/null 2>&1 || : + /sbin/service matahari-sysconfig condrestart >/dev/null 2>&1 || : fi
#== Broker @@ -299,7 +299,7 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot} %{_libdir}/libmhost.so.* %{_libdir}/libmnetwork.so.* %{_libdir}/libmservice.so.* -%{_libdir}/libmpostboot.so.* +%{_libdir}/libmsysconfig.so.* %doc AUTHORS COPYING
%files network @@ -342,15 +342,15 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot} %attr(755, root, root) %{_sbindir}/matahari-dbus-serviced %endif
-%files postboot +%files sysconfig %defattr(644, root, root, 755) %doc AUTHORS COPYING
%if %{with qmf} -%attr(755, root, root) %{_initddir}/matahari-postboot -%attr(755, root, root) %{_initddir}/matahari-postboot-console -%attr(755, root, root) %{_sbindir}/matahari-qmf-postbootd -%attr(755, root, root) %{_sbindir}/matahari-qmf-postboot-consoled +%attr(755, root, root) %{_initddir}/matahari-sysconfig +%attr(755, root, root) %{_initddir}/matahari-sysconfig-console +%attr(755, root, root) %{_sbindir}/matahari-qmf-sysconfigd +%attr(755, root, root) %{_sbindir}/matahari-qmf-sysconfig-consoled %endif
%if %{with qmf} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 227e89c..50b3ea7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,7 +138,7 @@ add_subdirectory(lib) add_subdirectory(host) add_subdirectory(network) add_subdirectory(service) -add_subdirectory(postboot) +add_subdirectory(sysconfig) add_subdirectory(tests)
### Installation diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h index 5b6c8a3..275e090 100644 --- a/src/include/matahari/mh_agent.h +++ b/src/include/matahari/mh_agent.h @@ -47,6 +47,9 @@ int required_argument = 1;
#define MH_NOT_IMPLEMENTED "Not implemented"
+#ifndef NS_MAXDNAME +# define NS_MAXDNAME 1025 +#endif using namespace qpid::management; using namespace std;
diff --git a/src/include/matahari/postboot.h b/src/include/matahari/postboot.h deleted file mode 100644 index b2b79e0..0000000 --- a/src/include/matahari/postboot.h +++ /dev/null @@ -1,34 +0,0 @@ -/* postboot.h - Copyright (C) 2011 Red Hat, Inc. - * Written by Adam Stokes astokes@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 - */ - -/** - * \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(); -extern void mh_configure(const char *uri); - -#endif // __MH_CONFIG_H__ diff --git a/src/include/matahari/sysconfig.h b/src/include/matahari/sysconfig.h new file mode 100644 index 0000000..9359123 --- /dev/null +++ b/src/include/matahari/sysconfig.h @@ -0,0 +1,36 @@ +/* sysconfig.h - Copyright (C) 2011 Red Hat, Inc. + * Written by Adam Stokes astokes@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 + */ + +/** + * \file + * \brief Config API + * \ingroup coreapi + */ + +#ifndef __MH_SYSCONFIG_H__ +#define __MH_SYSCONFIG_H__ + +#include <stdint.h> +// Supported FLAGS +#define SYSCONFIG_FLAG_FORCE (1 << 0) + +extern int mh_sysconfig_run_uri(const char *uri, uint32_t flags, const char *scheme); +extern int mh_sysconfig_run_string(const char *string, uint32_t flags, const char *scheme); +extern int mh_sysconfig_query(const char *query, const char *data, + uint32_t flags, const char *scheme); +#endif // __MH_SYSCONFIG_H__ diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index cf37cf3..f7e38ba 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,6 +1,6 @@ # Library
-set(LIBS mcommon mhost mnetwork mservice mpostboot) +set(LIBS mcommon mhost mnetwork mservice msysconfig) include_directories(${pcre_INCLUDE_DIRS})
# See http://sourceware.org/autobook/autobook/autobook_91.html for @@ -8,7 +8,7 @@ include_directories(${pcre_INCLUDE_DIRS})
add_library (mcommon SHARED utilities.c mainloop.c dnssrv_${VARIANT}.c) set_target_properties(mcommon PROPERTIES SOVERSION 1.0.0) -target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES} resolv) +target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES})
add_library (mhost SHARED host.c host_${VARIANT}.c) set_target_properties(mhost PROPERTIES SOVERSION 1.0.0) @@ -22,9 +22,9 @@ add_library (mservice SHARED services.c services_${VARIANT}.c) set_target_properties(mservice PROPERTIES SOVERSION 1.0.0) target_link_libraries(mservice ${pcre_LIBRARIES} mcommon ${SIGAR} ${glib_LIBRARIES})
-add_library (mpostboot SHARED postboot.c) -set_target_properties(mpostboot PROPERTIES SOVERSION 1.0.0) -target_link_libraries(mpostboot ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES}) +add_library (msysconfig SHARED sysconfig_${VARIANT}.c) +set_target_properties(msysconfig PROPERTIES SOVERSION 1.0.0) +target_link_libraries(msysconfig ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
if(WIN32) foreach (lib ${LIBS}) @@ -33,7 +33,8 @@ if(WIN32) endforeach (lib ${LIBS}) else(WIN32) foreach (lib ${LIBS}) - install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX}) + target_link_libraries(${lib} resolv curl) + install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX}) endforeach (lib ${LIBS}) endif(WIN32)
diff --git a/src/lib/postboot.c b/src/lib/postboot.c deleted file mode 100644 index 6f970fa..0000000 --- a/src/lib/postboot.c +++ /dev/null @@ -1,50 +0,0 @@ -/* postboot.c - Copyright (C) 2011 Red Hat, Inc. - * Written by Adam Stokes astokes@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" -#include <stddef.h> -#endif - -#include <stdint.h> -#include <stdio.h> -#include <glib.h> -#include "matahari/logging.h" -#include "matahari/postboot.h" - - -MH_TRACE_INIT_DATA(mh_postboot); - -static const char *filename = "/var/lib/matahari/.mh_configured"; - -uint32_t mh_is_configured() -{ - int config_file_exist = 0; - - if(g_file_test(filename, G_FILE_TEST_EXISTS)) { - config_file_exist = 1; - } - return config_file_exist; -} - -void mh_configure(const char *uri) -{ - if(!g_file_set_contents(filename, uri, -1, NULL)) { - mh_log(LOG_DEBUG, "Unable to create file."); - } -} diff --git a/src/lib/sysconfig_linux.c b/src/lib/sysconfig_linux.c new file mode 100644 index 0000000..cd2b725 --- /dev/null +++ b/src/lib/sysconfig_linux.c @@ -0,0 +1,148 @@ +/* sysconfig_linux.c - Copyright (C) 2011 Red Hat, Inc. + * Written by Adam Stokes astokes@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" +#include <stddef.h> +#endif + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <glib.h> +#include <curl/curl.h> +#include "matahari/logging.h" +#include "matahari/sysconfig.h" +#include "matahari/utilities.h" + + +MH_TRACE_INIT_DATA(mh_sysconfig); + +static int +download(const char *uri, FILE *fp) +{ + CURL *curl; + CURLcode res; + + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); + if (curl) { + curl_easy_setopt(curl, CURLOPT_URL, uri); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); + res = curl_easy_perform(curl); + + if (CURLE_OK != res) { + return -1; + } + } + curl_global_cleanup(); + return 0; +} + + +static int +mh_sysconfig_run_puppet(const char *uri, const char *data) +{ + gboolean ret; + GError *error; + char *filename = NULL; + gchar cmd[PATH_MAX]; + int fd; + FILE *fp; + + if (uri != NULL) { + filename = strdup("puppet_conf_XXXXXX"); + fd = mkstemp(filename); + fp = fdopen(fd, "w+b"); + if ((download(uri, fp)) != 0) { + fclose(fp); + return -1; + } + fclose(fp); + } else if (data != NULL) { + filename = strdup("puppet_conf_blob"); + g_file_set_contents(filename, data, strlen(data), NULL); + } else { + return -1; + } + + g_snprintf(cmd, sizeof(cmd), "puppet %s", filename); + fprintf(stderr, "%s", cmd); + ret = g_spawn_async(NULL, (gchar **)cmd, NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, &error); + fprintf(stderr, "bool: %d", ret); + if (ret == FALSE) { + g_error_free(error); + free(filename); + return -1; + } + + free(filename); + + return 0; +} + +static int +mh_sysconfig_run_augeas(const char *query, const char *data) +{ + fprintf(stderr, "not implemented\n"); + return 0; +} + +static int +mh_sysconfig_query_augeas(const char *query, const char *data) +{ + fprintf(stderr, "not implemented\n"); + return 0; +} + +int +mh_sysconfig_run_uri(const char *uri, uint32_t flags, const char *scheme) { + int rc = 0; + + if (g_strcmp0(scheme, "puppet") == 0) { + rc = mh_sysconfig_run_puppet(uri, NULL); + } else { + rc = -1; + } + return rc; +} + +int +mh_sysconfig_run_string(const char *data, uint32_t flags, const char *scheme) { + int rc = 0; + + if (g_strcmp0(scheme, "puppet") == 0) { + rc = mh_sysconfig_run_puppet(NULL, data); + } else { + rc = -1; + } + return rc; +} + +int +mh_sysconfig_query(const char *query, const char *data, uint32_t flags, const char *scheme) { + int rc = 0; + + if (g_strcmp0(scheme, "augeas") == 0) { + rc = mh_sysconfig_run_augeas(query, data); + } else { + rc = -1; + } + return rc; +} diff --git a/src/postboot/CMakeLists.txt b/src/postboot/CMakeLists.txt deleted file mode 100644 index 36d59a1..0000000 --- a/src/postboot/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(BASE "postboot") -set(BASE_LIB "m${BASE}") -set(QMF_AGENT "matahari-qmf-${BASE}d") -set(QMF_CONSOLE "matahari-qmf-${BASE}-consoled") - -# QMF daemon -if(WITH-QMF) - set(SCHEMA_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/QmfPackage.cpp) - generate_qmf_schemas(${CMAKE_CURRENT_SOURCE_DIR}/schema.xml ${SCHEMA_SOURCES}) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - - add_executable(${QMF_AGENT} ${BASE}-qmf.cpp ${SCHEMA_SOURCES}) - add_executable(${QMF_CONSOLE} ${BASE}-console.cpp) - - target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon_qmf) - target_link_libraries(${QMF_CONSOLE} mcommon_qmf) - - if(NOT WIN32) - configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE}) - install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir}) - # Override BASE for matahari-postboot-console - unset(BASE) - set(BASE "postboot-console") - configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE}) - install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir}) - endif(NOT WIN32) - - install(TARGETS ${QMF_AGENT} DESTINATION sbin) - install(TARGETS ${QMF_CONSOLE} DESTINATION sbin) -endif(WITH-QMF) diff --git a/src/postboot/postboot-console.cpp b/src/postboot/postboot-console.cpp deleted file mode 100644 index 188c443..0000000 --- a/src/postboot/postboot-console.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* config-console.cpp - Copyright (c) 2011 Red Hat, Inc. - * Written by Adam Stokes astokes@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 <string> -#include <iostream> - -using namespace std; -using namespace qmf; -using qpid::types::Variant; -using qpid::messaging::Duration; - -int main(int argc, char** argv) -{ - string brokerUrl("amqp:tcp:127.0.0.1:49000"); - qpid::types::Variant::Map connectionOptions; - qpid::types::Variant::Map dataProperties; - string sessionOptions; - - connectionOptions["reconnect"] = true; - - dataProperties["uri"] = argv[1] ? argv[1] : "http://localhost/config/uuid"; - - qpid::messaging::Connection connection(brokerUrl, connectionOptions); - connection.open(); - - ConsoleSession session(connection, sessionOptions); - // Only filter connecting agents under matahariproject.org vendor and Config product - session.setAgentFilter("[and, [eq, _vendor, [quote, 'matahariproject.org']], [eq, _product, [quote, 'Config']]]"); - session.open(); - - Agent agent; - while (true) { - ConsoleEvent event; - if(session.nextEvent(event)) { - switch(event.getType()) { - case CONSOLE_AGENT_ADD: - { - agent = event.getAgent(); - DataAddr agent_event_addr("config", agent.getName(), 0); - ConsoleEvent result(agent.callMethod("configure", - dataProperties, - agent_event_addr)); - } - break; - default: {} - } - } - } - return 0; -} diff --git a/src/postboot/postboot-qmf.cpp b/src/postboot/postboot-qmf.cpp deleted file mode 100644 index 7058276..0000000 --- a/src/postboot/postboot-qmf.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* config-qmf.cpp - Copyright (C) 2011 Red Hat, Inc. - * Written by Adam Stokes astokes@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/postboot.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_Postboot); - - _instance.setProperty("hostname", mh_hostname()); - _instance.setProperty("uuid", mh_uuid()); - _instance.setProperty("is_configured", mh_is_configured()); - - _agent_session.addData(_instance, "postboot"); - return 0; -} - -gboolean -ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) -{ - if (event.getType() != qmf::AGENT_METHOD) { - return TRUE; - } - - const std::string& methodName(event.getMethodName()); - - if (methodName == "configure") { - int rc = mh_is_configured(); - if(rc == 0) { - mh_configure(event.getArguments()["uri"].asString().c_str()); - } - event.addReturnArgument("configured", rc); - } else { - session.raiseException(event, MH_NOT_IMPLEMENTED); - goto bail; - } - - session.methodSuccess(event); - -bail: - return TRUE; -} diff --git a/src/postboot/schema.xml b/src/postboot/schema.xml deleted file mode 100644 index 2d930ce..0000000 --- a/src/postboot/schema.xml +++ /dev/null @@ -1,16 +0,0 @@ -<schema package="org.matahariproject"> - - <!-- Config API --> - <class name="Postboot"> - <property name="uuid" type="sstr" access="RO" desc="Host UUID" /> - <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/> - <property name="is_configured" type="uint32" access="RO" desc="Check if agent is configured." /> - - <statistic name="qmf-gen-no-crash" type="absTime" desc="Dummy stat to stop qmf-gen from crashing." /> - - <method name="configure" desc="Send configure method"> - <arg name="uri" dir="I" type="sstr" /> - <arg name="configured" dir="O" type="uint32" /> - </method> - </class> -</schema> diff --git a/src/sysconfig/CMakeLists.txt b/src/sysconfig/CMakeLists.txt new file mode 100644 index 0000000..1d9fba8 --- /dev/null +++ b/src/sysconfig/CMakeLists.txt @@ -0,0 +1,30 @@ +set(BASE "sysconfig") +set(BASE_LIB "m${BASE}") +set(QMF_AGENT "matahari-qmf-${BASE}d") +set(QMF_CONSOLE "matahari-qmf-${BASE}-consoled") + +# QMF daemon +if(WITH-QMF) + set(SCHEMA_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/QmfPackage.cpp) + generate_qmf_schemas(${CMAKE_CURRENT_SOURCE_DIR}/schema.xml ${SCHEMA_SOURCES}) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + + add_executable(${QMF_AGENT} ${BASE}-qmf.cpp ${SCHEMA_SOURCES}) + add_executable(${QMF_CONSOLE} ${BASE}-console.cpp) + + target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon_qmf) + target_link_libraries(${QMF_CONSOLE} mcommon_qmf) + + if(NOT WIN32) + configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE}) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir}) + # Override BASE for matahari-sysconfig-console + unset(BASE) + set(BASE "sysconfig-console") + configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE}) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir}) + endif(NOT WIN32) + + install(TARGETS ${QMF_AGENT} DESTINATION sbin) + install(TARGETS ${QMF_CONSOLE} DESTINATION sbin) +endif(WITH-QMF) diff --git a/src/sysconfig/schema.xml b/src/sysconfig/schema.xml new file mode 100644 index 0000000..d5c52aa --- /dev/null +++ b/src/sysconfig/schema.xml @@ -0,0 +1,35 @@ +<schema package="org.matahariproject"> + + <!-- Config API --> + <class name="Sysconfig"> + <property name="uuid" type="sstr" access="RO" desc="Host UUID" /> + <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/> + <property name="is_postboot_configured" type="uint32" access="RO" desc="Check if agent is configured." /> + + <statistic name="qmf-gen-no-crash" type="absTime" desc="Dummy stat to stop qmf-gen from crashing." /> + + <method name="run_uri" desc="Send configure uri method"> + <arg name="uri" dir="I" type="sstr" /> + <arg name="scheme" dir="I" type="sstr" /> + <arg name="key" dir="I" type="sstr" /> + <arg name="flags" dir="I" type="uint32" /> + </method> + + <method name="run_string" desc="Send configure text method"> + <arg name="text" dir="I" type="sstr" /> + <arg name="scheme" dir="I" type="sstr" /> + <arg name="key" dir="I" type="sstr" /> + <arg name="flags" dir="I" type="uint32" /> + </method> + + <method name="query" desc="Perform query lookup"> + <arg name="text" dir="I" type="sstr" /> + <arg name="scheme" dir="I" type="sstr" /> + <arg name="flags" dir="I" type="uint32" /> + </method> + + <method name="is_configured" desc="Check if system is configured"> + <arg name="key" dir="I" type="sstr" /> + </method> + </class> +</schema> diff --git a/src/sysconfig/sysconfig-console.cpp b/src/sysconfig/sysconfig-console.cpp new file mode 100644 index 0000000..e294152 --- /dev/null +++ b/src/sysconfig/sysconfig-console.cpp @@ -0,0 +1,96 @@ +/* config-console.cpp - Copyright (c) 2011 Red Hat, Inc. + * Written by Adam Stokes astokes@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 <matahari/mh_agent.h> + +#include <string> +#include <iostream> +#include <sstream> + +extern "C" { +#include "matahari/logging.h" +} + +using namespace std; +using namespace qmf; +using qpid::types::Variant; +using qpid::messaging::Duration; + +int main(int argc, char** argv) +{ + qpid::types::Variant::Map options; + qpid::types::Variant::Map callOptions; + string sessionOptions; + ConsoleEvent event; + Agent agent; + + mh_log_init("sysconfig-console", LOG_TRACE, TRUE); + + mh_add_option('U', required_argument, "uri", "URI of configuration", &options, NULL); + + string url = mh_parse_options("sysconfig-console", argc, argv, options); + + callOptions["uri"] = options["uri"]; + + mh_log_init("sysconfig-console", mh_log_level, mh_log_level > LOG_INFO); + + qpid::messaging::Connection connection(url, options); + connection.open(); + + ConsoleSession session(connection, sessionOptions); + // Only filter connecting agents under matahariproject.org vendor and Config product + session.setAgentFilter("[and, [eq, _vendor, [quote, 'matahariproject.org']], [eq, _product, [quote, 'Sysconfig']]]"); + session.open(); + + while(session.getAgentCount() == 0) { + g_usleep(1000); + } + + while (true) { + if(session.nextEvent(event)) { + switch(event.getType()) { + case CONSOLE_AGENT_ADD: + { + agent = event.getAgent(); + DataAddr agent_event_addr("config", agent.getName(), 0); + ConsoleEvent result(agent.callMethod("configure", + callOptions, + agent_event_addr)); + } + break; + default: + break; + } + } + } + return 0; +} diff --git a/src/sysconfig/sysconfig-qmf.cpp b/src/sysconfig/sysconfig-qmf.cpp new file mode 100644 index 0000000..1cacd87 --- /dev/null +++ b/src/sysconfig/sysconfig-qmf.cpp @@ -0,0 +1,163 @@ +/* config-qmf.cpp - Copyright (C) 2011 Red Hat, Inc. + * Written by Adam Stokes astokes@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 + */ + +/** + * \file + * \brief Sysconfig QMF Agent + */ + +#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 <fcntl.h> +#include <glib.h> +#include <glib/gstdio.h> +#include <glib/gprintf.h> +#include "matahari/sysconfig.h" +#include "matahari/logging.h" +#include "matahari/network.h" +#include "matahari/host.h" +#include <sigar.h> +#include <sigar_format.h> +}; + +static const char *configured_fn = "/var/lib/matahari/.is_configured"; + +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, "Sysconfig"); + if (rc == 0) { + agent.run(); + } + return rc; +} + +int +ConfigAgent::setup(qmf::AgentSession session) +{ + _package.configure(session); + _instance = qmf::Data(_package.data_Sysconfig); + + _instance.setProperty("hostname", mh_hostname()); + _instance.setProperty("uuid", mh_uuid()); + _instance.setProperty("is_postboot_configured", 0); + + _agent_session.addData(_instance, "sysconfig"); + return 0; +} + +static void +set_configured() { + if(!g_file_test(configured_fn, G_FILE_TEST_EXISTS)) { + g_creat(configured_fn, S_IRWXU); + } +} + +static int +is_configured(uint32_t flags) { + + if(flags & SYSCONFIG_FLAG_FORCE) { + return 0; + } + + if(g_file_test(configured_fn, G_FILE_TEST_EXISTS)) { + return 1; + } + return 0; +} + +gboolean +ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) +{ + int rc = 0; + uint32_t flags; + + + if (event.getType() != qmf::AGENT_METHOD) { + return TRUE; + } + + const std::string& methodName(event.getMethodName()); + + if (methodName == "run_uri") { + flags = event.getArguments()["flags"].asInt32(); + if((is_configured(flags)) == 0) { + rc = mh_sysconfig_run_uri(event.getArguments()["uri"].asString().c_str(), + flags, + event.getArguments()["scheme"].asString().c_str()); + if (rc == 0) { + set_configured(); + } + } + event.addReturnArgument("configured", rc); + } else if (methodName == "run_string") { + flags = event.getArguments()["flags"].asInt32(); + if((is_configured(flags)) == 0) { + rc = mh_sysconfig_run_string(event.getArguments()["data"].asString().c_str(), + flags, + event.getArguments()["scheme"].asString().c_str()); + if (rc == 0) { + set_configured(); + } + } + event.addReturnArgument("configured", rc); + } else if (methodName == "query") { + flags = event.getArguments()["flags"].asInt32(); + if((is_configured(flags)) == 0) { + rc = mh_sysconfig_query(event.getArguments()["query"].asString().c_str(), + event.getArguments()["data"].asString().c_str(), + flags, + event.getArguments()["scheme"].asString().c_str()); + } + event.addReturnArgument("configured", rc); + } else if (methodName == "is_configured") { + rc = is_configured(0); + _instance.setProperty("is_postboot_configured", rc); + event.addReturnArgument("configured", rc); + } else { + session.raiseException(event, MH_NOT_IMPLEMENTED); + goto bail; + } + + session.methodSuccess(event); + +bail: + return TRUE; +} diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 6db157c..8fe81f2 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -5,13 +5,13 @@ if(CXXTEST_FOUND) ENABLE_TESTING() CXXTEST_ADD_TEST(mh_api_network_unittest network_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_network.h) CXXTEST_ADD_TEST(mh_api_host_unittest host_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_host.h) - CXXTEST_ADD_TEST(mh_api_postboot_unittest postboot_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_postboot.h) + CXXTEST_ADD_TEST(mh_api_sysconfig_unittest sysconfig_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_sysconfig.h) CXXTEST_ADD_TEST(mh_hsa_unittest hsa_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_hsa_${VARIANT}.h) add_library(mh_tester SHARED test_utilities.c) - target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost mpostboot) + target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost msysconfig) target_link_libraries(mh_api_network_unittest mh_tester) target_link_libraries(mh_api_host_unittest mh_tester) - target_link_libraries(mh_api_postboot_unittest mh_tester) + target_link_libraries(mh_api_sysconfig_unittest mh_tester) target_link_libraries(mh_hsa_unittest mh_tester) endif(CXXTEST_FOUND)
diff --git a/src/tests/mh_api_postboot.h b/src/tests/mh_api_postboot.h deleted file mode 100644 index 5e59a9b..0000000 --- a/src/tests/mh_api_postboot.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __MH_API_NETWORK_UNITTEST_H -#define __MH_API_NETWORK_UNITTEST_H -#include <iostream> -#include <string> -#include <sstream> -#include <utility> -#include <vector> -#include <cstdlib> -#include <cstdio> -#include <sys/stat.h> -#include <dirent.h> -#include <cxxtest/TestSuite.h> - -extern "C" { -#include "matahari/postboot.h" -#include <glib.h> -#include "mh_test_utilities.h" -}; - -using namespace std; - -class MhApiPostbootSuite : public CxxTest::TestSuite -{ - public: - - void testIsConfigured(void) - { - const char *uri = "http://matahariproject.org/testing.xml"; - mh_configure(uri); - TS_ASSERT((mh_is_configured()) == 1); - } -}; - -#endif diff --git a/src/tests/mh_api_sysconfig.h b/src/tests/mh_api_sysconfig.h new file mode 100644 index 0000000..a9a3ebc --- /dev/null +++ b/src/tests/mh_api_sysconfig.h @@ -0,0 +1,34 @@ +#ifndef __MH_API_NETWORK_UNITTEST_H +#define __MH_API_NETWORK_UNITTEST_H +#include <iostream> +#include <string> +#include <sstream> +#include <utility> +#include <vector> +#include <cstdlib> +#include <cstdio> +#include <sys/stat.h> +#include <dirent.h> +#include <cxxtest/TestSuite.h> + +extern "C" { +#include "matahari/sysconfig.h" +#include <glib.h> +#include "mh_test_utilities.h" +}; + +using namespace std; + +class MhApiSysconfigSuite : public CxxTest::TestSuite +{ + public: + + void testIsConfigured(void) + { + const char *uri = "http://matahariproject.org/atom.xml"; + uint32_t flags = 0; + TS_ASSERT((mh_sysconfig_run_uri(uri, flags, "puppet")) != -1); + } +}; + +#endif
Thanks Adam, this is looking great. (One probably inconsequential note below.) Note that since I pushed the patch to export all of the headers just now, there is are a couple of new places to change postboot.h -> sysconfig.h when you merge/rebase: in src/CMakeLists.txt and in matahari.spec.
cheers, Zane.
On 20/07/11 21:33, Adam Stokes wrote:
diff --git a/src/sysconfig/sysconfig-qmf.cpp b/src/sysconfig/sysconfig-qmf.cpp new file mode 100644 index 0000000..1cacd87 --- /dev/null +++ b/src/sysconfig/sysconfig-qmf.cpp @@ -0,0 +1,163 @@
<snip>
+gboolean +ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) +{
- int rc = 0;
- uint32_t flags;
- if (event.getType() != qmf::AGENT_METHOD) {
return TRUE;
- }
- const std::string& methodName(event.getMethodName());
- if (methodName == "run_uri") {
flags = event.getArguments()["flags"].asInt32();
I guess this should now be asUInt32().
if((is_configured(flags)) == 0) {
rc = mh_sysconfig_run_uri(event.getArguments()["uri"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
if (rc == 0) {
set_configured();
}
}
event.addReturnArgument("configured", rc);
- } else if (methodName == "run_string") {
flags = event.getArguments()["flags"].asInt32();
if((is_configured(flags)) == 0) {
rc = mh_sysconfig_run_string(event.getArguments()["data"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
if (rc == 0) {
set_configured();
}
}
event.addReturnArgument("configured", rc);
- } else if (methodName == "query") {
flags = event.getArguments()["flags"].asInt32();
Ditto.
if((is_configured(flags)) == 0) {
rc = mh_sysconfig_query(event.getArguments()["query"].asString().c_str(),
event.getArguments()["data"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
}
event.addReturnArgument("configured", rc);
- } else if (methodName == "is_configured") {
rc = is_configured(0);
_instance.setProperty("is_postboot_configured", rc);
event.addReturnArgument("configured", rc);
- } else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
- }
- session.methodSuccess(event);
+bail:
- return TRUE;
+}
Hey guys, I know I said I'd try to dig into this to understand the similarities and differences between the sysconfig agent and the Audrey Config Server and guest tooling.
Unfortunately, I've been bogged down the last several days trying to scope out some work between Conductor and Audrey. I still promise to take a look at this, but it might not be really soon.
---- Greg
On 07/20/2011 05:39 PM, Zane Bitter wrote:
Thanks Adam, this is looking great. (One probably inconsequential note below.) Note that since I pushed the patch to export all of the headers just now, there is are a couple of new places to change postboot.h -> sysconfig.h when you merge/rebase: in src/CMakeLists.txt and in matahari.spec.
cheers, Zane.
On 20/07/11 21:33, Adam Stokes wrote:
diff --git a/src/sysconfig/sysconfig-qmf.cpp b/src/sysconfig/sysconfig-qmf.cpp new file mode 100644 index 0000000..1cacd87 --- /dev/null +++ b/src/sysconfig/sysconfig-qmf.cpp @@ -0,0 +1,163 @@
<snip>
+gboolean +ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) +{
- int rc = 0;
- uint32_t flags;
- if (event.getType() != qmf::AGENT_METHOD) {
return TRUE;
- }
- const std::string& methodName(event.getMethodName());
- if (methodName == "run_uri") {
flags = event.getArguments()["flags"].asInt32();
I guess this should now be asUInt32().
if((is_configured(flags)) == 0) {
rc = mh_sysconfig_run_uri(event.getArguments()["uri"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
if (rc == 0) {
set_configured();
}
}
event.addReturnArgument("configured", rc);
- } else if (methodName == "run_string") {
flags = event.getArguments()["flags"].asInt32();
if((is_configured(flags)) == 0) {
rc = mh_sysconfig_run_string(event.getArguments()["data"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
if (rc == 0) {
set_configured();
}
}
event.addReturnArgument("configured", rc);
- } else if (methodName == "query") {
flags = event.getArguments()["flags"].asInt32();
Ditto.
if((is_configured(flags)) == 0) {
rc = mh_sysconfig_query(event.getArguments()["query"].asString().c_str(),
event.getArguments()["data"].asString().c_str(),
flags,
event.getArguments()["scheme"].asString().c_str());
}
event.addReturnArgument("configured", rc);
- } else if (methodName == "is_configured") {
rc = is_configured(0);
_instance.setProperty("is_postboot_configured", rc);
event.addReturnArgument("configured", rc);
- } else {
session.raiseException(event, MH_NOT_IMPLEMENTED);
goto bail;
- }
- session.methodSuccess(event);
+bail:
- return TRUE;
+}
Matahari mailing list Matahari@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/matahari
On Wed, Jul 20, 2011 at 2:33 PM, Adam Stokes astokes@fedoraproject.org wrote:
- Full patch with all mentioned changes from ML
Signed-off-by: Adam Stokes astokes@fedoraproject.org
matahari.spec | 40 ++++---- src/CMakeLists.txt | 2 +- src/include/matahari/mh_agent.h | 3 + src/include/matahari/postboot.h | 34 ------- src/include/matahari/sysconfig.h | 36 ++++++++ src/lib/CMakeLists.txt | 13 ++-- src/lib/postboot.c | 50 ----------- src/lib/sysconfig_linux.c | 148 +++++++++++++++++++++++++++++++ src/postboot/CMakeLists.txt | 30 ------- src/postboot/postboot-console.cpp | 79 ----------------- src/postboot/postboot-qmf.cpp | 101 --------------------- src/postboot/schema.xml | 16 ---- src/sysconfig/CMakeLists.txt | 30 +++++++ src/sysconfig/schema.xml | 35 ++++++++ src/sysconfig/sysconfig-console.cpp | 96 ++++++++++++++++++++ src/sysconfig/sysconfig-qmf.cpp | 163 +++++++++++++++++++++++++++++++++++ src/tests/CMakeLists.txt | 6 +- src/tests/mh_api_postboot.h | 34 ------- src/tests/mh_api_sysconfig.h | 34 +++++++ 19 files changed, 576 insertions(+), 374 deletions(-) delete mode 100644 src/include/matahari/postboot.h create mode 100644 src/include/matahari/sysconfig.h delete mode 100644 src/lib/postboot.c create mode 100644 src/lib/sysconfig_linux.c delete mode 100644 src/postboot/CMakeLists.txt delete mode 100644 src/postboot/postboot-console.cpp delete mode 100644 src/postboot/postboot-qmf.cpp delete mode 100644 src/postboot/schema.xml create mode 100644 src/sysconfig/CMakeLists.txt create mode 100644 src/sysconfig/schema.xml create mode 100644 src/sysconfig/sysconfig-console.cpp create mode 100644 src/sysconfig/sysconfig-qmf.cpp delete mode 100644 src/tests/mh_api_postboot.h create mode 100644 src/tests/mh_api_sysconfig.h
diff --git a/matahari.spec b/matahari.spec index 49f9eca..29703cf 100644 --- a/matahari.spec +++ b/matahari.spec @@ -128,14 +128,14 @@ Requires: %{name}-agent-lib = %{version}-%{release} %description service QMF agent for viewing and controlling system services
-%package postboot +%package sysconfig License: GPLv2+ Summary: QMF agent for post boot configuration services. Group: Applications/System Requires: %{name}-lib = %{version}-%{release} Requires: %{name}-agent-lib = %{version}-%{release}
-%description postboot +%description sysconfig QMF agent/console for providing post boot capabilities.
%package devel @@ -234,24 +234,24 @@ if [ "$1" -ge "1" ]; then /sbin/service matahari-service condrestart >/dev/null 2>&1 || : fi
-#== Postboot +#== sysconfig
-%post postboot -/sbin/service matahari-postboot condrestart -/sbin/service matahari-postboot-console condrestart +%post sysconfig +/sbin/service matahari-sysconfig condrestart +/sbin/service matahari-sysconfig-console condrestart
-%preun postboot +%preun sysconfig if [ $1 = 0 ]; then
- /sbin/service matahari-postboot-console stop >/dev/null 2>&1 || :
- /sbin/service matahari-postboot stop >/dev/null 2>&1 || :
- chkconfig --del matahari-postboot-console
- chkconfig --del matahari-postboot
- /sbin/service matahari-sysconfig-console stop >/dev/null 2>&1 || :
- /sbin/service matahari-sysconfig stop >/dev/null 2>&1 || :
- chkconfig --del matahari-sysconfig-console
- chkconfig --del matahari-sysconfig
fi
-%postun postboot +%postun sysconfig if [ "$1" -ge "1" ]; then
- /sbin/service matahari-postboot-console condrestart >/dev/null 2>&1 || :
- /sbin/service matahari-postboot condrestart >/dev/null 2>&1 || :
- /sbin/service matahari-sysconfig-console condrestart >/dev/null 2>&1 || :
- /sbin/service matahari-sysconfig condrestart >/dev/null 2>&1 || :
fi
#== Broker @@ -299,7 +299,7 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot} %{_libdir}/libmhost.so.* %{_libdir}/libmnetwork.so.* %{_libdir}/libmservice.so.* -%{_libdir}/libmpostboot.so.* +%{_libdir}/libmsysconfig.so.* %doc AUTHORS COPYING
%files network @@ -342,15 +342,15 @@ test "x%{buildroot}" != "x" && rm -rf %{buildroot} %attr(755, root, root) %{_sbindir}/matahari-dbus-serviced %endif
-%files postboot +%files sysconfig %defattr(644, root, root, 755) %doc AUTHORS COPYING
%if %{with qmf} -%attr(755, root, root) %{_initddir}/matahari-postboot -%attr(755, root, root) %{_initddir}/matahari-postboot-console -%attr(755, root, root) %{_sbindir}/matahari-qmf-postbootd -%attr(755, root, root) %{_sbindir}/matahari-qmf-postboot-consoled +%attr(755, root, root) %{_initddir}/matahari-sysconfig +%attr(755, root, root) %{_initddir}/matahari-sysconfig-console +%attr(755, root, root) %{_sbindir}/matahari-qmf-sysconfigd +%attr(755, root, root) %{_sbindir}/matahari-qmf-sysconfig-consoled %endif
%if %{with qmf} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 227e89c..50b3ea7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,7 +138,7 @@ add_subdirectory(lib) add_subdirectory(host) add_subdirectory(network) add_subdirectory(service) -add_subdirectory(postboot) +add_subdirectory(sysconfig) add_subdirectory(tests)
### Installation diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h index 5b6c8a3..275e090 100644 --- a/src/include/matahari/mh_agent.h +++ b/src/include/matahari/mh_agent.h @@ -47,6 +47,9 @@ int required_argument = 1;
#define MH_NOT_IMPLEMENTED "Not implemented"
+#ifndef NS_MAXDNAME +# define NS_MAXDNAME 1025 +#endif
Is this really related to the MatahariAgent class? Maybe it would be better in dnssrv.h.
using namespace qpid::management; using namespace std;
diff --git a/src/include/matahari/postboot.h b/src/include/matahari/postboot.h deleted file mode 100644 index b2b79e0..0000000 --- a/src/include/matahari/postboot.h +++ /dev/null @@ -1,34 +0,0 @@ -/* postboot.h - Copyright (C) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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
- */
-/**
- \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(); -extern void mh_configure(const char *uri);
-#endif // __MH_CONFIG_H__ diff --git a/src/include/matahari/sysconfig.h b/src/include/matahari/sysconfig.h new file mode 100644 index 0000000..9359123 --- /dev/null +++ b/src/include/matahari/sysconfig.h @@ -0,0 +1,36 @@ +/* sysconfig.h - Copyright (C) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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
- */
+/**
- \file
- \brief Config API
- \ingroup coreapi
- */
+#ifndef __MH_SYSCONFIG_H__ +#define __MH_SYSCONFIG_H__
+#include <stdint.h> +// Supported FLAGS
Doxygenize this comment. /*! ... */
+#define SYSCONFIG_FLAG_FORCE (1 << 0)
Add an MH_ prefix here. Also, I'd rather use an enum, but it's just a style preference, I guess.
enum { MH_SYSCONFIG_FLAG_FORCE = (1 << 0), };
+extern int mh_sysconfig_run_uri(const char *uri, uint32_t flags, const char *scheme); +extern int mh_sysconfig_run_string(const char *string, uint32_t flags, const char *scheme); +extern int mh_sysconfig_query(const char *query, const char *data,
- uint32_t flags, const char *scheme);
Doxygen docs on all public API calls would be ideal.
Also, there is some discussion on struct vs. individual parameters in another thread. I'm not sure how likely it is for other applications to consume this API, so I'm not sure it's worth extra work to be more aggressive about API/ABI stability ...
+#endif // __MH_SYSCONFIG_H__ diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index cf37cf3..f7e38ba 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,6 +1,6 @@ # Library
-set(LIBS mcommon mhost mnetwork mservice mpostboot) +set(LIBS mcommon mhost mnetwork mservice msysconfig) include_directories(${pcre_INCLUDE_DIRS})
# See http://sourceware.org/autobook/autobook/autobook_91.html for @@ -8,7 +8,7 @@ include_directories(${pcre_INCLUDE_DIRS})
add_library (mcommon SHARED utilities.c mainloop.c dnssrv_${VARIANT}.c) set_target_properties(mcommon PROPERTIES SOVERSION 1.0.0) -target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES} resolv) +target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES})
add_library (mhost SHARED host.c host_${VARIANT}.c) set_target_properties(mhost PROPERTIES SOVERSION 1.0.0) @@ -22,9 +22,9 @@ add_library (mservice SHARED services.c services_${VARIANT}.c) set_target_properties(mservice PROPERTIES SOVERSION 1.0.0) target_link_libraries(mservice ${pcre_LIBRARIES} mcommon ${SIGAR} ${glib_LIBRARIES})
-add_library (mpostboot SHARED postboot.c) -set_target_properties(mpostboot PROPERTIES SOVERSION 1.0.0) -target_link_libraries(mpostboot ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES}) +add_library (msysconfig SHARED sysconfig_${VARIANT}.c) +set_target_properties(msysconfig PROPERTIES SOVERSION 1.0.0) +target_link_libraries(msysconfig ${pcre_LIBRARIES} mcommon ${glib_LIBRARIES})
if(WIN32) foreach (lib ${LIBS}) @@ -33,7 +33,8 @@ if(WIN32) endforeach (lib ${LIBS}) else(WIN32) foreach (lib ${LIBS})
- install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX})
- target_link_libraries(${lib} resolv curl)
- install(TARGETS ${lib} DESTINATION lib${LIB_SUFFIX})
endforeach (lib ${LIBS}) endif(WIN32)
diff --git a/src/lib/postboot.c b/src/lib/postboot.c deleted file mode 100644 index 6f970fa..0000000 --- a/src/lib/postboot.c +++ /dev/null @@ -1,50 +0,0 @@ -/* postboot.c - Copyright (C) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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" -#include <stddef.h> -#endif
-#include <stdint.h> -#include <stdio.h> -#include <glib.h> -#include "matahari/logging.h" -#include "matahari/postboot.h"
-MH_TRACE_INIT_DATA(mh_postboot);
-static const char *filename = "/var/lib/matahari/.mh_configured";
-uint32_t mh_is_configured() -{
- int config_file_exist = 0;
- if(g_file_test(filename, G_FILE_TEST_EXISTS)) {
- config_file_exist = 1;
- }
- return config_file_exist;
-}
-void mh_configure(const char *uri) -{
- if(!g_file_set_contents(filename, uri, -1, NULL)) {
- mh_log(LOG_DEBUG, "Unable to create file.");
- }
-} diff --git a/src/lib/sysconfig_linux.c b/src/lib/sysconfig_linux.c new file mode 100644 index 0000000..cd2b725 --- /dev/null +++ b/src/lib/sysconfig_linux.c @@ -0,0 +1,148 @@ +/* sysconfig_linux.c - Copyright (C) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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" +#include <stddef.h> +#endif
+#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <glib.h> +#include <curl/curl.h> +#include "matahari/logging.h" +#include "matahari/sysconfig.h" +#include "matahari/utilities.h"
+MH_TRACE_INIT_DATA(mh_sysconfig);
+static int +download(const char *uri, FILE *fp) +{
- CURL *curl;
- CURLcode res;
- curl_global_init(CURL_GLOBAL_DEFAULT);
- curl = curl_easy_init();
- if (curl) {
- curl_easy_setopt(curl, CURLOPT_URL, uri);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
- res = curl_easy_perform(curl);
- if (CURLE_OK != res) {
- return -1;
- }
- }
- curl_global_cleanup();
- return 0;
+}
+static int +mh_sysconfig_run_puppet(const char *uri, const char *data) +{
- gboolean ret;
- GError *error;
- char *filename = NULL;
- gchar cmd[PATH_MAX];
- int fd;
- FILE *fp;
- if (uri != NULL) {
- filename = strdup("puppet_conf_XXXXXX");
You've got a memory leak of this in the error handling code path. I don't think dynamically allocating it is really necessary, anyway.
- fd = mkstemp(filename);
- fp = fdopen(fd, "w+b");
What if mkstemp() or fdopen() fail?
- if ((download(uri, fp)) != 0) {
- fclose(fp);
- return -1;
- }
- fclose(fp);
- } else if (data != NULL) {
- filename = strdup("puppet_conf_blob");
Again, I don't think dynamic allocation is needed here.
- g_file_set_contents(filename, data, strlen(data), NULL);
- } else {
- return -1;
- }
- g_snprintf(cmd, sizeof(cmd), "puppet %s", filename);
- fprintf(stderr, "%s", cmd);
Either remove this or convert it to an mh_ logging function.
- ret = g_spawn_async(NULL, (gchar **)cmd, NULL, G_SPAWN_SEARCH_PATH,
- NULL, NULL, NULL, &error);
- fprintf(stderr, "bool: %d", ret);
Same as above.
- if (ret == FALSE) {
- g_error_free(error);
- free(filename);
- return -1;
- }
- free(filename);
- return 0;
+}
+static int +mh_sysconfig_run_augeas(const char *query, const char *data) +{
- fprintf(stderr, "not implemented\n");
Convert to mh logging.
- return 0;
+}
+static int +mh_sysconfig_query_augeas(const char *query, const char *data) +{
- fprintf(stderr, "not implemented\n");
Convert to mh logging.
- return 0;
+}
+int +mh_sysconfig_run_uri(const char *uri, uint32_t flags, const char *scheme) {
Move { to the next line. This applies to some other places, too.
- int rc = 0;
- if (g_strcmp0(scheme, "puppet") == 0) {
Since this isn't a gchar, use standard strcmp(). Also, should this be case insensitive instead?
- rc = mh_sysconfig_run_puppet(uri, NULL);
- } else {
- rc = -1;
- }
- return rc;
+}
+int +mh_sysconfig_run_string(const char *data, uint32_t flags, const char *scheme) {
- int rc = 0;
- if (g_strcmp0(scheme, "puppet") == 0) {
- rc = mh_sysconfig_run_puppet(NULL, data);
- } else {
- rc = -1;
- }
- return rc;
+}
+int +mh_sysconfig_query(const char *query, const char *data, uint32_t flags, const char *scheme) {
- int rc = 0;
- if (g_strcmp0(scheme, "augeas") == 0) {
- rc = mh_sysconfig_run_augeas(query, data);
- } else {
- rc = -1;
- }
- return rc;
+} diff --git a/src/postboot/CMakeLists.txt b/src/postboot/CMakeLists.txt deleted file mode 100644 index 36d59a1..0000000 --- a/src/postboot/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(BASE "postboot") -set(BASE_LIB "m${BASE}") -set(QMF_AGENT "matahari-qmf-${BASE}d") -set(QMF_CONSOLE "matahari-qmf-${BASE}-consoled")
-# QMF daemon -if(WITH-QMF)
- set(SCHEMA_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/QmfPackage.cpp)
- generate_qmf_schemas(${CMAKE_CURRENT_SOURCE_DIR}/schema.xml ${SCHEMA_SOURCES})
- include_directories(${CMAKE_CURRENT_BINARY_DIR})
- add_executable(${QMF_AGENT} ${BASE}-qmf.cpp ${SCHEMA_SOURCES})
- add_executable(${QMF_CONSOLE} ${BASE}-console.cpp)
- target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon_qmf)
- target_link_libraries(${QMF_CONSOLE} mcommon_qmf)
- if(NOT WIN32)
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
- # Override BASE for matahari-postboot-console
- unset(BASE)
- set(BASE "postboot-console")
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
- endif(NOT WIN32)
- install(TARGETS ${QMF_AGENT} DESTINATION sbin)
- install(TARGETS ${QMF_CONSOLE} DESTINATION sbin)
-endif(WITH-QMF) diff --git a/src/postboot/postboot-console.cpp b/src/postboot/postboot-console.cpp deleted file mode 100644 index 188c443..0000000 --- a/src/postboot/postboot-console.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* config-console.cpp - Copyright (c) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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 <string> -#include <iostream>
-using namespace std; -using namespace qmf; -using qpid::types::Variant; -using qpid::messaging::Duration;
-int main(int argc, char** argv) -{
- string brokerUrl("amqp:tcp:127.0.0.1:49000");
- qpid::types::Variant::Map connectionOptions;
- qpid::types::Variant::Map dataProperties;
- string sessionOptions;
- connectionOptions["reconnect"] = true;
- dataProperties["uri"] = argv[1] ? argv[1] : "http://localhost/config/uuid";
- qpid::messaging::Connection connection(brokerUrl, connectionOptions);
- connection.open();
- ConsoleSession session(connection, sessionOptions);
- // Only filter connecting agents under matahariproject.org vendor and Config product
- session.setAgentFilter("[and, [eq, _vendor, [quote, 'matahariproject.org']], [eq, _product, [quote, 'Config']]]");
- session.open();
- Agent agent;
- while (true) {
- ConsoleEvent event;
- if(session.nextEvent(event)) {
- switch(event.getType()) {
- case CONSOLE_AGENT_ADD:
- {
- agent = event.getAgent();
- DataAddr agent_event_addr("config", agent.getName(), 0);
- ConsoleEvent result(agent.callMethod("configure",
- dataProperties,
- agent_event_addr));
- }
- break;
- default: {}
- }
- }
- }
- return 0;
-} diff --git a/src/postboot/postboot-qmf.cpp b/src/postboot/postboot-qmf.cpp deleted file mode 100644 index 7058276..0000000 --- a/src/postboot/postboot-qmf.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* config-qmf.cpp - Copyright (C) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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/postboot.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_Postboot);
- _instance.setProperty("hostname", mh_hostname());
- _instance.setProperty("uuid", mh_uuid());
- _instance.setProperty("is_configured", mh_is_configured());
- _agent_session.addData(_instance, "postboot");
- return 0;
-}
-gboolean -ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) -{
- if (event.getType() != qmf::AGENT_METHOD) {
- return TRUE;
- }
- const std::string& methodName(event.getMethodName());
- if (methodName == "configure") {
- int rc = mh_is_configured();
- if(rc == 0) {
- mh_configure(event.getArguments()["uri"].asString().c_str());
- }
- event.addReturnArgument("configured", rc);
- } else {
- session.raiseException(event, MH_NOT_IMPLEMENTED);
- goto bail;
- }
- session.methodSuccess(event);
-bail:
- return TRUE;
-} diff --git a/src/postboot/schema.xml b/src/postboot/schema.xml deleted file mode 100644 index 2d930ce..0000000 --- a/src/postboot/schema.xml +++ /dev/null @@ -1,16 +0,0 @@ -<schema package="org.matahariproject">
- <!-- Config API -->
- <class name="Postboot">
- <property name="uuid" type="sstr" access="RO" desc="Host UUID" />
- <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/>
- <property name="is_configured" type="uint32" access="RO" desc="Check if agent is configured." />
- <statistic name="qmf-gen-no-crash" type="absTime" desc="Dummy stat to stop qmf-gen from crashing." />
- <method name="configure" desc="Send configure method">
- <arg name="uri" dir="I" type="sstr" />
- <arg name="configured" dir="O" type="uint32" />
- </method>
- </class>
-</schema> diff --git a/src/sysconfig/CMakeLists.txt b/src/sysconfig/CMakeLists.txt new file mode 100644 index 0000000..1d9fba8 --- /dev/null +++ b/src/sysconfig/CMakeLists.txt @@ -0,0 +1,30 @@ +set(BASE "sysconfig") +set(BASE_LIB "m${BASE}") +set(QMF_AGENT "matahari-qmf-${BASE}d") +set(QMF_CONSOLE "matahari-qmf-${BASE}-consoled")
+# QMF daemon +if(WITH-QMF)
- set(SCHEMA_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/QmfPackage.cpp)
- generate_qmf_schemas(${CMAKE_CURRENT_SOURCE_DIR}/schema.xml ${SCHEMA_SOURCES})
- include_directories(${CMAKE_CURRENT_BINARY_DIR})
- add_executable(${QMF_AGENT} ${BASE}-qmf.cpp ${SCHEMA_SOURCES})
- add_executable(${QMF_CONSOLE} ${BASE}-console.cpp)
- target_link_libraries(${QMF_AGENT} ${BASE_LIB} mcommon_qmf)
- target_link_libraries(${QMF_CONSOLE} mcommon_qmf)
- if(NOT WIN32)
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
- # Override BASE for matahari-sysconfig-console
- unset(BASE)
- set(BASE "sysconfig-console")
- configure_file(${CMAKE_SOURCE_DIR}/matahari.init.in ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE})
- install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/matahari-${BASE} DESTINATION ${initdir})
- endif(NOT WIN32)
- install(TARGETS ${QMF_AGENT} DESTINATION sbin)
- install(TARGETS ${QMF_CONSOLE} DESTINATION sbin)
+endif(WITH-QMF) diff --git a/src/sysconfig/schema.xml b/src/sysconfig/schema.xml new file mode 100644 index 0000000..d5c52aa --- /dev/null +++ b/src/sysconfig/schema.xml @@ -0,0 +1,35 @@ +<schema package="org.matahariproject">
- <!-- Config API -->
- <class name="Sysconfig">
- <property name="uuid" type="sstr" access="RO" desc="Host UUID" />
- <property name="hostname" type="sstr" access="RO" desc="Hostname" index="y"/>
- <property name="is_postboot_configured" type="uint32" access="RO" desc="Check if agent is configured." />
- <statistic name="qmf-gen-no-crash" type="absTime" desc="Dummy stat to stop qmf-gen from crashing." />
- <method name="run_uri" desc="Send configure uri method">
- <arg name="uri" dir="I" type="sstr" />
- <arg name="scheme" dir="I" type="sstr" />
- <arg name="key" dir="I" type="sstr" />
- <arg name="flags" dir="I" type="uint32" />
- </method>
- <method name="run_string" desc="Send configure text method">
- <arg name="text" dir="I" type="sstr" />
- <arg name="scheme" dir="I" type="sstr" />
- <arg name="key" dir="I" type="sstr" />
- <arg name="flags" dir="I" type="uint32" />
- </method>
- <method name="query" desc="Perform query lookup">
- <arg name="text" dir="I" type="sstr" />
- <arg name="scheme" dir="I" type="sstr" />
- <arg name="flags" dir="I" type="uint32" />
- </method>
- <method name="is_configured" desc="Check if system is configured">
- <arg name="key" dir="I" type="sstr" />
- </method>
- </class>
+</schema> diff --git a/src/sysconfig/sysconfig-console.cpp b/src/sysconfig/sysconfig-console.cpp new file mode 100644 index 0000000..e294152 --- /dev/null +++ b/src/sysconfig/sysconfig-console.cpp @@ -0,0 +1,96 @@ +/* config-console.cpp - Copyright (c) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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 <matahari/mh_agent.h>
+#include <string> +#include <iostream> +#include <sstream>
+extern "C" { +#include "matahari/logging.h" +}
Why include with quotes here, but brackets above, both for matahari headers? In this case I don't think it really matters that much, but consistency is good.
+using namespace std; +using namespace qmf; +using qpid::types::Variant; +using qpid::messaging::Duration;
Random thought ... we need to decide for the coding guidelines if we really want to be using "using". I think I would rather not, personally.
+int main(int argc, char** argv)
nit-pick, space _before_ **, not after
+{
- qpid::types::Variant::Map options;
- qpid::types::Variant::Map callOptions;
- string sessionOptions;
- ConsoleEvent event;
- Agent agent;
- mh_log_init("sysconfig-console", LOG_TRACE, TRUE);
- mh_add_option('U', required_argument, "uri", "URI of configuration", &options, NULL);
- string url = mh_parse_options("sysconfig-console", argc, argv, options);
- callOptions["uri"] = options["uri"];
- mh_log_init("sysconfig-console", mh_log_level, mh_log_level > LOG_INFO);
- qpid::messaging::Connection connection(url, options);
- connection.open();
- ConsoleSession session(connection, sessionOptions);
- // Only filter connecting agents under matahariproject.org vendor and Config product
- session.setAgentFilter("[and, [eq, _vendor, [quote, 'matahariproject.org']], [eq, _product, [quote, 'Sysconfig']]]");
- session.open();
- while(session.getAgentCount() == 0) {
- g_usleep(1000);
- }
- while (true) {
- if(session.nextEvent(event)) {
- switch(event.getType()) {
- case CONSOLE_AGENT_ADD:
- {
- agent = event.getAgent();
- DataAddr agent_event_addr("config", agent.getName(), 0);
- ConsoleEvent result(agent.callMethod("configure",
- callOptions,
- agent_event_addr));
- }
- break;
- default:
- break;
- }
- }
- }
- return 0;
+} diff --git a/src/sysconfig/sysconfig-qmf.cpp b/src/sysconfig/sysconfig-qmf.cpp new file mode 100644 index 0000000..1cacd87 --- /dev/null +++ b/src/sysconfig/sysconfig-qmf.cpp @@ -0,0 +1,163 @@ +/* config-qmf.cpp - Copyright (C) 2011 Red Hat, Inc.
- Written by Adam Stokes astokes@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
- */
+/**
- \file
- \brief Sysconfig QMF Agent
- */
+#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 <fcntl.h> +#include <glib.h> +#include <glib/gstdio.h> +#include <glib/gprintf.h> +#include "matahari/sysconfig.h" +#include "matahari/logging.h" +#include "matahari/network.h" +#include "matahari/host.h" +#include <sigar.h> +#include <sigar_format.h> +};
+static const char *configured_fn = "/var/lib/matahari/.is_configured";
Make this ... static const char configured_fn[] = ...
+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);
Another pedantic style comment: I prefer always putting public: first.
+};
+int +main(int argc, char **argv) +{
- ConfigAgent agent;
- int rc = agent.init(argc, argv, "Sysconfig");
- if (rc == 0) {
- agent.run();
- }
- return rc;
+}
+int +ConfigAgent::setup(qmf::AgentSession session) +{
- _package.configure(session);
- _instance = qmf::Data(_package.data_Sysconfig);
- _instance.setProperty("hostname", mh_hostname());
- _instance.setProperty("uuid", mh_uuid());
- _instance.setProperty("is_postboot_configured", 0);
- _agent_session.addData(_instance, "sysconfig");
- return 0;
+}
+static void +set_configured() {
- if(!g_file_test(configured_fn, G_FILE_TEST_EXISTS)) {
- g_creat(configured_fn, S_IRWXU);
- }
+}
Does this logic really belong directly in the QMF agent or should it be in the core C library?
Also, what happened to the "key" concept described in your design? Is that just still on the to-do list?
+static int +is_configured(uint32_t flags) {
- if(flags & SYSCONFIG_FLAG_FORCE) {
- return 0;
- }
- if(g_file_test(configured_fn, G_FILE_TEST_EXISTS)) {
- return 1;
- }
- return 0;
+}
+gboolean +ConfigAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) +{
- int rc = 0;
- uint32_t flags;
- if (event.getType() != qmf::AGENT_METHOD) {
- return TRUE;
- }
- const std::string& methodName(event.getMethodName());
- if (methodName == "run_uri") {
- flags = event.getArguments()["flags"].asInt32();
- if((is_configured(flags)) == 0) {
- rc = mh_sysconfig_run_uri(event.getArguments()["uri"].asString().c_str(),
Since you're going to end up using event.getArguments() a bunch, you can just save off the reference at the beginning of the function. A couple of other agents do this.
- flags,
- event.getArguments()["scheme"].asString().c_str());
- if (rc == 0) {
- set_configured();
- }
- }
- event.addReturnArgument("configured", rc);
- } else if (methodName == "run_string") {
- flags = event.getArguments()["flags"].asInt32();
- if((is_configured(flags)) == 0) {
- rc = mh_sysconfig_run_string(event.getArguments()["data"].asString().c_str(),
- flags,
- event.getArguments()["scheme"].asString().c_str());
- if (rc == 0) {
- set_configured();
- }
- }
- event.addReturnArgument("configured", rc);
- } else if (methodName == "query") {
- flags = event.getArguments()["flags"].asInt32();
- if((is_configured(flags)) == 0) {
- rc = mh_sysconfig_query(event.getArguments()["query"].asString().c_str(),
- event.getArguments()["data"].asString().c_str(),
- flags,
- event.getArguments()["scheme"].asString().c_str());
- }
- event.addReturnArgument("configured", rc);
- } else if (methodName == "is_configured") {
- rc = is_configured(0);
- _instance.setProperty("is_postboot_configured", rc);
- event.addReturnArgument("configured", rc);
- } else {
- session.raiseException(event, MH_NOT_IMPLEMENTED);
- goto bail;
- }
- session.methodSuccess(event);
+bail:
- return TRUE;
+} diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 6db157c..8fe81f2 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -5,13 +5,13 @@ if(CXXTEST_FOUND) ENABLE_TESTING() CXXTEST_ADD_TEST(mh_api_network_unittest network_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_network.h) CXXTEST_ADD_TEST(mh_api_host_unittest host_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_host.h)
- CXXTEST_ADD_TEST(mh_api_postboot_unittest postboot_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_postboot.h)
- CXXTEST_ADD_TEST(mh_api_sysconfig_unittest sysconfig_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_api_sysconfig.h)
CXXTEST_ADD_TEST(mh_hsa_unittest hsa_unittest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mh_hsa_${VARIANT}.h) add_library(mh_tester SHARED test_utilities.c)
- target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost mpostboot)
- target_link_libraries(mh_tester ${pcre_LIBRARIES} mcommon mnetwork mhost msysconfig)
target_link_libraries(mh_api_network_unittest mh_tester) target_link_libraries(mh_api_host_unittest mh_tester)
- target_link_libraries(mh_api_postboot_unittest mh_tester)
- target_link_libraries(mh_api_sysconfig_unittest mh_tester)
target_link_libraries(mh_hsa_unittest mh_tester) endif(CXXTEST_FOUND)
diff --git a/src/tests/mh_api_postboot.h b/src/tests/mh_api_postboot.h deleted file mode 100644 index 5e59a9b..0000000 --- a/src/tests/mh_api_postboot.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __MH_API_NETWORK_UNITTEST_H -#define __MH_API_NETWORK_UNITTEST_H -#include <iostream> -#include <string> -#include <sstream> -#include <utility> -#include <vector> -#include <cstdlib> -#include <cstdio> -#include <sys/stat.h> -#include <dirent.h> -#include <cxxtest/TestSuite.h>
-extern "C" { -#include "matahari/postboot.h" -#include <glib.h> -#include "mh_test_utilities.h" -};
-using namespace std;
-class MhApiPostbootSuite : public CxxTest::TestSuite -{
- public:
- void testIsConfigured(void)
- {
- const char *uri = "http://matahariproject.org/testing.xml";
- mh_configure(uri);
- TS_ASSERT((mh_is_configured()) == 1);
- }
-};
-#endif diff --git a/src/tests/mh_api_sysconfig.h b/src/tests/mh_api_sysconfig.h new file mode 100644 index 0000000..a9a3ebc --- /dev/null +++ b/src/tests/mh_api_sysconfig.h @@ -0,0 +1,34 @@ +#ifndef __MH_API_NETWORK_UNITTEST_H +#define __MH_API_NETWORK_UNITTEST_H +#include <iostream> +#include <string> +#include <sstream> +#include <utility> +#include <vector> +#include <cstdlib> +#include <cstdio> +#include <sys/stat.h> +#include <dirent.h> +#include <cxxtest/TestSuite.h>
+extern "C" { +#include "matahari/sysconfig.h" +#include <glib.h> +#include "mh_test_utilities.h" +};
+using namespace std;
+class MhApiSysconfigSuite : public CxxTest::TestSuite +{
- public:
- void testIsConfigured(void)
- {
- const char *uri = "http://matahariproject.org/atom.xml";
I guess this is a placeholder for now? Is it just verifying that it can download it successfully?
- uint32_t flags = 0;
- TS_ASSERT((mh_sysconfig_run_uri(uri, flags, "puppet")) != -1);
- }
+};
+#endif
1.7.6
Matahari mailing list Matahari@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/matahari
matahari@lists.fedorahosted.org