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):
...
@@ -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
):
...
...
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