Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e59d6102
authored
Jul 24, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite to expect json form result
requires modifications of cloud:feature-agent-renew
parent
32a65e73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
25 deletions
+22
-25
notify.py
+22
-25
No files found.
notify.py
View file @
e59d6102
...
...
@@ -46,32 +46,29 @@ def wall(text):
def
accept
():
import
urllib2
if
not
os
.
path
.
isfile
(
"
%
s/
%
s"
%
(
get_temp_dir
(),
file_name
)):
logger
.
error
(
"There isn't a request received currently"
)
else
:
done
=
False
# 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
# do POST request to
req
=
urllib2
.
Request
(
url
,
""
)
file_path
=
os
.
path
.
join
(
get_temp_dir
(),
file_name
)
if
not
os
.
path
.
isfile
(
file_path
):
print
"There is no recent notification to accept."
return
False
# Load the saved url
url
=
json
.
load
(
open
(
file_path
,
"r"
))
# Fake data to post so we make urllib2 send a POST instead of a GET
# do POST request to
req
=
urllib2
.
Request
(
url
,
""
,
{
"http_accept"
:
"application/json"
})
try
:
rsp
=
urllib2
.
urlopen
(
req
)
# Get the result of the request
success
=
rsp
.
info
()[
'renewal'
]
if
success
is
not
None
or
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
:
print
"Successfull renewal of this vm!"
os
.
remove
(
"
%
s/
%
s"
%
(
get_temp_dir
(),
file_name
))
data
=
json
.
load
(
rsp
)
newtime
=
data
[
"new_suspend_time"
]
except
:
print
"Renewal failed. Please try it manually at
%
s"
%
url
logger
.
exception
(
"renew failed"
)
return
False
else
:
print
"Renew succeeded. The machine will be suspended at
%
s."
%
newtime
os
.
remove
(
file_path
)
return
True
def
notify
(
url
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment