1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

Merge pull request #349 from davemq/mount_aix

Add AIX mount support
This commit is contained in:
Kelly Brazil
2023-01-05 11:39:42 -08:00
committed by GitHub
4 changed files with 71 additions and 3 deletions

View File

@ -79,7 +79,7 @@ class info():
description = '`mount` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux', 'darwin', 'freebsd']
compatible = ['linux', 'darwin', 'freebsd', 'aix']
magic_commands = ['mount']
tags = ['command']
@ -147,6 +147,41 @@ def _linux_parse(data):
return output
def _aix_parse(data):
output = []
# AIX mount command starts with these headers:
# node mounted mounted over vfs date options
# -------- --------------- --------------- ------ ------------ ---------------
# Remove them
data.pop(0)
data.pop(0)
for entry in data:
output_line = {}
parsed_line = entry.split()
# AIX mount entries have the remote node as the zeroth element. If the
# mount is local, the zeroth element is the filesystem instead. We can
# detect this by the lenth of the list. For local mounts, length is 7,
# and for remote mounts, the length is 8. In the remote case, pop off
# the zeroth element. Then parsed_line has a consistent format.
if len(parsed_line) == 8:
parsed_line.pop(0)
output_line['filesystem'] = parsed_line[0]
output_line['mount_point'] = parsed_line[1]
output_line['type'] = parsed_line[2]
# options = {}
options = parsed_line[6].lstrip('(').rstrip(')').split(',')
output_line['options'] = options
output.append(output_line)
return output
def parse(data, raw=False, quiet=False):
"""
@ -171,9 +206,12 @@ def parse(data, raw=False, quiet=False):
if jc.utils.has_data(data):
# check for OSX output
# check for OSX and AIX output
if ' type ' not in cleandata[0]:
raw_output = _osx_parse(cleandata)
if 'node' in cleandata[0]:
raw_output = _aix_parse(cleandata)
else:
raw_output = _osx_parse(cleandata)
else:
raw_output = _linux_parse(cleandata)

1
tests/fixtures/aix-7.1/mount.json vendored Normal file
View File

@ -0,0 +1 @@
[{"filesystem":"/dev/hd4","mount_point":"/","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/hd2","mount_point":"/usr","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/hd9var","mount_point":"/var","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/hd3","mount_point":"/tmp","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/hd1","mount_point":"/home","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/hd11admin","mount_point":"/admin","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/proc","mount_point":"/proc","type":"procfs","options":["rw"]},{"filesystem":"/dev/hd10opt","mount_point":"/opt","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/livedump","mount_point":"/var/adm/ras/livedump","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/lvvarlog","mount_point":"/var/log","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/lvafslogs","mount_point":"/usr/afs/logs","type":"jfs2","options":["rw","log=/dev/hd8"]},{"filesystem":"/dev/fslv00","mount_point":"/sandbox","type":"jfs2","options":["rw","log=/dev/sboxlv_log"]},{"filesystem":"/dev/ramdisk0","mount_point":"/usr/vice/cache","type":"jfs","options":["rw","nointegrity"]},{"filesystem":"AFS","mount_point":"/afs","type":"afs","options":["rw"]},{"filesystem":"/local","mount_point":"/remote","type":"nfs3","options":["hard","intr","vers=3","sec=sys","proto=tcp","grpid","rsize=65536","wsize=65536","biods=16","nosuid"]}]

17
tests/fixtures/aix-7.1/mount.out vendored Normal file
View File

@ -0,0 +1,17 @@
node mounted mounted over vfs date options
-------- --------------- --------------- ------ ------------ ---------------
/dev/hd4 / jfs2 Sep 06 11:46 rw,log=/dev/hd8
/dev/hd2 /usr jfs2 Sep 06 11:46 rw,log=/dev/hd8
/dev/hd9var /var jfs2 Sep 06 11:46 rw,log=/dev/hd8
/dev/hd3 /tmp jfs2 Sep 06 11:46 rw,log=/dev/hd8
/dev/hd1 /home jfs2 Sep 06 11:47 rw,log=/dev/hd8
/dev/hd11admin /admin jfs2 Sep 06 11:47 rw,log=/dev/hd8
/proc /proc procfs Sep 06 11:47 rw
/dev/hd10opt /opt jfs2 Sep 06 11:47 rw,log=/dev/hd8
/dev/livedump /var/adm/ras/livedump jfs2 Sep 06 11:47 rw,log=/dev/hd8
/dev/lvvarlog /var/log jfs2 Sep 06 11:47 rw,log=/dev/hd8
/dev/lvafslogs /usr/afs/logs jfs2 Sep 06 11:47 rw,log=/dev/hd8
/dev/fslv00 /sandbox jfs2 Sep 06 11:47 rw,log=/dev/sboxlv_log
/dev/ramdisk0 /usr/vice/cache jfs Sep 06 11:47 rw,nointegrity
AFS /afs afs Sep 06 11:47 rw
remote /local /remote nfs3 Sep 06 11:49 hard,intr,vers=3,sec=sys,proto=tcp,grpid,rsize=65536,wsize=65536,biods=16,nosuid

View File

@ -21,6 +21,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/mount2.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_mount2 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/aix-7.1/mount.out'), 'r', encoding='utf-8') as f:
aix_7_1_mount = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mount.json'), 'r', encoding='utf-8') as f:
centos_7_7_mount_json = json.loads(f.read())
@ -34,6 +37,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/mount2.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_mount2_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/aix-7.1/mount.json'), 'r', encoding='utf-8') as f:
aix_7_1_mount_json = json.loads(f.read())
def test_mount_nodata(self):
"""
@ -65,6 +71,12 @@ class MyTests(unittest.TestCase):
"""
self.assertEqual(jc.parsers.mount.parse(self.osx_10_14_6_mount2, quiet=True), self.osx_10_14_6_mount2_json)
def test_mount_aix_7_1(self):
"""
Test 'mount' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.mount.parse(self.aix_7_1_mount, quiet=True), self.aix_7_1_mount_json)
if __name__ == '__main__':
unittest.main()