Пример #1
0
static int
baytech_status(StonithPlugin  *s)
{
	struct pluginDevice*	bt;
	int	rc;

	ERRIFNOTCONFIGED(s,S_OOPS);

	bt = (struct pluginDevice*) s;
	
	if ((rc = RPCRobustLogin(bt) != S_OK)) {
		LOG(PIL_CRIT, "Cannot log into %s."
		,	bt->idinfo ? bt->idinfo : DEVICE);
		return(rc);
	}

	/* Verify that we're in the top-level menu */
	SEND(bt->wrfd, "\r");

	/* Expect "RPC-x Menu" */
	EXPECT(bt->rdfd, RPC, 5);
	EXPECT(bt->rdfd, Menu, 5);

	return(RPCLogout(bt));
}
Пример #2
0
/*
 *	Reset the given host on this StonithPlugin device.  
 */
static int
apcmaster_reset_req(StonithPlugin * s, int request, const char * host)
{
	int	rc = 0;
	int	lorc = 0;
	struct pluginDevice*	ms;

	ERRIFNOTCONFIGED(s,S_OOPS);

	ms = (struct pluginDevice*) s;

	if ((rc = MSRobustLogin(ms)) != S_OK) {
		LOG(PIL_CRIT, "Cannot log into %s.", ms->idinfo);
		return(rc);
	}else{
		int noutlet; 
		noutlet = MSNametoOutlet(ms, host);
		if (noutlet < 1) {
			LOG(PIL_WARN, "%s doesn't control host [%s]"
			,	ms->device, host);
			return(S_BADHOST);
		}
		switch(request) {

#if defined(ST_POWERON) && defined(ST_POWEROFF)
		case ST_POWERON:
		        rc = apcmaster_onoff(ms, noutlet, host, request);
			break;
		case ST_POWEROFF:
			rc = apcmaster_onoff(ms, noutlet, host, request);
			break;
#endif
		case ST_GENERIC_RESET:
			rc = MSReset(ms, noutlet, host);
			break;
		default:
			rc = S_INVAL;
			break;
		}
	}

	lorc = MSLogout(ms);
	return(rc != S_OK ? rc : lorc);
}
Пример #3
0
static int
wti_mpc_status(StonithPlugin * s)
{
    struct pluginDevice *ad;
    char *ident;

    DEBUGCALL;

    ERRIFNOTCONFIGED(s, S_OOPS);

    ad = (struct pluginDevice *) s;

    if ((ident = MPC_read(ad->sptr, OID_IDENT, ASN_OCTET_STR)) == NULL) {
        LOG(PIL_CRIT, "%s: cannot read ident.", __FUNCTION__);
        return (S_ACCESS);
    }

    /* status ok */
    return (S_OK);
}
Пример #4
0
static int
apcmaster_status(StonithPlugin  *s)
{
	struct pluginDevice*	ms;
	int	rc;

	ERRIFNOTCONFIGED(s,S_OOPS);

	ms = (struct pluginDevice*) s;

	if ((rc = MSRobustLogin(ms) != S_OK)) {
		LOG(PIL_CRIT, "Cannot log into %s.", ms->idinfo);
		return(rc);
	}

	/* Expect ">" */
	SEND(ms->wrfd, "\033\r");
	EXPECT(ms->rdfd, Prompt, 5);

	return(MSLogout(ms));
}
Пример #5
0
static int
wti_mpc_reset_req(StonithPlugin * s, int request, const char *host)
{
    struct pluginDevice *ad;
    char objname[MAX_STRING];
    char value[MAX_STRING];
    char *outlet_name;
    int req_oid = OUTLET_REBOOT;
    int outlet;
    int found_outlet=-1;

    DEBUGCALL;

    ERRIFNOTCONFIGED(s, S_OOPS);

    ad = (struct pluginDevice *) s;

    /* read max. as->num_outlets values */
    for (outlet = 1; outlet <= ad->num_outlets; outlet++) {

        /* prepare objname */
        switch (ad->mib_version) {
        case 3:
            snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V3,outlet);
            break;
        case 1:
        default:
            snprintf(objname,MAX_STRING,OID_GROUP_NAMES_V1,outlet);
            break;
        }

        /* read outlet name */
        if ((outlet_name = MPC_read(ad->sptr, objname, ASN_OCTET_STR))
                ==	NULL) {
            LOG(PIL_CRIT, "%s: cannot read name for outlet %d."
                ,   __FUNCTION__, outlet);
            return (S_ACCESS);
        }
        if (Debug) {
            LOG(PIL_DEBUG, "%s: found outlet: %s.", __FUNCTION__, outlet_name);
        }

        /* found one */
        if (strcasecmp(outlet_name, host) == 0) {
            if (Debug) {
                LOG(PIL_DEBUG, "%s: found %s at outlet %d."
                    ,   __FUNCTION__, host, outlet);
            }

            /* Ok, stop iterating over host list */
            found_outlet=outlet;
            break;
        }
    }
    if (Debug) {
        LOG(PIL_DEBUG, "%s: outlet: %i.", __FUNCTION__, outlet);
    }

    /* host not found in outlet names */
    if (found_outlet == -1) {
        LOG(PIL_CRIT, "%s: no active outlet for '%s'.", __FUNCTION__, host);
        return (S_BADHOST);
    }


    /* choose the OID for the stonith request */
    switch (request) {
    case ST_POWERON:
        req_oid = OUTLET_ON;
        break;
    case ST_POWEROFF:
        req_oid = OUTLET_OFF;
        break;
    case ST_GENERIC_RESET:
        req_oid = OUTLET_REBOOT;
        break;
    default:
        break;
    }

    /* Turn them all off */

    /* prepare objnames */

    switch (ad->mib_version) {
    case 3:
        snprintf(objname,MAX_STRING,OID_GROUP_STATE_V3,found_outlet);
        break;
    case 1:
    default:
        snprintf(objname,MAX_STRING,OID_GROUP_STATE_V1,found_outlet);
        break;
    }

    snprintf(value, MAX_STRING, "%i", req_oid);

    /* send reboot cmd */
    if (!MPC_write(ad->sptr, objname, 'i', value)) {
        LOG(PIL_CRIT
            ,	"%s: cannot send reboot command for outlet %d."
            ,	__FUNCTION__, found_outlet);
        return (S_RESETFAIL);
    }

    return (S_OK);
}
Пример #6
0
/*
 *	Reset the given host on this Stonith device.
 */
