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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
21 deletions
+18
-21
notify.py
+18
-21
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"
})
rsp
=
urllib2
.
urlopen
(
req
)
# Get the result of the request
try
:
success
=
rsp
.
info
()[
'renewal'
]
rsp
=
urllib2
.
urlopen
(
req
)
if
success
is
not
None
or
rsp
.
getcode
()
==
200
:
data
=
json
.
load
(
rsp
)
logger
.
info
(
"Successfull renew, 200 - OK"
)
newtime
=
data
[
"new_suspend_time"
]
done
=
True
except
:
elif
rsp
.
getcode
()
==
302
:
print
"Renewal failed. Please try it manually at
%
s"
%
url
logger
.
info
(
"Response is 302 - FOUND
"
)
logger
.
exception
(
"renew failed
"
)
done
=
Tru
e
return
Fals
e
else
:
else
:
logger
.
error
(
"Renewal failed please try it manually at
%
s"
%
url
)
print
"Renew succeeded. The machine will be suspended at
%
s."
%
newtime
# POST request was sent and received successfully
os
.
remove
(
file_path
)
if
done
:
return
True
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