2
* constraint_common.c: common functions for constraint providers
4
* Author: Jia Ming Pan <jmltc@cn.ibm.com>
5
* Copyright (c) 2005 International Business Machines
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include <lha_internal.h>
28
#include <sys/types.h>
33
#include "cluster_info.h"
34
#include "constraint_common.h"
35
#include "cmpi_utils.h"
37
static char SystemName [] = "LinuxHACluster";
38
static char SystemCrName [] = "HA_Cluster";
40
static CMPIInstance * make_instance_byid(CMPIBroker * broker, char * classname,
41
CMPIObjectPath * op, char * id, uint32_t type,
43
static CMPIInstance * make_instance(CMPIBroker * broker, char * classname,
44
CMPIObjectPath *op, struct ha_msg *cons,
45
int type, CMPIStatus * rc);
47
make_instance(CMPIBroker *broker, char *classname, CMPIObjectPath *op,
48
struct ha_msg* constraint, int type, CMPIStatus *rc)
50
CMPIInstance * ci = NULL;
55
ci = CMNewInstance(broker, op, rc);
56
if ( CMIsNullObject(ci) ) {
57
cl_log(LOG_ERR, "%s: can't create instance", __FUNCTION__);
58
CMSetStatusWithChars(broker, rc,
59
CMPI_RC_ERR_FAILED, "Can't get create instance");
63
id = cim_strdup(cl_get_string(constraint, "id"));
64
if ( id == NULL ) { return NULL; }
66
/* setting properties */
67
CMSetProperty(ci, "Id", id, CMPI_chars);
68
CMSetProperty(ci, "SystemCreationClassName", SystemCrName, CMPI_chars);
69
CMSetProperty(ci, "SystemName", SystemName, CMPI_chars);
70
CMSetProperty(ci, "CreationClassName", classname, CMPI_chars);
72
if ( type == TID_CONS_ORDER ) {
73
cmpi_msg2inst(broker, ci,
74
HA_ORDER_CONSTRAINT, constraint, rc);
75
} else if ( type == TID_CONS_LOCATION ) {
76
cmpi_msg2inst(broker, ci,
77
HA_LOCATION_CONSTRAINT, constraint, rc);
78
} else if ( type == TID_CONS_COLOCATION ) {
79
cmpi_msg2inst(broker, ci,
80
HA_COLOCATION_CONSTRAINT, constraint, rc);
82
snprintf(caption, MAXLEN, "Constraint.%s", id);
83
CMSetProperty(ci, "Caption", caption, CMPI_chars);
91
make_instance_byid(CMPIBroker * broker, char * classname, CMPIObjectPath * op,
92
char * id, uint32_t type, CMPIStatus * rc)
95
struct ha_msg *constraint;
100
case TID_CONS_LOCATION: funcid=GET_LOCATION_CONSTRAINT; break;
101
case TID_CONS_COLOCATION: funcid=GET_COLOCATION_CONSTRAINT; break;
102
case TID_CONS_ORDER: funcid=GET_ORDER_CONSTRAINT; break;
106
if ( (constraint= cim_query_dispatch(funcid, id, NULL)) == NULL ) {
109
ci = make_instance(broker, classname, op, constraint, type, rc);
110
ha_msg_del(constraint);
116
constraing_get_inst(CMPIBroker * broker, char * classname, CMPIContext * ctx,
117
CMPIResult * rslt, CMPIObjectPath * cop,
118
char ** properties, uint32_t type, CMPIStatus * rc)
120
CMPIInstance* ci = NULL;
121
CMPIObjectPath * op = NULL;
122
char * consid = NULL;
125
/* get the key from the object path */
126
if (( consid = CMGetKeyString(cop, "Id", rc)) == NULL ) {
127
cl_log(LOG_ERR, "%s: Id is missing.", __FUNCTION__);
131
/* create a object path */
132
op = CMNewObjectPath(broker,
133
CMGetCharPtr(CMGetNameSpace(cop, rc)), classname, rc);
134
if ( CMIsNullObject(op) ){
135
cl_log(LOG_ERR, "%s: Could not create object path.",
140
/* make an instance */
141
ci = make_instance_byid(broker, classname, op, consid, type, rc);
142
if ( CMIsNullObject(ci) ) {
143
cl_log(LOG_ERR, "%s: Could not create instance.",
148
/* add the instance to result */
149
CMReturnInstance(rslt, ci);
155
constraint_enum_insts(CMPIBroker * broker, char * classname, CMPIContext * ctx,
156
CMPIResult * rslt, CMPIObjectPath * ref,
157
int need_inst, uint32_t type, CMPIStatus * rc)
159
char * namespace = NULL;
160
CMPIObjectPath * op = NULL;
161
int i, funcid = 0, len;
162
struct ha_msg * cons;
164
/* create object path */
165
namespace = CMGetCharPtr(CMGetNameSpace(ref, rc));
166
op = CMNewObjectPath(broker, namespace, classname, rc);
167
if ( CMIsNullObject(op) ){
173
funcid = GET_ORDER_CONS_LIST;break;
174
case TID_CONS_LOCATION:
175
funcid = GET_LOCATION_CONS_LIST; break;
176
case TID_CONS_COLOCATION:
177
funcid = GET_COLOCATION_CONS_LIST; break;
181
if ( ( cons = cim_query_dispatch(funcid, NULL, NULL) ) == NULL ) {
185
len = cim_list_length(cons);
186
/* for each constraint */
187
for ( i = 0; i < len; i++) {
188
char * consid = cim_list_index(cons, i);
190
/* if need instance, make instance an return it */
191
CMPIInstance * ci = NULL;
192
ci = make_instance_byid(broker, classname, op,
194
if ( CMIsNullObject(ci) ){
196
"%s: can not make instance", __FUNCTION__);
200
cl_log(LOG_INFO, "%s: return instance", __FUNCTION__);
201
CMReturnInstance(rslt, ci);
203
/* otherwise, just add keys to objectpath and return it */
204
CMAddKey(op, "Id", consid, CMPI_chars);
205
CMAddKey(op, "SystemName", SystemName, CMPI_chars);
206
CMAddKey(op, "SystemCreationClassName", SystemCrName, CMPI_chars);
207
CMAddKey(op, "CreationClassName", classname, CMPI_chars);
209
/* add object to rslt */
210
CMReturnObjectPath(rslt, op);
220
constraint_delete_inst(CMPIBroker * broker, char * classname,
221
CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt,
222
CMPIObjectPath * cop, uint32_t type, CMPIStatus * rc)
224
const char * key [] = {"Id", "CreationClassName", "SystemName",
225
"SystemCreationClassName"};
230
if ((id = CMGetKeyString(cop, key[0], rc)) == NULL ) {
231
rc->rc = CMPI_RC_ERR_FAILED;
232
cl_log(LOG_ERR, "del_cons: can't get constraint id.");
238
funcid = DEL_ORDER_CONSTRAINT;
240
case TID_CONS_LOCATION:
241
funcid = DEL_LOCATION_CONSTRAINT;
243
case TID_CONS_COLOCATION:
244
funcid = DEL_COLOCATION_CONSTRAINT;
247
cl_log(LOG_WARNING, "del_cons: Unknown type");
250
if ( cim_update_dispatch(funcid, id, NULL, NULL) == HA_OK ) {
253
rc->rc = CMPI_RC_ERR_FAILED;
254
cl_log(LOG_ERR, "del_cons: cim_update return error.");
262
constraint_update_inst(CMPIBroker * broker, char * classname,
263
CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt,
264
CMPIObjectPath * cop, CMPIInstance * ci, char ** properties,
265
uint32_t type, CMPIStatus * rc)
267
struct ha_msg * t=NULL;
268
const char * key [] = {"Id", "CreationClassName", "SystemName",
269
"SystemCreationClassName"};
270
char * id, *crname, *sysname, *syscrname;
274
id = CMGetKeyString(cop, key[0], rc);
275
crname = CMGetKeyString(cop, key[1], rc);
276
sysname = CMGetKeyString(cop, key[2], rc);
277
syscrname = CMGetKeyString(cop, key[3], rc);
281
t = cim_query_dispatch(GET_ORDER_CONSTRAINT, id, NULL);
282
cmpi_inst2msg(ci, HA_ORDER_CONSTRAINT, t, rc);
283
ret = cim_update_dispatch(UPDATE_ORDER_CONSTRAINT, NULL, t, NULL);
285
case TID_CONS_LOCATION:
286
t = cim_query_dispatch(GET_LOCATION_CONSTRAINT, id, NULL);
287
cmpi_inst2msg(ci, HA_LOCATION_CONSTRAINT, t, rc);
288
ret = cim_update_dispatch(UPDATE_LOCATION_CONSTRAINT, NULL, t, NULL);
290
case TID_CONS_COLOCATION:
291
t = cim_query_dispatch(GET_COLOCATION_CONSTRAINT, id, NULL);
292
cmpi_inst2msg(ci, HA_COLOCATION_CONSTRAINT, t, rc);
293
ret = cim_update_dispatch(UPDATE_COLOCATION_CONSTRAINT, NULL, t, NULL);
299
/* if update OK, return CMPI_RC_OK */
300
rc->rc = (ret == HA_OK)? CMPI_RC_OK : CMPI_RC_ERR_FAILED;
306
constraint_create_inst(CMPIBroker * broker, char * classname,
307
CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt,
308
CMPIObjectPath * cop, CMPIInstance * ci, uint32_t type,
315
if (( t = ha_msg_new(16)) == NULL ) {
316
rc->rc = CMPI_RC_ERR_FAILED;
322
cmpi_inst2msg(ci, HA_ORDER_CONSTRAINT, t, rc);
323
ret = cim_update_dispatch(UPDATE_ORDER_CONSTRAINT, NULL, t, NULL);
325
case TID_CONS_LOCATION:
326
cmpi_inst2msg(ci, HA_LOCATION_CONSTRAINT, t, rc);
327
ret = cim_update_dispatch(UPDATE_LOCATION_CONSTRAINT, NULL, t, NULL);
329
case TID_CONS_COLOCATION:
330
cmpi_inst2msg(ci, HA_COLOCATION_CONSTRAINT, t, rc);
331
ret = cim_update_dispatch(UPDATE_COLOCATION_CONSTRAINT, NULL, t, NULL);
335
rc->rc = (ret==HA_OK)? CMPI_RC_OK : CMPI_RC_ERR_FAILED;