From 3ac95d9da4e207f5d1db14ecbf9c10c13247dd45 Mon Sep 17 00:00:00 2001 From: Jeremy Puhlman Date: Wed, 19 Feb 2020 22:35:51 +0000 Subject: [PATCH] Update for python3 Upstream-Status: Inappropriate --- lib/plugins/stonith/external/dracmc-telnet | 10 +++++----- lib/plugins/stonith/external/ibmrsa-telnet | 8 ++++---- lib/plugins/stonith/external/riloe | 30 +++++++++++++++--------------- lib/plugins/stonith/ribcl.py.in | 20 ++++++++++---------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/plugins/stonith/external/dracmc-telnet b/lib/plugins/stonith/external/dracmc-telnet index 78c01453..7fbed86b 100644 --- a/lib/plugins/stonith/external/dracmc-telnet +++ b/lib/plugins/stonith/external/dracmc-telnet @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vim: set filetype=python ####################################################################### # @@ -74,7 +74,7 @@ class DracMC(telnetlib.Telnet): def _get_timestamp(self): ct = time.time() - msecs = (ct - long(ct)) * 1000 + msecs = (ct - int(ct)) * 1000 return "%s,%03d" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ct)), msecs) @@ -170,7 +170,7 @@ class DracMCStonithPlugin: def _get_timestamp(self): ct = time.time() - msecs = (ct - long(ct)) * 1000 + msecs = (ct - int(ct)) * 1000 return "%s,%03d" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ct)), msecs) @@ -200,7 +200,7 @@ class DracMCStonithPlugin: self._parameters['cyclades_port']) c.login(self._parameters['username'], self._parameters['password']) - except Exception, args: + except Exception as args: if "Connection reset by peer" in str(args): self._echo_debug("Someone is already logged in... retry=%s" % tries) c.close() @@ -362,7 +362,7 @@ class DracMCStonithPlugin: func = getattr(self, cmd, self.not_implemented) rc = func() return(rc) - except Exception, args: + except Exception as args: self.echo_log("err", 'Exception raised:', str(args)) if self._connection: self.echo_log("err", self._connection.get_history()) diff --git a/lib/plugins/stonith/external/ibmrsa-telnet b/lib/plugins/stonith/external/ibmrsa-telnet index adb2a3eb..0a3ce3c2 100644 --- a/lib/plugins/stonith/external/ibmrsa-telnet +++ b/lib/plugins/stonith/external/ibmrsa-telnet @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # vim: set filetype=python ####################################################################### # @@ -71,7 +71,7 @@ class RSABoard(telnetlib.Telnet): def _get_timestamp(self): ct = time.time() - msecs = (ct - long(ct)) * 1000 + msecs = (ct - int(ct)) * 1000 return "%s,%03d" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ct)), msecs) @@ -149,7 +149,7 @@ class RSAStonithPlugin: def _get_timestamp(self): ct = time.time() - msecs = (ct - long(ct)) * 1000 + msecs = (ct - int(ct)) * 1000 return "%s,%03d" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ct)), msecs) @@ -305,7 +305,7 @@ class RSAStonithPlugin: func = getattr(self, cmd, self.not_implemented) rc = func() return(rc) - except Exception, args: + except Exception as args: self.echo_log("err", 'Exception raised:', str(args)) if self._connection: self.echo_log("err", self._connection.get_history()) diff --git a/lib/plugins/stonith/external/riloe b/lib/plugins/stonith/external/riloe index 412873f5..370fd57f 100644 --- a/lib/plugins/stonith/external/riloe +++ b/lib/plugins/stonith/external/riloe @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Stonith module for RILOE Stonith device # @@ -35,7 +35,7 @@ import os import socket import subprocess import xml.dom.minidom -import httplib +import http.client import time import re @@ -163,12 +163,12 @@ info = { } if cmd in info: - print info[cmd] + print(info[cmd]) sys.exit(0) if cmd == 'getconfignames': for arg in [ "hostlist", "ilo_hostname", "ilo_user", "ilo_password", "ilo_can_reset", "ilo_protocol", "ilo_powerdown_method", "ilo_proxyhost", "ilo_proxyport"]: - print arg + print(arg) sys.exit(0) if not rihost: @@ -257,7 +257,7 @@ def read_resp(node): ''' msg = "" str_status = "" - for attr in node.attributes.keys(): + for attr in list(node.attributes.keys()): if attr == A_STATUS: str_status = node.getAttribute(attr) elif attr == A_MSG: @@ -285,7 +285,7 @@ def read_power(node): variable correspondingly. ''' global power - for attr in node.attributes.keys(): + for attr in list(node.attributes.keys()): if attr == A_POWER_STATE: power_state = node.getAttribute(attr).upper() else: @@ -339,18 +339,18 @@ def open_ilo(host): fatal("Error status=: %s" %(response)) import ssl sock = ssl.wrap_socket(proxy) - h=httplib.HTTPConnection('localhost') + h=http.client.HTTPConnection('localhost') h.sock=sock return h else: - return httplib.HTTPSConnection(host) - except socket.gaierror, msg: + return http.client.HTTPSConnection(host) + except socket.gaierror as msg: fatal("%s: %s" %(msg,host)) - except socket.sslerror, msg: + except socket.sslerror as msg: fatal("%s for %s" %(msg,host)) - except socket.error, msg: + except socket.error as msg: fatal("%s while talking to %s" %(msg,host)) - except ImportError, msg: + except ImportError as msg: fatal("ssl support missing (%s)" %msg) def send_request(req,proc_f): @@ -364,7 +364,7 @@ def send_request(req,proc_f): c = open_ilo(rihost) try: c.send(req+'\r\n') - except socket.error, msg: + except socket.error as msg: fatal("%s, while talking to %s" %(msg,rihost)) t_end = time.time() my_debug("request sent in %0.2f s" % ((t_end-t_begin))) @@ -377,7 +377,7 @@ def send_request(req,proc_f): if not reply: break result.append(reply) - except socket.error, msg: + except socket.error as msg: if msg[0] == 6: # connection closed break my_err("%s, while talking to %s" %(msg,rihost)) @@ -393,7 +393,7 @@ def send_request(req,proc_f): reply = re.sub("<(RIBCL.*)/>", r"<\1>", reply) try: doc = xml.dom.minidom.parseString(reply) - except xml.parsers.expat.ExpatError,msg: + except xml.parsers.expat.ExpatError as msg: fatal("malformed response: %s\n%s"%(msg,reply)) rc = proc_f(doc) doc.unlink() diff --git a/lib/plugins/stonith/ribcl.py.in b/lib/plugins/stonith/ribcl.py.in index 0733bb24..3533dee3 100644 --- a/lib/plugins/stonith/ribcl.py.in +++ b/lib/plugins/stonith/ribcl.py.in @@ -1,4 +1,4 @@ -#!@TRAGET_PYTHON@ +#!/usr/bin/env python3 # @@ -18,7 +18,7 @@ import sys import socket -from httplib import * +from http.client import * from time import sleep @@ -29,7 +29,7 @@ try: host = argv[1].split('.')[0]+'-rm' cmd = argv[2] except IndexError: - print "Not enough arguments" + print("Not enough arguments") sys.exit(1) @@ -66,7 +66,7 @@ try: else: acmds.append(login + todo[cmd] + logout) except KeyError: - print "Invalid command: "+ cmd + print("Invalid command: "+ cmd) sys.exit(1) @@ -88,13 +88,13 @@ try: sleep(1) -except socket.gaierror, msg: - print msg +except socket.gaierror as msg: + print(msg) sys.exit(1) -except socket.sslerror, msg: - print msg +except socket.sslerror as msg: + print(msg) sys.exit(1) -except socket.error, msg: - print msg +except socket.error as msg: + print(msg) sys.exit(1) -- 2.13.3