Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
agentdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3b828db2
authored
Jun 09, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle responses from agent
parent
c2d8f7e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
1 deletions
+37
-1
protocol.py
+37
-1
No files found.
protocol.py
View file @
3b828db2
...
...
@@ -5,7 +5,9 @@ import pickle
import
logging
import
time
import
struct
from
threading
import
Event
from
os
import
getenv
from
celery.result
import
TimeoutError
from
utils
import
SerialLineReceiverBase
...
...
@@ -62,8 +64,9 @@ class SerialLineReceiver(SerialLineReceiverBase):
agent_stopped
.
apply_async
(
queue
=
'localhost.man'
,
args
=
(
self
.
factory
.
vm
,
))
if
command
==
'agent_started'
:
version
=
args
.
get
(
'version'
,
None
)
agent_started
.
apply_async
(
queue
=
'localhost.man'
,
args
=
(
self
.
factory
.
vm
,
))
args
=
(
self
.
factory
.
vm
,
version
))
if
command
==
'ping'
:
self
.
send_response
(
response
=
'pong'
,
args
=
args
)
...
...
@@ -71,6 +74,14 @@ class SerialLineReceiver(SerialLineReceiverBase):
def
handle_response
(
self
,
response
,
args
):
if
response
==
'status'
:
self
.
send_to_graphite
(
args
)
else
:
uuid
=
args
.
get
(
'uuid'
,
None
)
if
not
uuid
:
return
event
=
self
.
factory
.
running_tasks
.
get
(
uuid
,
None
)
if
event
:
self
.
factory
.
ended_tasks
[
uuid
]
=
args
event
.
set
()
def
connectionMade
(
self
):
logger
.
info
(
"connected to
%
s"
%
self
.
factory
.
vm
)
...
...
@@ -80,9 +91,34 @@ class SerialLineReceiver(SerialLineReceiverBase):
logger
.
info
(
"disconnected from
%
s"
%
self
.
factory
.
vm
)
del
reactor
.
connections
[
self
.
factory
.
vm
]
def
send_command
(
self
,
command
,
args
,
timeout
=
10.0
,
uuid
=
None
):
if
not
uuid
:
super
(
SerialLineReceiver
,
self
)
.
send_command
(
command
,
args
)
return
event
=
Event
()
args
[
'uuid'
]
=
uuid
self
.
factory
.
running_tasks
[
uuid
]
=
event
self
.
factory
.
ended_tasks
[
uuid
]
=
None
super
(
SerialLineReceiver
,
self
)
.
send_command
(
command
,
args
)
success
=
event
.
wait
(
timeout
)
retval
=
self
.
factory
.
ended_tasks
[
uuid
]
del
self
.
factory
.
ended_tasks
[
uuid
]
del
self
.
factory
.
running_tasks
[
uuid
]
if
not
success
:
raise
TimeoutError
()
return
retval
class
SerialLineReceiverFactory
(
protocol
.
ClientFactory
):
protocol
=
SerialLineReceiver
def
__init__
(
self
,
vm
):
self
.
vm
=
vm
self
.
running_tasks
=
{}
self
.
ended_tasks
=
{}
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