Commit 5e32d6a6 by Guba Sándor

add search for vrtio device fallback to serial when missing

parent 97f9e18b
...@@ -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__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment