File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1129,10 +1129,14 @@ def get_machine_id():
11291129 return None
11301130
11311131
1132- def is_running_in_container ():
1132+ def detect_virt ():
1133+ # Run systemd-detect-virt command
1134+ virt = run_command (["systemd-detect-virt" ])
1135+ if virt and virt != "none" :
1136+ return virt
1137+
11331138 # Check if the process in running in a container
11341139 import os .path
1135-
11361140 if os .path .exists ('/.dockerenv' ):
11371141 return 'docker'
11381142 if os .path .exists ('/run/.containerenv' ):
@@ -1142,11 +1146,6 @@ def is_running_in_container():
11421146 if container :
11431147 return container
11441148
1145- # Run systemd-detect-virt command
1146- container = run_command (["systemd-detect-virt" ])
1147- if container and container != "none" :
1148- return container
1149-
11501149 # Other ways to check if running in a container:
11511150 # * Parse /proc/1/mounts or /proc/1/mountinfo (check "/" filesystem).
11521151 # * Parse /proc/1/cgroup.
@@ -1183,9 +1182,9 @@ def collect_system(info_add):
11831182 uptime = f'{ uptime } sec'
11841183 info_add ('system.uptime' , uptime )
11851184
1186- container = is_running_in_container ()
1187- if container :
1188- info_add ('system.in_container ' , container )
1185+ virt = detect_virt ()
1186+ if virt :
1187+ info_add ('system.virt ' , virt )
11891188
11901189
11911190def collect_info (info ):
You can’t perform that action at this time.
0 commit comments