Commit e59d6102 by Őry Máté

rewrite to expect json form result

requires modifications of cloud:feature-agent-renew
parent 32a65e73
...@@ -46,32 +46,29 @@ def wall(text): ...@@ -46,32 +46,29 @@ def wall(text):
def accept(): def accept():
import urllib2 file_path = os.path.join(get_temp_dir(), file_name)
if not os.path.isfile("%s/%s" % (get_temp_dir(), file_name)): if not os.path.isfile(file_path):
logger.error("There isn't a request received currently") print "There is no recent notification to accept."
else: return False
done = False
# Load the saved url # Load the saved url
url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb")) url = json.load(open(file_path, "r"))
# Fake data to post so we make urllib2 send a POST instead of a GET # Fake data to post so we make urllib2 send a POST instead of a GET
# do POST request to # do POST request to
req = urllib2.Request(url, "") req = urllib2.Request(url, "", {"http_accept": "application/json"})
try:
rsp = urllib2.urlopen(req) rsp = urllib2.urlopen(req)
data = json.load(rsp)
# Get the result of the request newtime = data["new_suspend_time"]
success = rsp.info()['renewal'] except:
if success is not None or rsp.getcode() == 200: print "Renewal failed. Please try it manually at %s" % url
logger.info("Successfull renew, 200 - OK") logger.exception("renew failed")
done = True return False
elif rsp.getcode() == 302: else:
logger.info("Response is 302 - FOUND") print "Renew succeeded. The machine will be suspended at %s." % newtime
done = True os.remove(file_path)
else: return True
logger.error("Renewal failed please try it manually at %s" % url)
# POST request was sent and received successfully
if done:
print "Successfull renewal of this vm!"
os.remove("%s/%s" % (get_temp_dir(), file_name))
def notify(url): def notify(url):
......
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