forked from sharm294/FPGA-Startup
-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_containers.py
33 lines (26 loc) · 1.02 KB
/
list_containers.py
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
################################################################################
# This script takes two arguments: a FPGA serial number and a file name. It
# writes the names of all containers that contain that serial number under the
# user.fpga-serial key to the file.
#
# This script is called by program_fpga.sh
################################################################################
from pylxd import Client as lxdClient
import sys
def list_containers(serial, fileName):
lxd = lxdClient()
containers = lxd.containers.all()
f = open(fileName, "w")
for container in containers:
try:
fpgaSerialKey = container.config["user.fpga-serial"]
except KeyError:
continue #no FPGAs in this container
for fpgaSerial in fpgaSerialKey.split(' '):
if serial == fpgaSerial: #this container has this FPGA
f.write(container.name)
f.close()
if __name__ == "__main__":
if len(sys.argv) != 3:
sys.exit("Usage: python list_containers.py FPGA_SERIAL FILENAME")
list_containers(sys.argv[1], sys.argv[2])