Skip to content

Commit

Permalink
Lint cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Mrunal Patel <[email protected]>
  • Loading branch information
mrunalp committed Jan 26, 2019
1 parent 1beeb42 commit f989b27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions container_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def get_container_layers(id):
container_status = subprocess.check_output(
["runc", "state", container_id])
except subprocess.CalledProcessError:
print "container not found; probably exited"
print("container not found; probably exited")
sys.exit(0)

status_json = json.loads(container_status)
if status_json['status'] == "stopped":
print "container already stopped"
print("container already stopped")
sys.exit(0)

rootfs_path = status_json['rootfs']
Expand All @@ -26,45 +26,45 @@ def get_container_layers(id):
container_pid = status_json['pid']

# Note: os.path.join failed for some reason on RHCOS
countainer_mounts_path = "/proc/" + str(container_pid) + "/mountinfo"
container_mounts_path = "/proc/" + str(container_pid) + "/mountinfo"
container_mount_output = ""
with open(countainer_mounts_path, "r") as f:
with open(container_mounts_path, "r") as f:
for line in f:
if re.search(top_layer_id, line):
container_mount_output = line
break

if container_mount_output == "":
print "container mount not found; probably exited"
print("container mount not found; probably exited")
sys.exit(0)

layers = []
m = re.search('lowerdir=(.*),upperdir', container_mount_output)
if m:
lowerdirs = m.group(1).split(':')
for l in lowerdirs:
lower_dirs = m.group(1).split(':')
for l in lower_dirs:
layers.append(l)
else:
print "Unable to find lowerdir in mount output: ", container_mount_output
print("Unable to find lowerdir in mount output: ", container_mount_output)
sys.exit(1)

m = re.search('upperdir=(.*),workdir', container_mount_output)
if m:
upperdir = m.group(1)
layers.append(upperdir)
upper_dir = m.group(1)
layers.append(upper_dir)
else:
print "Unable to find upperdir in mount output: ", container_mount_output
print("Unable to find upperdir in mount output: ", container_mount_output)
sys.exit(1)

return layers


if __name__ == "__main__":
if len(sys.argv) < 2:
print "Usage: sys.argv[0] <container_id>"
print("Usage: sys.argv[0] <container_id>")
sys.exit(1)

container_id = sys.argv[1]
layers = get_container_layers(container_id)
for l in layers:
print l
print(l)

0 comments on commit f989b27

Please sign in to comment.