⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 riloe.in

📁 Linux Heartbeat Source Code
💻 IN
字号:
#!@PYTHON@## Stonith module for RILOE Stonith device## Copyright (c) 2004 Alain St-Denis <alain.st-denis@ec.gc.ca>## Modified by Alan Robertson <alanr@unix.sh> for STONITH external compatibility.## 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#import sysimport osimport socketfrom httplib import *from time import sleepargv = sys.argv#   If device name is not set,	We assume the device name for node #   X.foo.bar.com is X-rm and is accessible as a local (non-FQDN) #   DNS name.try:        cmd = argv[1]except IndexError:        print "Not enough arguments"        sys.exit(1)try:        password = os.environ['RI_PASSWORD']        os.environ['RI_PASSWORD'] = "********"        anypass=1except KeyError:        password = ""        anypass=0loginname = os.environ.get('RO_LOGIN', "Administrator")		rihost = os.environ.get('RI_HOSTRI', "")host = os.environ.get('RI_HOST', "<unconfigured>")if rihost == "" and host != "<unconfigured>":        rihost = host.split('.')[0]+'-rm'#	Some old RILOE devices don't support the reset command#	This variable is 1 if it does.try:        reset_ok = os.environ["RI_CAN_RESET"]        if reset_ok == '':                reset_ok = Noneexcept KeyError:        reset_ok = Nonelogin = [ '<RIBCL VERSION="1.2">',          '<LOGIN USER_LOGIN="' + loginname + '" PASSWORD="' + password + '">' ]logout = [ '</LOGIN>', '</RIBCL>' ]status = [ '<SERVER_INFO MODE="read">', '<GET_HOST_POWER_STATUS/>',           '</SERVER_INFO>' ]reset = [ '<SERVER_INFO MODE="write">', '<RESET_SERVER/>', '</SERVER_INFO>' ]off = [ '<SERVER_INFO MODE = "write">', '<SET_HOST_POWER HOST_POWER  = "N"/>',          '</SERVER_INFO>' ]on = [ '<SERVER_INFO MODE = "write">', '<SET_HOST_POWER HOST_POWER  = "Y"/>',          '</SERVER_INFO>' ]todo = { 'reset':reset, 'on':on, 'off':off, 'status':status }xmlinfo = '''<parameters><parameter name="RI_HOST" unique="1"><content type="string" /><shortdesc lang="en">Host</shortdesc><longdesc lang="en">The host that the STONITH device controls</longdesc></parameter><parameter name="RI_HOSTRI" unique="1"><content type="string" /><shortdesc lang="en">Host riLo device</shortdesc><longdesc lang="en">The address of the STONITH device </longdesc></parameter><parameter name="RI_LOGIN" unique="1"><content type="string" /><shortdesc lang="en">Login accout</shortdesc><longdesc lang="en">The login accout for control the STONITH device</longdesc></parameter><parameter name="RI_PASSWORD" unique="1"><content type="string" /><shortdesc lang="en">Login password</shortdesc><longdesc lang="en">The password for login into the STONITH device</longdesc></parameter></parameters>'''info = {        'getinfo-devid':	'RILOE',        'getinfo-devname':	'riloe ' + rihost,        'getinfo-devdescr':	'COMPAQ RILOE STONITH device',        'getinfo-devurl':	'http://www.hp.com/',        'gethosts':			host,        'getinfo-xml':		xmlinfo}try:        print info[cmd]        sys.exit(0)except KeyError:        Noneif cmd == 'getconfignames':        for arg in ['RI_HOST', 'RI_HOSTRI', 'RI_LOGIN', 'RI_PASSWORD']:            print arg        sys.exit(0)##	All remaining commands need host and password to succeed...#if host == '<unconfigured>':        print "Missing 'RI_HOST' environment variable"        sys.exit(1)if not anypass:        print "Missing 'RI_PASSWORD' environment variable"        sys.exit(1)acmds=[]try:        if cmd == 'reset' and not reset_ok:                acmds.append(login + todo['off'] + logout)                acmds.append(login + todo['on'] + logout)        else:                   acmds.append(login + todo[cmd] + logout)except KeyError:        print 'Invalid command: '+ cmd        sys.exit(1)try:        for cmds in acmds:                c=HTTPSConnection(rihost)                c.send('<?xml version="1.0"?>\r\n')                c.sock.recv(1024)                for line in cmds:                        c.send(line+'\r\n')                        c.sock.recv(1024)                c.close()                sleep(1)except socket.gaierror, msg:        print "ERROR: " + str(msg) + ": " + rihost        sys.exit(1)except socket.sslerror, msg:        print "ERROR: " + str(msg) + "for " + rihost        sys.exit(1)except socket.error, msg:        print "ERROR: " + str(msg) + "talking to " + rihost        sys.exit(1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -