command for accepting the proposed renewal, what user needs to type down at a console client (vm_renewal) to renew his suspension time.
Any ideas to do it better?
ps: (This file needs to be in the path enviroment variable ofc)
Edited
command for accepting the proposed renewal, what user needs to type down at a console client (vm_renewal) to renew his suspension time.
Any ideas to do it better?
ps: (This file needs to be in the path enviroment variable ofc)
I checked into this. If we switch to urllib2 we still need to generate a fake data so we achive that the urllib2 sends a POST instead of a GET and in the response we loose the ability to easily check the headers. Even checking the returned page status code requires 2.6+ python. Are you sure it's worth the switch? I remember I ran into this problem when i made this code, but i double checked it now, to be sure.
So it would look something like this:
# Load the saved urlurl=pickle.load(open("%s/%s"%(get_temp_dir(),file_name),"rb"))# Fake data to post so we make urllib2 send a POST instead of a GETdata=urllib.urlencode(dict(fromPhyton='True'))# do POST request to req=urllib2.Request(url,data)rsp=urllib2.urlopen(req)# Get the result of the request - NOTE: only works past 2.6+ pythonifrsp.getcode()==200:logger.info("Successfull renew, 200 - OK")done=Trueelifrsp.getcode()==302:logger.info("Response is 302 - FOUND")done=Trueelse:logger.error("Renewal failed please try it manually at %s"%url)# POST request was sent and received successfullyifdone:wall("Successfull renewal of this vm!")os.remove("%s/%s"%(get_temp_dir(),file_name))
Edited
I checked into this. If we switch to urllib2 we still need to generate a fake data so we achive that the urllib2 sends a POST instead of a GET and in the response we loose the ability to easily check the headers. Even checking the returned page status code requires 2.6+ python. Are you sure it's worth the switch? I remember I ran into this problem when i made this code, but i double checked it now, to be sure.
So it would look something like this:
```python
# Load the saved url
url = pickle.load(open("%s/%s" % (get_temp_dir(), file_name), "rb"))
# Fake data to post so we make urllib2 send a POST instead of a GET
data = urllib.urlencode(dict(fromPhyton='True'))
# do POST request to
req = urllib2.Request(url, data)
rsp = urllib2.urlopen(req)
# Get the result of the request - NOTE: only works past 2.6+ python
if rsp.getcode() == 200:
logger.info("Successfull renew, 200 - OK")
done = True
elif rsp.getcode() == 302:
logger.info("Response is 302 - FOUND")
done = True
else:
logger.error("Renewal failed please try it manually at %s" % url)
# POST request was sent and received successfully
if done:
wall("Successfull renewal of this vm!")
os.remove("%s/%s" % (get_temp_dir(), file_name))
```
* we do have python2.6+
* urllib2 code seems much better
* `data=""` is more simple
* you can both get the response and send custom request headers
```
req = Request("http://postcatcher.in/catchers/53d0c38b10b71c02000004c5", "", {'x-hello': 3})
resp = urlopen(req)
resp.info()['x-powered-by']
# OUT: 'Express'
```
Dosen't that just only makes it more pythonic or using a < b < c have benefits in runtime over the current one?
And sure it can be changed to try except format too if needed.
But maybe it would be even better to delete the whole checking as I recently learned about 2to3 python tool, which renders this useless
Edited
Dosen't that just only makes it more pythonic or using a < b < c have benefits in runtime over the current one?
And sure it can be changed to try except format too if needed.
But maybe it would be even better to delete the whole checking as I recently learned about 2to3 python tool, which renders this useless
or you could even use json :)
in this case i wouldn't care the run time of this expression, but the compact form must be slightly quicker as it evaluates b only once
or you could even use json :)
in this case i wouldn't care the run time of this expression, but the compact form must be slightly quicker as it evaluates `b` only once
I could, but the main idea was to spam the user with information about the incoming suspension. Shouldn't a renew error be spammed too? Considering the other errors are all wall-ed too.
Edited
I could, but the main idea was to spam the user with information about the incoming suspension. Shouldn't a renew error be spammed too? Considering the other errors are all wall-ed too.