Commit aa01db5b by Csók Tamás

Corrections based on merge request inputs

parent 951d822b
#!/usr/bin/python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
## ##
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
## ##
import platform, logging, os, subprocess, webbrowser, sys import platform, logging, os, subprocess, webbrowser, sys
if sys.hexversion < 0x03000000 and sys.hexversion > 0x02000000: import cPickle as pickle
import cPickle as pickle
else:
import pickle
system = platform.system() system = platform.system()
logger = logging.getLogger() logger = logging.getLogger()
...@@ -43,32 +40,24 @@ def wall(text): ...@@ -43,32 +40,24 @@ def wall(text):
def accept(): def accept():
import httplib import urllib2, urllib
if not os.path.isfile("%s/%s" % (get_temp_dir(), file_name)): if not os.path.isfile("%s/%s" % (get_temp_dir(), file_name)):
logger.error("There isn't a request received currently") logger.error("There isn't a request received currently")
else: else:
done = False done = False
# Load the saved url # Load the saved url
url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb")) url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb"))
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} # Fake data to post so we make urllib2 send a POST instead of a GET
# Delete https:// or http:// from beginning # do POST request to
if url[:4].lower() == 'http': req = urllib2.Request(url, "")
url = url[url.find("/")+2:] rsp = urllib2.urlopen(req)
# Try to connect to the specified URL
conn = httplib.HTTPConnection(url[:url.find("/")])
logger.info("Connection requested to %s" % url[:url.find("/")])
# Create the POST http request
conn.request("POST", url[url.find("/"):], "", headers)
logger.info("Post reques sent to %s" % url)
# Get the result of the request # Get the result of the request
response = conn.getresponse() success = rsp.info()['renewal']
success = response.getheader('renewal') if success is not None or rsp.getcode() == 200:
if success is None:
success = ''
if success.lower() == 'success' or response.status == httplib.OK:
logger.info("Successfull renew, 200 - OK") logger.info("Successfull renew, 200 - OK")
done = True done = True
elif response.status == httplib.FOUND: elif rsp.getcode() == 302:
logger.info("Response is 302 - FOUND") logger.info("Response is 302 - FOUND")
done = True done = True
else: else:
......
#!/usr/bin/python #!/usr/bin/env python
import notify import notify
if __name__ == '__main__': if __name__ == '__main__':
try: try:
notify.accept() notify.accept()
finally: except:
pass notify.wall("There was an unknown error while trying to renew this vm, please do it manually!")
Please register or sign in to reply
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment