summaryrefslogtreecommitdiffstats
path: root/src/software-dbus
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2014-03-27 17:27:59 +0100
committerPeter Schiffer <pschiffe@redhat.com>2014-03-27 17:27:59 +0100
commit3ae5f8606e63e820359e16186b96938d5a23bcea (patch)
tree45a8ccb11264644a1886a6bb8a080874c4f82739 /src/software-dbus
parentc9dd327c44eca6b5226f0d6ea4449a0261b2f2ab (diff)
downloadopenlmi-providers-3ae5f8606e63e820359e16186b96938d5a23bcea.tar.gz
openlmi-providers-3ae5f8606e63e820359e16186b96938d5a23bcea.tar.xz
openlmi-providers-3ae5f8606e63e820359e16186b96938d5a23bcea.zip
Software-dbus: Implemented SoftwareIdentityResourceProvider
Diffstat (limited to 'src/software-dbus')
-rw-r--r--src/software-dbus/LMI_Software.h1
-rw-r--r--src/software-dbus/LMI_SoftwareIdentityResourceProvider.c186
2 files changed, 183 insertions, 4 deletions
diff --git a/src/software-dbus/LMI_Software.h b/src/software-dbus/LMI_Software.h
index 916ca5f..6e434f9 100644
--- a/src/software-dbus/LMI_Software.h
+++ b/src/software-dbus/LMI_Software.h
@@ -30,5 +30,6 @@
#define SW_IDENTITY_CLASS_NAME "SoftwareIdentity"
#define SYSTEM_SW_COLLECTION_CLASS_NAME "SystemSoftwareCollection"
+#define SW_IDENTITY_RESOURCE_CLASS_NAME "SoftwareIdentityResource"
#endif /* LMI_SOFTWARE_H_ */
diff --git a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
index d173b48..ecf1391 100644
--- a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
+++ b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
@@ -1,10 +1,34 @@
+/*
+ * Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ *
+ * Authors: Peter Schiffer <pschiffe@redhat.com>
+ */
+
#include <konkret/konkret.h>
#include "LMI_SoftwareIdentityResource.h"
+#include "LMI_Software.h"
+
+#define DSC_LEN 256
static const CMPIBroker* _cb = NULL;
-static void LMI_SoftwareIdentityResourceInitialize()
+static void LMI_SoftwareIdentityResourceInitialize(const CMPIContext *ctx)
{
+ lmi_init(provider_name, _cb, ctx, provider_config_defaults);
}
static CMPIStatus LMI_SoftwareIdentityResourceCleanup(
@@ -32,6 +56,103 @@ static CMPIStatus LMI_SoftwareIdentityResourceEnumInstances(
const CMPIObjectPath* cop,
const char** properties)
{
+ PkTask *task = NULL;
+ PkResults *results = NULL;
+ GPtrArray *array = NULL;
+ gboolean repo_enabled;
+ gchar *repo_id = NULL, *repo_desc = NULL;
+ unsigned i;
+ char error_msg[ERROR_MSG_LEN] = "", dsc[DSC_LEN] = "",
+ instance_id[INSTANCE_ID_LEN] = "";
+
+ task = pk_task_new();
+
+ results = pk_task_get_repo_list_sync(task, 0, NULL, NULL, NULL, NULL);
+ if (check_and_create_error_msg(results,
+ "Getting list of repositories failed", error_msg, ERROR_MSG_LEN)) {
+ goto done;
+ }
+
+ array = pk_results_get_repo_detail_array(results);
+ for (i = 0; i < array->len; i++) {
+ g_object_get(g_ptr_array_index(array, i), "repo-id", &repo_id,
+ "description", &repo_desc, "enabled", &repo_enabled, NULL);
+ snprintf(dsc, DSC_LEN, "[%s] - %s", repo_id, repo_desc);
+ create_instance_id(SW_IDENTITY_RESOURCE_CLASS_NAME, repo_id,
+ instance_id, INSTANCE_ID_LEN);
+
+ LMI_SoftwareIdentityResource w;
+ LMI_SoftwareIdentityResource_Init(&w, _cb, KNameSpace(cop));
+ LMI_SoftwareIdentityResource_Set_SystemName(&w, get_system_name());
+ LMI_SoftwareIdentityResource_Set_CreationClassName(&w,
+ ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME);
+ LMI_SoftwareIdentityResource_Set_SystemCreationClassName(&w,
+ get_system_creation_class_name());
+ LMI_SoftwareIdentityResource_Set_Name(&w, repo_id);
+
+ LMI_SoftwareIdentityResource_Set_AccessContext(&w,
+ LMI_SoftwareIdentityResource_AccessContext_Other);
+ LMI_SoftwareIdentityResource_Init_AvailableRequestedStates(&w, 2);
+ LMI_SoftwareIdentityResource_Set_AvailableRequestedStates(&w, 0,
+ LMI_SoftwareIdentityResource_AvailableRequestedStates_Enabled);
+ LMI_SoftwareIdentityResource_Set_AvailableRequestedStates(&w, 1,
+ LMI_SoftwareIdentityResource_AvailableRequestedStates_Disabled);
+ LMI_SoftwareIdentityResource_Set_EnabledDefault(&w,
+ LMI_SoftwareIdentityResource_EnabledDefault_Not_Applicable);
+ LMI_SoftwareIdentityResource_Set_ExtendedResourceType(&w,
+ LMI_SoftwareIdentityResource_ExtendedResourceType_Linux_RPM);
+ LMI_SoftwareIdentityResource_Set_InfoFormat(&w,
+ LMI_SoftwareIdentityResource_InfoFormat_URL);
+ LMI_SoftwareIdentityResource_Set_OtherAccessContext(&w,
+ "YUM package repository");
+ LMI_SoftwareIdentityResource_Set_OtherResourceType(&w,
+ "RPM Software Package");
+ LMI_SoftwareIdentityResource_Set_ResourceType(&w,
+ LMI_SoftwareIdentityResource_ResourceType_Other);
+ LMI_SoftwareIdentityResource_Set_TransitioningToState(&w,
+ LMI_SoftwareIdentityResource_TransitioningToState_Not_Applicable);
+
+ LMI_SoftwareIdentityResource_Set_Caption(&w, repo_desc);
+ LMI_SoftwareIdentityResource_Set_Description(&w, dsc);
+ LMI_SoftwareIdentityResource_Set_ElementName(&w, repo_id);
+ LMI_SoftwareIdentityResource_Set_InstanceID(&w, instance_id);
+
+ if (repo_enabled) {
+ LMI_SoftwareIdentityResource_Set_EnabledState(&w,
+ LMI_SoftwareIdentityResource_EnabledState_Enabled);
+ LMI_SoftwareIdentityResource_Set_RequestedState(&w,
+ LMI_SoftwareIdentityResource_RequestedState_Enabled);
+ } else {
+ LMI_SoftwareIdentityResource_Set_EnabledState(&w,
+ LMI_SoftwareIdentityResource_EnabledState_Disabled);
+ LMI_SoftwareIdentityResource_Set_RequestedState(&w,
+ LMI_SoftwareIdentityResource_RequestedState_Disabled);
+ }
+
+ KReturnInstance(cr, w);
+ }
+
+done:
+ if (task) {
+ g_object_unref(task);
+ }
+ if (results) {
+ g_object_unref(results);
+ }
+ if (array) {
+ g_ptr_array_unref(array);
+ }
+ if (repo_id) {
+ g_free(repo_id);
+ }
+ if (repo_desc) {
+ g_free(repo_desc);
+ }
+
+ if (*error_msg) {
+ KReturn2(_cb, ERR_FAILED, "%s", error_msg);
+ }
+
CMReturn(CMPI_RC_OK);
}
@@ -91,7 +212,7 @@ CMInstanceMIStub(
LMI_SoftwareIdentityResource,
LMI_SoftwareIdentityResource,
_cb,
- LMI_SoftwareIdentityResourceInitialize())
+ LMI_SoftwareIdentityResourceInitialize(ctx))
static CMPIStatus LMI_SoftwareIdentityResourceMethodCleanup(
CMPIMethodMI* mi,
@@ -118,7 +239,7 @@ CMMethodMIStub(
LMI_SoftwareIdentityResource,
LMI_SoftwareIdentityResource,
_cb,
- LMI_SoftwareIdentityResourceInitialize())
+ LMI_SoftwareIdentityResourceInitialize(ctx))
KUint32 LMI_SoftwareIdentityResource_RequestStateChange(
const CMPIBroker* cb,
@@ -131,8 +252,65 @@ KUint32 LMI_SoftwareIdentityResource_RequestStateChange(
CMPIStatus* status)
{
KUint32 result = KUINT32_INIT;
+ PkTask *task = NULL;
+ PkResults *results = NULL;
+ gboolean enable;
+ char error_msg[ERROR_MSG_LEN] = "";
+ unsigned ret = 1;
+
+ if (RequestedState->null || !RequestedState->exists) {
+ KSetStatus2(_cb, status, ERR_INVALID_PARAMETER,
+ "Missing requested state");
+ goto done;
+ }
+
+ if (TimeoutPeriod->exists && !TimeoutPeriod->null) {
+ KSetStatus2(_cb, status, ERR_NOT_SUPPORTED,
+ "Use of Timeout parameter is not supported");
+ goto done;
+ }
+
+ if (RequestedState->value == \
+ LMI_SoftwareIdentityResource_RequestedState_Enabled) {
+ enable = TRUE;
+ } else if (RequestedState->value == \
+ LMI_SoftwareIdentityResource_RequestedState_Disabled) {
+ enable = FALSE;
+ } else {
+ KSetStatus2(_cb, status, ERR_INVALID_PARAMETER,
+ "Invalid state requested");
+ goto done;
+ }
+
+ task = pk_task_new();
+
+ results = pk_task_repo_enable_sync(task, self->Name.chars, enable, NULL,
+ NULL, NULL, NULL);
+ if (check_and_create_error_msg(results,
+ "Failed to set repository state", error_msg, ERROR_MSG_LEN)) {
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ if (task) {
+ g_object_unref(task);
+ }
+ if (results) {
+ g_object_unref(results);
+ }
+
+ if (*error_msg) {
+ KSetStatus2(_cb, status, ERR_FAILED, error_msg);
+ }
+
+ if (ret == 0) {
+ KSetStatus(status, OK);
+ }
+
+ KUint32_Set(&result, ret);
- KSetStatus(status, ERR_NOT_SUPPORTED);
return result;
}