Fixes python 3 support for cluster-dns images scripts
The cluster-dns images' scripts are only working with Python 2. Considering that Python 2 support will be dropped in 2020, it would be a good idea to transition towards Python 3 support. This commit the cluster-dns Python scripts to work on both Python versions.
This commit is contained in:
parent
a5fc981e3b
commit
12f77704a3
|
@ -14,7 +14,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler,HTTPServer
|
||||||
|
|
||||||
PORT_NUMBER = 8000
|
PORT_NUMBER = 8000
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ class HTTPHandler(BaseHTTPRequestHandler):
|
||||||
try:
|
try:
|
||||||
# Create a web server and define the handler to manage the incoming request.
|
# Create a web server and define the handler to manage the incoming request.
|
||||||
server = HTTPServer(('', PORT_NUMBER), HTTPHandler)
|
server = HTTPServer(('', PORT_NUMBER), HTTPHandler)
|
||||||
print 'Started httpserver on port ' , PORT_NUMBER
|
print('Started httpserver on port ', PORT_NUMBER)
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print '^C received, shutting down the web server'
|
print('^C received, shutting down the web server')
|
||||||
server.socket.close()
|
server.socket.close()
|
||||||
|
|
|
@ -17,21 +17,25 @@
|
||||||
import argparse
|
import argparse
|
||||||
import requests
|
import requests
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
from urlparse import urlparse
|
if sys.version_info[0] < 3:
|
||||||
|
from urlparse import urlparse
|
||||||
|
else:
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
def CheckServiceAddress(address):
|
def CheckServiceAddress(address):
|
||||||
hostname = urlparse(address).hostname
|
hostname = urlparse(address).hostname
|
||||||
service_address = socket.gethostbyname(hostname)
|
service_address = socket.gethostbyname(hostname)
|
||||||
print service_address
|
print(service_address)
|
||||||
|
|
||||||
|
|
||||||
def GetServerResponse(address):
|
def GetServerResponse(address):
|
||||||
print 'Send request to:', address
|
print('Send request to:', address)
|
||||||
response = requests.get(address)
|
response = requests.get(address)
|
||||||
print response
|
print(response)
|
||||||
print response.content
|
print(response.content)
|
||||||
|
|
||||||
|
|
||||||
def Main():
|
def Main():
|
||||||
|
|
Loading…
Reference in New Issue