22utils for discovery cluster
33"""
44from distutils .version import StrictVersion
5+ from django .utils .encoding import smart_text
56import re
67from telnetlib import Telnet
78
@@ -28,20 +29,20 @@ def get_cluster_info(host, port):
2829 }
2930 """
3031 client = Telnet (host , int (port ))
31- client .write ('version\n ' )
32- res = client .read_until ('\r \n ' ).strip ()
33- version_list = res .split (' ' )
34- if len (version_list ) != 2 or version_list [0 ] != 'VERSION' :
32+ client .write (b 'version\n ' )
33+ res = client .read_until (b '\r \n ' ).strip ()
34+ version_list = res .split (b ' ' )
35+ if len (version_list ) != 2 or version_list [0 ] != b 'VERSION' :
3536 raise WrongProtocolData ('version' , res )
3637 version = version_list [1 ]
37- if StrictVersion (version ) >= StrictVersion ('1.4.14' ):
38- cmd = 'config get cluster\n '
38+ if StrictVersion (smart_text ( version ) ) >= StrictVersion ('1.4.14' ):
39+ cmd = b 'config get cluster\n '
3940 else :
40- cmd = 'get AmazonElastiCache:cluster\n '
41+ cmd = b 'get AmazonElastiCache:cluster\n '
4142 client .write (cmd )
42- res = client .read_until ('\n \r \n END\r \n ' )
43+ res = client .read_until (b '\n \r \n END\r \n ' )
4344 client .close ()
44- ls = list (filter (None , re .compile (r '\r?\n' ).split (res )))
45+ ls = list (filter (None , re .compile (br '\r?\n' ).split (res )))
4546 if len (ls ) != 4 :
4647 raise WrongProtocolData (cmd , res )
4748
@@ -51,9 +52,10 @@ def get_cluster_info(host, port):
5152 raise WrongProtocolData (cmd , res )
5253 nodes = []
5354 try :
54- for node in ls [2 ].split (' ' ):
55- host , ip , port = node .split ('|' )
56- nodes .append ('{}:{}' .format (ip or host , port ))
55+ for node in ls [2 ].split (b' ' ):
56+ host , ip , port = node .split (b'|' )
57+ nodes .append ('{}:{}' .format (smart_text (ip or host ),
58+ smart_text (port )))
5759 except ValueError :
5860 raise WrongProtocolData (cmd , res )
5961 return {
0 commit comments