Exemplo n.º 1
0
            if line.startswith("/bin/mount ") or line.startswith("mount "):
                continue

            words = line.split()
            devInfo = [words[0], words[2], words[4]]
            if rslt is None:
                rslt = [devInfo]
            else:
                rslt.append(devInfo)
        return rslt


if __name__ == '__main__':
    ''' Test this module here '''
    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "mount -l | grep docknode"
    cmdCtx.rspMsg = """mount -l | grep docknode
/dev/sdb on /kodiak/dock/myDock/docknode/1/mnt/0 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdc on /kodiak/dock/myDock/docknode/1/mnt/1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdd on /kodiak/dock/myDock/docknode/1/mnt/2 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sde on /kodiak/dock/myDock/docknode/1/mnt/3 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdg on /kodiak/dock/myDock/docknode/1/mnt/4 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdh on /kodiak/dock/myDock/docknode/1/mnt/5 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdi on /kodiak/dock/myDock/docknode/1/mnt/6 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)"""

    if MountHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = MountHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 2
0
            if rslt is None:
                rslt = []
            rslt.append((tokens[-1], tokens[0][1:-1]))
        return rslt


if __name__ == '__main__':
    ''' Test this module here '''
    from kd.ep.cmd_ctx import CmdCtx

    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "/bin/lsscsi"
    cmdCtx.rspMsg = """/bin/lsscsi ....
[0:0:0:0]    cd/dvd  QEMU     QEMU DVD-ROM     1.5.  /dev/sr0
[2:0:0:0]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sda
[2:0:0:1]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sdi
[2:0:0:2]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sdg
[2:0:0:3]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sde
[2:0:0:4]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sdc
[2:0:0:5]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sdh
[2:0:0:6]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sdf
[2:0:0:7]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sdd
[2:0:0:8]    disk    QEMU     QEMU HARDDISK    1.5.  /dev/sdb"""

    if LsscsiHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = LsscsiHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 3
0
    @staticmethod
    def parseRslt(cmdCtx):
        rslt = None

        for line in cmdCtx.rspMsg.splitlines():
            if line == "" or line.isspace():
                continue
            if line.startswith("/usr/sbin/lsmod ") or line.startswith(
                    "lsmod "):
                continue

            print line
            words = line.split()
            rslt = [words[0], int(words[2])]
        return rslt


if __name__ == '__main__':
    ''' Test this module here '''
    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "lsmod | grep --color=never kodiak"
    cmdCtx.rspMsg = """lsmod | grep --color=never kodiak
kodiak                118041  0
"""

    if LsmodHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = LsmodHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 4
0
        rslt = None

        for line in cmdCtx.rspMsg.splitlines():
            if line == "" or line.isspace():
                continue
            if line.startswith("/usr/sbin/pidof  ") or line.startswith("pidof "):
                continue

            for name in line.split():
                if name.strip() != '':
                    if rslt is None:
                        rslt = [ int(name) ]
                    else:
                        rslt.append(int(name))
        return rslt

if __name__ == '__main__':
    ''' Test this module here '''
    cmdCtx        = CmdCtx()
    cmdCtx.cmdMsg = "pidof kdtkcd"
    cmdCtx.rspMsg = """1234 5678"""

    if PidofHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = PidofHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"



Exemplo n.º 5
0
if __name__ == '__main__':
    from kd.ep.cmd_ctx import CmdCtx
    ''' Test this module here '''
    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "/usr/sbin/ifconfig -s"
    cmdCtx.rspMsg = """/usr/sbin/ifconfig -s ....
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0      1500   299706     75      0 0         15949      0      0      0 BMRU
eth1      1500        0      0      0 0             0      0      0      0 BMU
eth2      1500   132601      0      0 0          8273      0      0      0 BMRU
eth3      1500        0      0      0 0             0      0      0      0 BMU
lo       65536       10      0      0 0            10      0      0      0 LRU
virbr0    1500 29749044      0      0 0       7320954      0      0      0 BMRU
virbr1    1500       10      0      0 0             9      0      0      0 BMRU
virbr2    1500   124383      0      0 0            35      0      0      0 BMRU
virbr3    1500       10      0      0 0             9      0      0      0 BMRU
vnet0     1500    11423      0      0 0        264318      0      0      0 BMRU
vnet1     1500       10      0      0 0            16      0      0      0 BMRU
vnet2     1500       10      0      0 0        123947      0      0      0 BMRU
vnet3     1500       10      0      0 0            16      0      0      0 BMRU
vnet4     1500 29517285      0      0 0      58859685      0      0      0 BMRU
vnet5     1500        0      0      0 0            19      0      0      0 BMRU
vnet6     1500        0      0      0 0        123954      0      0      0 BMRU
vnet7     1500        0      0      0 0            19      0      0      0 BMRU"""

    if IfconfigHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = IfconfigHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 6
0
    def canParseRslt(cmdCtx):
        if cmdCtx.cmdMsg.startswith("print "):
            return True
        return False

    @staticmethod
    def parseRslt(cmdCtx):
        for line in cmdCtx.rspMsg.splitlines():
            if line == "" or line.isspace():
                continue
            if line.startswith("print "):
                continue
            words = line.split('=')
            rslt = words[1].strip()
        return rslt


if __name__ == '__main__':
    ''' Test this module here '''
    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "print aaa"
    cmdCtx.rspMsg = """$65997 = 65996
"""

    if GcmdHdlr.canParseRslt(cmdCtx):
        print "canParse"
        cmdCtx.rslt = GcmdHdlr.parseRslt(cmdCtx)
        print cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 7
0
            if line == "" or line.isspace():
                continue
            if line.startswith("/bin/ls ") or line.startswith("/bin/ls:"):
                continue

            if line.find("No such file or directory") >= 0:
                cmdCtx.setRC(RC.NOT_FOUND, line)
                break

            for name in line.split():
                if name.strip() != '':
                    if rslt is None:
                        rslt = [name]
                    else:
                        rslt.append(name)
        return rslt


if __name__ == '__main__':
    ''' Test this module here '''
    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "/bin/ls --color=none /dev"
    cmdCtx.rspMsg = """autofs cpu_dma_latency input mem pts sr0 tty14
tty24  tty34  tty44  tty54  tty7 usbmon1  vcsa"""

    if LsHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = LsHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 8
0
        rslt = None

        for line in cmdCtx.rspMsg.splitlines():
            if line == "" or line.isspace():
                continue
            if line.startswith("/bin/systemctl"):
                continue
            if line.startswith("systemctl"):
                continue

            rslt = True if line == 'active' else False
            break

        return rslt


if __name__ == '__main__':
    ''' Test this module here '''
    from kd.ep.cmd_ctx import CmdCtx

    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "systemctl is-active kodiak-data-engine"
    cmdCtx.rspMsg = cmdCtx.cmdMsg + """ ....
active"""

    if SystemctlIsactive.canParseRslt(cmdCtx):
        cmdCtx.rslt = SystemctlIsactive.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 9
0
    @staticmethod
    def parseRslt(cmdCtx):
        rslt = None

        for line in cmdCtx.rspMsg.splitlines():
            if line == "" or line.isspace():
                continue
            if line.startswith("/usr/sbin/pvdisplay"):
                continue
            if line.startswith("pvdisplay"):
                continue

            rslt = line.strip().split(':')
            break
        return rslt


if __name__ == '__main__':
    from kd.ep.cmd_ctx import CmdCtx
    ''' Test this module here '''
    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "/usr/sbin/pvdisplay -c"
    cmdCtx.rspMsg = """/usr/sbin/pvdisplay ....
  /dev/sda2:centos_kodiak-cube2-c71-br4:66082816:-1:8:8:-1:4096:8066:11:8055:82FBVl-xqTS-C9Ja-m5J7-xhaw-bgeL-9eQ6Q9"""

    if PvdisplayHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = PvdisplayHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"
Exemplo n.º 10
0
            if "Active:" not in line:
                continue

            tokens = line.split()
            if tokens[1] != 'disk':
                continue
            if rslt is None:
                rslt = []
            rslt.append( (tokens[-1], tokens[0][1:-1]) )
        return rslt

if __name__ == '__main__':
    ''' Test this module here '''
    from kd.ep.cmd_ctx  import CmdCtx

    cmdCtx        = CmdCtx()
    cmdCtx.cmdMsg = "systemctl status kodiak-data-engine"
    cmdCtx.rspMsg = """systemctl status kodiak-data-engine ....
   Loaded: loaded (/usr/lib/systemd/system/kodiak-data-engine.service; disabled; vendor preset: disabled)
      Active: inactive (dead) """

    if SystemctlStatus.canParseRslt(cmdCtx):
        cmdCtx.rslt = SystemctlStatus.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"



Exemplo n.º 11
0
                    cmdCtx.setRC(RC.ERROR, line)
                    break
                continue
            if line.endswith('records in') or line.endswith('records out'):
                continue
            if "bytes (" not in line:
                continue

            m = re.findall('([-+]?\d+[\.]?\d*)', line)
            rslt = [int(m[0]), float(m[2])]
            break

        return rslt


if __name__ == '__main__':
    ''' Test this module here '''
    cmdCtx = CmdCtx()
    cmdCtx.cmdMsg = "/bin/dd new.txt old.txt"
    cmdCtx.rspMsg = """/bin/dd if=/dev/zero of=/dev/kdblk0 bs=8192 seek=0 cou nt=1 oflag=direct,seek_bytes
/bin/dd: error writing /dev/kdblk0: Input/output error
1+0 records in
0+0 records out
0 bytes (0 B) copied, 29.5568 s, 0.0 kB/s"""

    if DdHdlr.canParseRslt(cmdCtx):
        cmdCtx.rslt = DdHdlr.parseRslt(cmdCtx)
        print "canParse:\n %s" % cmdCtx
    else:
        print "Failed to parse it!!!"