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
5e32d6a6
authored
Sep 10, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add search for vrtio device fallback to serial when missing
parent
97f9e18b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
9 deletions
+42
-9
agent.py
+42
-9
No files found.
agent.py
View file @
5e32d6a6
...
@@ -7,10 +7,11 @@ from shutil import copy
...
@@ -7,10 +7,11 @@ from shutil import copy
import
subprocess
import
subprocess
import
sys
import
sys
system
=
platform
.
system
()
try
:
try
:
chdir
(
sys
.
path
[
0
])
chdir
(
sys
.
path
[
0
])
subprocess
.
call
((
'pip'
,
'install'
,
'-r'
,
'requirements.txt'
))
subprocess
.
call
((
'pip'
,
'install'
,
'-r'
,
'requirements.txt'
))
system
=
platform
.
system
()
if
system
==
'Linux'
:
if
system
==
'Linux'
:
copy
(
"/root/agent/misc/vm_renewal"
,
"/usr/local/bin/"
)
copy
(
"/root/agent/misc/vm_renewal"
,
"/usr/local/bin/"
)
except
:
except
:
...
@@ -19,7 +20,7 @@ except:
...
@@ -19,7 +20,7 @@ except:
from
twisted.internet
import
reactor
,
defer
from
twisted.internet
import
reactor
,
defer
from
twisted.internet.task
import
LoopingCall
from
twisted.internet.task
import
LoopingCall
from
twisted.internet.serialport
import
SerialPort
import
uptime
import
uptime
import
logging
import
logging
...
@@ -44,7 +45,6 @@ logger = logging.getLogger()
...
@@ -44,7 +45,6 @@ logger = logging.getLogger()
level
=
environ
.
get
(
'LOGLEVEL'
,
'INFO'
)
level
=
environ
.
get
(
'LOGLEVEL'
,
'INFO'
)
logger
.
setLevel
(
level
)
logger
.
setLevel
(
level
)
SSH_DIR
=
expanduser
(
'~cloud/.ssh'
)
SSH_DIR
=
expanduser
(
'~cloud/.ssh'
)
AUTHORIZED_KEYS
=
join
(
SSH_DIR
,
'authorized_keys'
)
AUTHORIZED_KEYS
=
join
(
SSH_DIR
,
'authorized_keys'
)
...
@@ -332,7 +332,11 @@ class SerialLineReceiver(SerialLineReceiverBase):
...
@@ -332,7 +332,11 @@ class SerialLineReceiver(SerialLineReceiverBase):
args
=
{})
args
=
{})
def
tick
(
self
):
def
tick
(
self
):
self
.
send_status
()
logger
.
debug
(
"Sending tick"
)
try
:
self
.
send_status
()
except
:
logger
.
exception
(
"Twisted hide exception"
)
def
__init__
(
self
):
def
__init__
(
self
):
super
(
SerialLineReceiver
,
self
)
.
__init__
()
super
(
SerialLineReceiver
,
self
)
.
__init__
()
...
@@ -415,20 +419,49 @@ class SerialLineReceiver(SerialLineReceiverBase):
...
@@ -415,20 +419,49 @@ class SerialLineReceiver(SerialLineReceiverBase):
pass
pass
def
get_virtio_device
():
path
=
None
GUID
=
'{6FDE7521-1B65-48ae-B628-80BE62016026}'
from
infi.devicemanager
import
DeviceManager
dm
=
DeviceManager
()
dm
.
root
.
rescan
()
# Search Virtio-Serial by name TODO: search by class_guid
for
i
in
dm
.
all_devices
:
if
i
.
has_property
(
"description"
):
if
"virtio-serial"
.
upper
()
in
i
.
description
.
upper
():
path
=
(
"
\\\\
?
\\
"
+
i
.
children
[
0
]
.
instance_id
.
lower
()
.
replace
(
'
\\
'
,
'#'
)
+
"#"
+
GUID
.
lower
()
)
return
path
def
main
():
def
main
():
if
system
==
'Windows'
:
if
system
==
'Windows'
:
import
pythoncom
port
=
get_virtio_device
()
pythoncom
.
CoInitialize
()
if
port
:
port
=
r'\\.\COM1'
from
w32serial
import
SerialPort
else
:
from
twisted.internet.serial
import
SerialPort
import
pythoncom
pythoncom
.
CoInitialize
()
port
=
r'\\.\COM1'
else
:
else
:
port
=
'/dev/ttyS0'
from
twisted.internet.serial
import
SerialPort
SerialPort
(
SerialLineReceiver
(),
port
,
reactor
,
baudrate
=
115200
)
# Try virtio first
port
=
"/dev/virtio-ports/agent"
if
not
exists
(
port
):
port
=
'/dev/ttyS0'
logger
.
info
(
"Opening port
%
s"
,
port
)
SerialPort
(
SerialLineReceiver
(),
port
,
reactor
)
try
:
try
:
from
notify
import
register_publisher
from
notify
import
register_publisher
register_publisher
(
reactor
)
register_publisher
(
reactor
)
except
:
except
:
logger
.
exception
(
"Couldnt register notify publisher"
)
logger
.
exception
(
"Couldnt register notify publisher"
)
logger
.
debug
(
"Starting reactor."
)
reactor
.
run
()
reactor
.
run
()
logger
.
debug
(
"Reactor after run."
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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