static int
baytech_reset_req(StonithPlugin * s, int request, const char * host)
{
	int	rc = S_OK;
	int	lorc = 0;
	struct pluginDevice*	bt;

	ERRIFNOTCONFIGED(s,S_OOPS);

	bt = (struct pluginDevice*) s;

	if ((rc = RPCRobustLogin(bt)) != S_OK) {
		LOG(PIL_CRIT, "Cannot log into %s."
		,	bt->idinfo ? bt->idinfo : DEVICE);
	}else{
		int	noutlets;
		int	outlets[MAXOUTLET];
		int	j;
		noutlets = RPCNametoOutletList(bt, host, outlets);

		if (noutlets < 1) {
			LOG(PIL_CRIT,	"%s %s doesn't control host [%s]"
			,	bt->idinfo, bt->unitid, host);
			return(S_BADHOST);
		}
		switch(request) {

		case ST_POWERON:
		case ST_POWEROFF:
			for (j=0; rc == S_OK && j < noutlets;++j) {
				rc = RPC_onoff(bt, outlets[j], host, request);
			}
			break;
		case ST_GENERIC_RESET:
			/*
			 * Our strategy here:
			 *   1. Power off all outlets except the last one
			 *   2. reset the last outlet
			 *   3. power the other outlets back on
			 */

			for (j=0; rc == S_OK && j < noutlets-1; ++j) {
				rc = RPC_onoff(bt,outlets[j],host
				,	ST_POWEROFF);
			}
			if (rc == S_OK) {
				rc = RPCReset(bt, outlets[j], host); 
			}
			for (j=0; rc == S_OK && j < noutlets-1; ++j) {
				rc = RPC_onoff(bt, outlets[j], host
				,	ST_POWERON);
			}
			break;
		default:
			rc = S_INVAL;
			break;
		}
	}

	lorc = RPCLogout(bt);

	return(rc != S_OK ? rc : lorc);
}
Пример #7
0
static int
external_reset_req(StonithPlugin * s, int request, const char * host)
{
	struct pluginDevice *	sd;
	const char *		op;
	int			rc;
	char *			args1and2;
	int			argslen;
	
	if (Debug) {
		LOG(PIL_DEBUG, "%s: called.", __FUNCTION__);
	}

	ERRIFNOTCONFIGED(s,S_OOPS);
	
	if (Debug) {
		LOG(PIL_DEBUG, "Host external-reset initiating on %s", host);
	}

	sd = (struct pluginDevice*) s;
	if (sd->subplugin == NULL) {
		LOG(PIL_CRIT, "%s: invoked without subplugin", __FUNCTION__);
		return(S_OOPS);
	}

	switch (request) {
		case ST_GENERIC_RESET:
			op = "reset";
			break;

		case ST_POWEROFF:
			op = "off";
			break;
			
		case ST_POWERON:
			op = "on";
			break;
			
		default:
			LOG(PIL_CRIT, "%s: Unknown stonith request %d",
				__FUNCTION__, request);
			return S_OOPS;
			break;
	}
	
	argslen = strlen(op) + strlen(host) + 2 /* 1 for blank, 1 for EOS */;
	args1and2 = (char *)MALLOC(argslen);
	if (args1and2 == NULL) {
		LOG(PIL_CRIT, "%s: out of memory!", __FUNCTION__);
		return S_OOPS;
	}
	rc = snprintf(args1and2, argslen, "%s %s", op, host);
	if (rc <= 0 || rc >= argslen) {
		FREE(args1and2);
		return S_OOPS;
	}
	
	rc = external_run_cmd(sd, args1and2, NULL);
	FREE(args1and2);
	if (rc != 0) {
		LOG(PIL_CRIT, "%s: '%s %s' for host %s failed with rc %d",
			__FUNCTION__, sd->subplugin, op, host, rc);
		return S_RESETFAIL;
	}
	else {
		if (Debug) {
			LOG(PIL_DEBUG, "%s: running '%s %s' returned %d",
				__FUNCTION__, sd->subplugin, op, rc);
		}
		return S_OK;
	}
	
}