Last change
on this file since c159c76 was
30fdcce,
checked in by Jose M. Guisado <jguisado@…>, 3 years ago
|
src: improve logging
Adds new logging handler redirecting messages to the log file
located in the Samba shared directory (applies to live mode
clients, i.e: ogLive)
Parses log level configuration from ogclient.json. See:
{
"opengnsys": {
...
"log": "INFO",
...
}
...
}
Adds --debug option to set root logger level to DEBUG when starting
ogClient. Overrides log level from config file.
In addition:
- Replaces any occurence of print with a corresponding logging function.
- Unsets log level for handlers, use root logger level instead.
- Default level for root logger is INFO.
- Replaces level from response log messages to debug (ogRest)
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | # |
---|
2 | # Copyright (C) 2021 Soleta Networks <info@soleta.eu> |
---|
3 | # |
---|
4 | # This program is free software: you can redistribute it and/or modify it under |
---|
5 | # the terms of the GNU Affero General Public License as published by the |
---|
6 | # Free Software Foundation; either version 3 of the License, or |
---|
7 | # (at your option) any later version. |
---|
8 | |
---|
9 | import logging |
---|
10 | |
---|
11 | from src.virtual.qmp import QEMUMonitorProtocol |
---|
12 | from src.virtual.qmp import QMPCapabilitiesError, QMPConnectError |
---|
13 | |
---|
14 | QMP_DEFAULT_PORT = 4445 |
---|
15 | QMP_DEFAULT_HOST = "127.0.0.1" |
---|
16 | |
---|
17 | def is_shutdown_event(qmp_ev): |
---|
18 | """ |
---|
19 | """ |
---|
20 | return qmp_ev.get('event') == 'SHUTDOWN' |
---|
21 | |
---|
22 | |
---|
23 | def init(host=QMP_DEFAULT_HOST, port=QMP_DEFAULT_PORT): |
---|
24 | """ |
---|
25 | """ |
---|
26 | qmpconn = QEMUMonitorProtocol((host, port)) |
---|
27 | try: |
---|
28 | qmpconn.connect() |
---|
29 | except ConnectionRefusedError: |
---|
30 | logging.critical('poweroffd: Connection refused') |
---|
31 | return None |
---|
32 | except QMPCapabilitiesError as e: |
---|
33 | logging.critical('poweroffd: Error negotiating capabilities') |
---|
34 | return None |
---|
35 | return qmpconn |
---|
36 | |
---|
37 | |
---|
38 | def run(qmpconn): |
---|
39 | """ |
---|
40 | """ |
---|
41 | while(True): |
---|
42 | try: |
---|
43 | qmp_ev = qmpconn.pull_event(wait=True) |
---|
44 | except QMPConnectError as e: |
---|
45 | logging.critical('Error trying to pull an event') |
---|
46 | ret = -1 |
---|
47 | break |
---|
48 | if is_shutdown_event(qmp_ev): |
---|
49 | logging.info('Detected guest shutdown, powering off') |
---|
50 | ret = 0 |
---|
51 | break |
---|
52 | |
---|
53 | qmpconn.close() |
---|
54 | return ret |
---|
Note: See
TracBrowser
for help on using the repository browser.