File: ribcl.py.in

package info (click to toggle)
cluster-glue 1.0.12-12
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,788 kB
  • sloc: ansic: 43,010; sh: 5,578; python: 942; makefile: 587; perl: 375; xml: 101
file content (101 lines) | stat: -rw-r--r-- 2,478 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!@PYTHON@


#
# 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 sys
import socket
from http.client import *
from time import sleep


argv = sys.argv


try:
        host = argv[1].split('.')[0]+'-rm'
        cmd = argv[2]
except IndexError:
        print("Not enough arguments")
        sys.exit(1)


login = [ '<RIBCL VERSION="1.2">',
          '<LOGIN USER_LOGIN="Administrator" 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 }


acmds=[]
try:
        if cmd == 'reset' and host.startswith('gfxcl'):
                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(host)
                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 as msg:
        print(msg)
        sys.exit(1)
except socket.sslerror as msg:
        print(msg)
        sys.exit(1)
except socket.error as msg:
        print(msg)
        sys.exit(1)