~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to lib/plugins/stonith/ribcl.py.in

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2010-02-17 21:59:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217215918-06paxph5do4saw8v
Tags: 3.0.2-0ubuntu1
* New upstream release
* Drop hard dep on pacemaker for heartbet; moved to Recommends
* debian/heartbeat.install:
  - follow upstream changes
* debian/control:
  - added docbook-xsl and xsltproc to build depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!@PYTHON@
2
 
 
3
 
 
4
 
#
5
 
# This library is free software; you can redistribute it and/or
6
 
# modify it under the terms of the GNU Lesser General Public
7
 
# License as published by the Free Software Foundation; either
8
 
# version 2.1 of the License, or (at your option) any later version.
9
 
10
 
# This library is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
# Lesser General Public License for more details.
14
 
15
 
# You should have received a copy of the GNU Lesser General Public
16
 
# License along with this library; if not, write to the Free Software
17
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
#
19
 
 
20
 
import sys
21
 
import socket
22
 
from httplib import *
23
 
from time import sleep
24
 
 
25
 
 
26
 
argv = sys.argv
27
 
 
28
 
 
29
 
try:
30
 
        host = argv[1].split('.')[0]+'-rm'
31
 
        cmd = argv[2]
32
 
except IndexError:
33
 
        print "Not enough arguments"
34
 
        sys.exit(1)
35
 
 
36
 
 
37
 
login = [ '<RIBCL VERSION="1.2">',
38
 
          '<LOGIN USER_LOGIN="Administrator" PASSWORD="********">' ]
39
 
 
40
 
 
41
 
logout = [ '</LOGIN>', '</RIBCL>' ]
42
 
 
43
 
 
44
 
status = [ '<SERVER_INFO MODE="read">', '<GET_HOST_POWER_STATUS/>',
45
 
           '</SERVER_INFO>' ]
46
 
 
47
 
 
48
 
reset = [ '<SERVER_INFO MODE="write">', '<RESET_SERVER/>', '</SERVER_INFO>' ]
49
 
 
50
 
 
51
 
off = [ '<SERVER_INFO MODE = "write">', '<SET_HOST_POWER HOST_POWER  = "N"/>',
52
 
          '</SERVER_INFO>' ]
53
 
 
54
 
 
55
 
on = [ '<SERVER_INFO MODE = "write">', '<SET_HOST_POWER HOST_POWER  = "Y"/>',
56
 
          '</SERVER_INFO>' ]
57
 
 
58
 
 
59
 
todo = { 'reset':reset, 'on':on, 'off':off, 'status':status }
60
 
 
61
 
 
62
 
acmds=[]
63
 
try:
64
 
        if cmd == 'reset' and host.startswith('gfxcl'):
65
 
                acmds.append(login + todo['off'] + logout)
66
 
                acmds.append(login + todo['on'] + logout)
67
 
        else:   
68
 
                acmds.append(login + todo[cmd] + logout)
69
 
except KeyError:
70
 
        print "Invalid command: "+ cmd
71
 
        sys.exit(1)
72
 
 
73
 
 
74
 
try:
75
 
        for cmds in acmds:
76
 
 
77
 
 
78
 
                c=HTTPSConnection(host)
79
 
                c.send('<?xml version="1.0"?>\r\n')
80
 
                c.sock.recv(1024)
81
 
 
82
 
 
83
 
                for line in cmds:
84
 
                        c.send(line+'\r\n')
85
 
                        c.sock.recv(1024)
86
 
 
87
 
 
88
 
                c.close()
89
 
                sleep(1)
90
 
 
91
 
 
92
 
except socket.gaierror, msg:
93
 
        print msg
94
 
        sys.exit(1)
95
 
except socket.sslerror, msg:
96
 
        print msg
97
 
        sys.exit(1)
98
 
except socket.error, msg:
99
 
        print msg
100
 
        sys.exit(1)
101