summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2014-06-24 13:18:55 +0200
committerMichal Minar <miminar@redhat.com>2014-07-01 15:40:57 +0200
commit55cb42ff2a328dfb025df72626fe5b2e891fad4e (patch)
treedeefdf7ff52c701eaccc953274de6c026f063ad1
parentab33e12d00ad570e6a6aa0e9899b9f3ee08ed0e5 (diff)
downloadopenlmi-providers-55cb42ff2a328dfb025df72626fe5b2e891fad4e.tar.gz
openlmi-providers-55cb42ff2a328dfb025df72626fe5b2e891fad4e.tar.xz
openlmi-providers-55cb42ff2a328dfb025df72626fe5b2e891fad4e.zip
software-dbus: implemented LMI_AffectedSoftwareJobElement
-rw-r--r--mof/60_LMI_Software.mof6
-rw-r--r--src/software-dbus/LMI_AffectedSoftwareJobElementProvider.c198
2 files changed, 199 insertions, 5 deletions
diff --git a/mof/60_LMI_Software.mof b/mof/60_LMI_Software.mof
index b8611f3..3ba1163 100644
--- a/mof/60_LMI_Software.mof
+++ b/mof/60_LMI_Software.mof
@@ -741,6 +741,12 @@ class LMI_AffectedSoftwareJobElement : LMI_AffectedJobElement {
[Override("AffectingElement")]
LMI_SoftwareJob REF AffectingElement;
+ [Implemented(true), Override("ElementEffects")]
+ uint16 ElementEffects[];
+
+ [Implemented(true), Override("OtherElementEffectsDescriptions")]
+ string OtherElementEffectsDescriptions[];
+
};
[Version("0.2.0"), Association]
diff --git a/src/software-dbus/LMI_AffectedSoftwareJobElementProvider.c b/src/software-dbus/LMI_AffectedSoftwareJobElementProvider.c
index 6285269..d08acc3 100644
--- a/src/software-dbus/LMI_AffectedSoftwareJobElementProvider.c
+++ b/src/software-dbus/LMI_AffectedSoftwareJobElementProvider.c
@@ -1,10 +1,35 @@
+/*
+ * 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: Michal Minar <miminar@redhat.com>
+ */
+
#include <konkret/konkret.h>
#include "LMI_AffectedSoftwareJobElement.h"
+#include "LMI_SystemSoftwareCollection.h"
+#include "sw-utils.h"
+#include "lmi_sw_job.h"
+#include "job_manager.h"
static const CMPIBroker* _cb;
-static void LMI_AffectedSoftwareJobElementInitialize()
+static void LMI_AffectedSoftwareJobElementInitialize(const CMPIContext *ctx)
{
+ software_init(provider_name, _cb, ctx, provider_config_defaults);
}
static CMPIStatus LMI_AffectedSoftwareJobElementCleanup(
@@ -12,7 +37,7 @@ static CMPIStatus LMI_AffectedSoftwareJobElementCleanup(
const CMPIContext* cc,
CMPIBoolean term)
{
- CMReturn(CMPI_RC_OK);
+ return software_cleanup();
}
static CMPIStatus LMI_AffectedSoftwareJobElementEnumInstanceNames(
@@ -25,6 +50,29 @@ static CMPIStatus LMI_AffectedSoftwareJobElementEnumInstanceNames(
_cb, mi, cc, cr, cop);
}
+static CMPIStatus fill_inst(LMI_AffectedSoftwareJobElement *inst,
+ const gchar *namespace,
+ CMPIObjectPath *job,
+ CMPIObjectPath *affected_element,
+ const gchar *description)
+{
+ LMI_AffectedSoftwareJobElement_Init(inst, _cb, namespace);
+ LMI_AffectedSoftwareJobElement_SetObjectPath_AffectingElement(inst, job);
+ LMI_AffectedSoftwareJobElement_Init_ElementEffects(inst, 1);
+ LMI_AffectedSoftwareJobElement_Set_ElementEffects_Other(inst, 0);
+ if (description != NULL) {
+ LMI_AffectedSoftwareJobElement_Init_OtherElementEffectsDescriptions(inst, 1);
+ LMI_AffectedSoftwareJobElement_Set_OtherElementEffectsDescriptions(
+ inst, 0, description);
+ } else {
+ LMI_AffectedSoftwareJobElement_Init_OtherElementEffectsDescriptions(inst, 0);
+ }
+ LMI_AffectedSoftwareJobElement_SetObjectPath_AffectedElement(
+ inst, affected_element);
+ KReturn(OK);
+}
+
+
static CMPIStatus LMI_AffectedSoftwareJobElementEnumInstances(
CMPIInstanceMI* mi,
const CMPIContext* cc,
@@ -32,7 +80,147 @@ static CMPIStatus LMI_AffectedSoftwareJobElementEnumInstances(
const CMPIObjectPath* cop,
const char** properties)
{
- CMReturn(CMPI_RC_OK);
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ LmiJob *job = NULL;
+ CMPIObjectPath *jop;
+ CMPIObjectPath *op;
+ guint *jobnum;
+ guint *jobnums = jobmgr_get_job_numbers(NULL);
+ gchar *description;
+ char instance_id[BUFLEN] = "";
+
+ if (jobnums == NULL)
+ CMReturn(CMPI_RC_ERR_FAILED);
+
+ for (jobnum = jobnums; *jobnum != 0; ++jobnum) {
+ job = jobmgr_get_job_by_number(*jobnum);
+ if (!job)
+ /* job may have been deleted since numbers query */
+ continue;
+
+ JOB_CRITICAL_BEGIN(job);
+
+ status = jobmgr_job_to_cim_op(job, &jop);
+ if (status.rc) {
+ gchar *jobid = lmi_job_get_jobid(job);
+ if (status.msg) {
+ lmi_warn("Failed to make cim instance out of job \"%s\": %s",
+ jobid, CMGetCharsPtr(status.msg, NULL));
+ } else {
+ lmi_warn("Failed to make cim instance out of job \"%s\".",
+ jobid);
+ }
+ g_free(jobid);
+ goto job_critical_end;
+ }
+
+ description = NULL;
+ if ( LMI_IS_SW_INSTALLATION_JOB(job)
+ && lmi_job_has_in_param(job, IN_PARAM_INSTALL_OPTIONS_NAME))
+ {
+ GVariant *variant = lmi_job_get_in_param(job,
+ IN_PARAM_INSTALL_OPTIONS_NAME);
+ guint32 iopts = g_variant_get_uint32(variant);
+ g_variant_unref(variant);
+ if (iopts & INSTALLATION_OPERATION_INSTALL) {
+ description = "Installing";
+ } else if (iopts & INSTALLATION_OPERATION_UPDATE) {
+ description = "Updating";
+ } else if (iopts & INSTALLATION_OPERATION_REMOVE) {
+ description = "Removing";
+ } else {
+ description = "Modifying";
+ }
+ } else if (LMI_IS_SW_VERIFICATION_JOB(job)) {
+ description = "Verifying";
+ }
+
+ if (LMI_IS_SW_INSTALLATION_JOB(job)) {
+ /* associate to SystemSoftwareCollection */
+ create_instance_id(LMI_SystemSoftwareCollection_ClassName,
+ NULL, instance_id, BUFLEN);
+
+ LMI_SystemSoftwareCollectionRef sc;
+ LMI_SystemSoftwareCollectionRef_Init(&sc, _cb, KNameSpace(cop));
+ LMI_SystemSoftwareCollectionRef_Set_InstanceID(&sc, instance_id);
+ op = LMI_SystemSoftwareCollectionRef_ToObjectPath(&sc, &status);
+ if (status.rc)
+ goto mem_err;
+
+ LMI_AffectedSoftwareJobElement w;
+ status = fill_inst(&w, KNameSpace(cop), jop, op, description);
+ if (status.rc) {
+ CMRelease(op);
+ goto mem_err;
+ }
+ KReturnInstance(cr, w);
+ }
+
+ { /* associate to ComputerSystem */
+ LMI_AffectedSoftwareJobElement w;
+ status = fill_inst(&w, KNameSpace(cop), jop,
+ lmi_get_computer_system_safe(cc), description);
+ if (status.rc)
+ goto mem_err;
+ KReturnInstance(cr, w);
+ }
+
+ if (lmi_job_has_out_param(job, OUT_PARAM_AFFECTED_PACKAGES)) {
+ /* associate to affected packages */
+ GVariant *affected_packages = lmi_job_get_out_param(
+ job, OUT_PARAM_AFFECTED_PACKAGES);
+ GVariantIter iter;
+ gchar *pkg_id = NULL;
+ SwPackage sw_pkg;
+ g_variant_iter_init(&iter, affected_packages);
+ gchar buf[BUFLEN];
+ while (g_variant_iter_next(&iter, "&s", &pkg_id)) {
+ init_sw_package(&sw_pkg);
+ if (create_sw_package_from_pk_pkg_id(pkg_id, &sw_pkg) != 0)
+ continue;
+ sw_pkg_get_element_name(&sw_pkg, buf, BUFLEN);
+ create_instance_id(LMI_SoftwareIdentity_ClassName, buf,
+ instance_id, BUFLEN);
+ free_sw_package(&sw_pkg);
+
+ LMI_SoftwareIdentityRef sir;
+ LMI_SoftwareIdentityRef_Init(&sir, _cb, KNameSpace(cop));
+ LMI_SoftwareIdentityRef_Set_InstanceID(&sir, instance_id);
+ op = LMI_SoftwareIdentityRef_ToObjectPath(&sir, &status);
+ if (status.rc)
+ goto mem_err;
+
+ LMI_AffectedSoftwareJobElement w;
+ status = fill_inst(&w, KNameSpace(cop), jop, op, description);
+ if (status.rc) {
+ CMRelease(op);
+ goto mem_err;
+ }
+ KReturnInstance(cr, w);
+ }
+ g_variant_unref(affected_packages);
+ }
+
+job_critical_end:
+ JOB_CRITICAL_END(job);
+ g_clear_object(&job);
+ }
+
+ g_free(jobnums);
+ return status;
+
+mem_err:
+ if (job != NULL) {
+ JOB_CRITICAL_END(job);
+ g_object_unref(job);
+ }
+ if (status.msg != NULL) {
+ lmi_error(CMGetCharsPtr(status.msg, NULL));
+ } else {
+ lmi_error("Memory allocation failed");
+ }
+ g_free(jobnums);
+ return status;
}
static CMPIStatus LMI_AffectedSoftwareJobElementGetInstance(
@@ -187,13 +375,13 @@ CMInstanceMIStub(
LMI_AffectedSoftwareJobElement,
LMI_AffectedSoftwareJobElement,
_cb,
- LMI_AffectedSoftwareJobElementInitialize())
+ LMI_AffectedSoftwareJobElementInitialize(ctx))
CMAssociationMIStub(
LMI_AffectedSoftwareJobElement,
LMI_AffectedSoftwareJobElement,
_cb,
- LMI_AffectedSoftwareJobElementInitialize())
+ LMI_AffectedSoftwareJobElementInitialize(ctx))
KONKRET_REGISTRATION(
"root/cimv2",