initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read status or pause/resume/power down this dedicated local VM."""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('command', choices=['query-status', 'stop', 'cont', 'system_powerdown'])
|
||||
args = parser.parse_args()
|
||||
root = Path(os.environ.get('DOCVIEW_VM_WORK', 'build-ubuntu-vm')).resolve()
|
||||
with socket.socket(socket.AF_UNIX) as stream:
|
||||
stream.settimeout(5)
|
||||
stream.connect(str(root / 'qmp.sock'))
|
||||
reader = stream.makefile('rb')
|
||||
json.loads(reader.readline())
|
||||
for operation in ['qmp_capabilities', args.command]:
|
||||
stream.sendall(json.dumps({'execute': operation}).encode() + b'\n')
|
||||
while True:
|
||||
response = json.loads(reader.readline())
|
||||
if 'return' in response or 'error' in response:
|
||||
break
|
||||
if operation == args.command:
|
||||
print(json.dumps(response))
|
||||
if 'error' in response:
|
||||
raise SystemExit(1)
|
||||
Reference in New Issue
Block a user