[Libvirt-cim] [PATCH 2 of 2] Add new provider: RedirectionService

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Mon Sep 15 16:46:42 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1221241361 25200
# Node ID 5dcc5fba620ae6d965feaf8dfce222e1eda9f2d1
# Parent  3d2b534d18c893486bc083fe855c807d3112a37f
Add new provider: RedirectionService.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r 3d2b534d18c8 -r 5dcc5fba620a src/Virt_RedirectionService.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Virt_RedirectionService.c	Fri Sep 12 10:42:41 2008 -0700
@@ -0,0 +1,221 @@
+/*
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ *  Kaitlin Rupert <karupert at us.ibm.com>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <inttypes.h>
+
+#include "cmpidt.h"
+#include "cmpift.h"
+#include "cmpimacs.h"
+
+#include "misc_util.h"
+
+#include <libcmpiutil/libcmpiutil.h>
+#include <libcmpiutil/std_invokemethod.h>
+#include <libcmpiutil/std_instance.h>
+
+#include "Virt_HostSystem.h"
+
+#define SERVICE_TYPE  3
+#define SHARING_MODE  3
+
+#define ENABLED_STATE   2
+#define REQUESTED_STATE 12
+
+const static CMPIBroker *_BROKER;
+
+static CMPIStatus get_rs(const CMPIObjectPath *reference,
+                         CMPIInstance **_inst,
+                         const CMPIBroker *broker,
+                         const CMPIContext *context,
+                         bool is_get_inst)
+{ 
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        virConnectPtr conn = NULL;
+        CMPIInstance *inst = NULL;
+        CMPIArray *array;
+        const char *name = NULL;
+        const char *ccname = NULL;
+        uint16_t prop_val;
+
+        *_inst = NULL;
+        conn = connect_by_classname(broker, CLASSNAME(reference), &s);
+        if (conn == NULL) {
+                if (is_get_inst)
+                        cu_statusf(broker, &s,
+                                   CMPI_RC_ERR_NOT_FOUND,
+                                   "No such instance");
+
+                return s;
+        }
+
+        inst = get_typed_instance(broker,
+                                  pfx_from_conn(conn),
+                                  "RedirectionService",
+                                  NAMESPACE(reference));
+
+        if (inst == NULL) {
+                CU_DEBUG("Failed to get typed instance");
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Failed to create instance");
+                goto out;
+        }
+
+        s = get_host_system_properties(&name,
+                                       &ccname,
+                                       reference,
+                                       broker,
+                                       context);
+        if (s.rc != CMPI_RC_OK) {
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "Unable to get host attributes");
+                goto out;
+        }
+
+        CMSetProperty(inst, "Name",
+                      (CMPIValue *)"Redirection Service", CMPI_chars);
+
+        CMSetProperty(inst, "SystemName",
+                      (CMPIValue *)name, CMPI_chars);
+
+        CMSetProperty(inst, "SystemCreationClassName",
+                      (CMPIValue *)ccname, CMPI_chars);
+
+        CMSetProperty(inst, "ElementName",
+                      (CMPIValue *)"Redirection Service", CMPI_chars);
+
+        array = CMNewArray(broker, 1, CMPI_uint16, &s);
+        if ((s.rc != CMPI_RC_OK) || CMIsNullObject(array))
+                goto out;
+
+        prop_val = (uint16_t)SERVICE_TYPE;
+        CMSetArrayElementAt(array, 0, &prop_val, CMPI_uint16);
+
+        CMSetProperty(inst, "RedirectionServiceType",
+                      (CMPIValue *)&array, CMPI_uint16A);
+
+        prop_val = (uint16_t) virConnectNumOfDomains(conn) + 
+                   (uint16_t) virConnectNumOfDefinedDomains(conn);
+
+        CMSetProperty(inst, "MaxConcurrentEnabledSAPs",
+                      (CMPIValue *)&prop_val, CMPI_uint16);
+
+        prop_val = (uint16_t)SHARING_MODE;
+        CMSetProperty(inst, "SharingMode",
+                      (CMPIValue *)&prop_val, CMPI_uint16);
+
+        prop_val = (uint16_t)ENABLED_STATE;
+        CMSetProperty(inst, "EnabledState",
+                      (CMPIValue *)&prop_val, CMPI_uint16);
+
+        prop_val = (uint16_t)REQUESTED_STATE;
+        CMSetProperty(inst, "RequestedState",
+                      (CMPIValue *)&prop_val, CMPI_uint16);
+
+        if (is_get_inst) {
+                s = cu_validate_ref(broker, reference, inst);
+                if (s.rc != CMPI_RC_OK)
+                        goto out;
+        }
+
+        cu_statusf(broker, &s,
+                   CMPI_RC_OK,
+                   "");
+ out:
+        virConnectClose(conn);
+        *_inst = inst;
+
+        return s;
+}
+
+static CMPIStatus return_rs(const CMPIContext *context,
+                            const CMPIObjectPath *reference,
+                            const CMPIResult *results,
+                            bool name_only,
+                            bool is_get_inst)
+{
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        CMPIInstance *inst;
+
+        s = get_rs(reference, &inst, _BROKER, context, is_get_inst);
+        if (s.rc != CMPI_RC_OK || inst == NULL)
+                goto out;
+
+        if (name_only)
+                cu_return_instance_name(results, inst);
+        else
+                CMReturnInstance(results, inst);
+ out:
+        return s;
+}
+
+static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self,
+                                    const CMPIContext *context,
+                                    const CMPIResult *results,
+                                    const CMPIObjectPath *reference)
+{
+        return return_rs(context, reference, results, true, false);
+}
+
+static CMPIStatus EnumInstances(CMPIInstanceMI *self,
+                                const CMPIContext *context,
+                                const CMPIResult *results,
+                                const CMPIObjectPath *reference,
+                                const char **properties)
+{
+
+        return return_rs(context, reference, results, false, false);
+}
+
+static CMPIStatus GetInstance(CMPIInstanceMI *self,
+                              const CMPIContext *context,
+                              const CMPIResult *results,
+                              const CMPIObjectPath *ref,
+                              const char **properties)
+{
+        return return_rs(context, ref, results, false, true);
+}
+
+DEFAULT_CI();
+DEFAULT_MI();
+DEFAULT_DI();
+DEFAULT_EQ();
+DEFAULT_INST_CLEANUP();
+
+STD_InstanceMIStub(, 
+                   Virt_RedirectionService, 
+                   _BROKER,
+                   libvirt_cim_init());
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-set-style: "K&R"
+ * tab-width: 8
+ * c-basic-offset: 8
+ * indent-tabs-mode: nil
+ * End:
+ */




More information about the Libvirt-cim mailing list