mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #46756 from nages13/bugfix-grain-virtual_subtype
fix grains['virtual_subtype'] to show Docker on xen kernels
This commit is contained in:
commit
91c078ce12
1 changed files with 14 additions and 13 deletions
|
@ -714,19 +714,6 @@ def _virtual(osdata):
|
|||
grains['virtual_subtype'] = 'chroot'
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
if os.path.isfile('/proc/1/cgroup'):
|
||||
try:
|
||||
with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr:
|
||||
fhr_contents = fhr.read()
|
||||
if ':/lxc/' in fhr_contents:
|
||||
grains['virtual_subtype'] = 'LXC'
|
||||
else:
|
||||
if any(x in fhr_contents
|
||||
for x in (':/system.slice/docker', ':/docker/',
|
||||
':/docker-ce/')):
|
||||
grains['virtual_subtype'] = 'Docker'
|
||||
except IOError:
|
||||
pass
|
||||
if isdir('/proc/vz'):
|
||||
if os.path.isfile('/proc/vz/version'):
|
||||
grains['virtual'] = 'openvzhn'
|
||||
|
@ -776,6 +763,20 @@ def _virtual(osdata):
|
|||
# If a Dom0 or DomU was detected, obviously this is xen
|
||||
if 'dom' in grains.get('virtual_subtype', '').lower():
|
||||
grains['virtual'] = 'xen'
|
||||
# Check container type after hypervisors, to avoid variable overwrite on containers running in virtual environment.
|
||||
if os.path.isfile('/proc/1/cgroup'):
|
||||
try:
|
||||
with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr:
|
||||
fhr_contents = fhr.read()
|
||||
if ':/lxc/' in fhr_contents:
|
||||
grains['virtual_subtype'] = 'LXC'
|
||||
else:
|
||||
if any(x in fhr_contents
|
||||
for x in (':/system.slice/docker', ':/docker/',
|
||||
':/docker-ce/')):
|
||||
grains['virtual_subtype'] = 'Docker'
|
||||
except IOError:
|
||||
pass
|
||||
if os.path.isfile('/proc/cpuinfo'):
|
||||
with salt.utils.fopen('/proc/cpuinfo', 'r') as fhr:
|
||||
if 'QEMU Virtual CPU' in fhr.read():
|
||||
|
|
Loading…
Add table
Reference in a new issue