-
Notifications
You must be signed in to change notification settings - Fork 7
/
storcli64
executable file
·47 lines (38 loc) · 1.25 KB
/
storcli64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
#
# storcli64 :: connector to emulate 'storcli64' storage tool
# by passing args to simengine and receiving
# stdio/stderr from simengine.
#
# The connection to simengine is performed over
# a qemu virtserial port connected to a TCP socket
# on simengine. Communication is JSON-encoded over
# the raw socket.
#
# Chris Tyler <chris.tyler@senecacollege.ca> 2018-12-06
from __future__ import print_function
import json
import time
import sys
import os
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def send_cmd(conn):
conn.write(str(json.dumps({"argv": sys.argv})).encode())
return simengine.readline()
# open a connection
simengine = open("/dev/virtio-ports/systems.cdot.simengine.storage.net", "r+b", 0)
# wait for the daemon running on the host to respond:
response_msg = send_cmd(simengine)
while not response_msg:
response_msg = send_cmd(simengine)
time.sleep(1)
received = json.loads(response_msg)
# print out storcli64 output
if len(received["stdout"]) > 0:
print(received["stdout"])
if len(received["stderr"]) > 0:
eprint(received["stderr"])
# End: tidy and wrap
simengine.close()
sys.exit(received["status"])