Пример #1
0
def run_nms_cmd (args):
    global output_dict
    host_ip     = args['host_ip']
    username    = args['username']
    passwd      = args['passwd']
    cmd_to_run  = args['cmd']

    result = True
    cmd_dict = {}
    try:
        ssh = connect_to_box(host_ip, username, passwd)
        cmd_dict['cmd'] = 'ssh %s with provided username and passwd' % host_ip
        if not ssh:
            cmd_dict['output'] = 'Could not ssh to ' + host_ip
            cmd_dict['pass'] = False
            output_dict['command_list'].append(cmd_dict)
            return False
        else:
            cmd_dict['pass'] = True
        output_dict['command_list'].append(cmd_dict)
        cmd_dict = {}
        cmd = cmd_to_run
        output = ssh_cmd(ssh, cmd).split('\n')
        cmd_dict['cmd'] = cmd
        cmd_dict['output'] = output
    except (KeyboardInterrupt, SystemExit):
        print '\nkeyboardinterrupt caught (again)'
        print '\n...Program Stopped Manually!'
        result = False
        raise
    cmd_dict['pass'] = result
    output_dict['command_list'].append(cmd_dict)
    return result
Пример #2
0
def run_nms_cmd(args):
    global output_dict
    host_ip = args['host_ip']
    username = args['username']
    passwd = args['passwd']
    cmd_to_run = args['cmd']

    result = True
    cmd_dict = {}
    try:
        ssh = connect_to_box(host_ip, username, passwd)
        cmd_dict['cmd'] = 'ssh %s with provided username and passwd' % host_ip
        if not ssh:
            cmd_dict['output'] = 'Could not ssh to ' + host_ip
            cmd_dict['pass'] = False
            output_dict['command_list'].append(cmd_dict)
            return False
        else:
            cmd_dict['pass'] = True
        output_dict['command_list'].append(cmd_dict)
        cmd_dict = {}
        cmd = cmd_to_run
        output = ssh_cmd(ssh, cmd).split('\n')
        cmd_dict['cmd'] = cmd
        cmd_dict['output'] = output
    except (KeyboardInterrupt, SystemExit):
        print '\nkeyboardinterrupt caught (again)'
        print '\n...Program Stopped Manually!'
        result = False
        raise
    cmd_dict['pass'] = result
    output_dict['command_list'].append(cmd_dict)
    return result
Пример #3
0
def ping_test (src_ip, dst_ip, username, passwd, count, timeout):
    global output_dict
    result = False
    cmd_dict = {}
    try:
        ssh = connect_to_box(src_ip, username, passwd)
        cmd_dict['cmd'] = 'ssh %s with provided username and passwd' % src_ip
        if not ssh:
            cmd_dict['output'] = 'Could not ssh to ' + src_ip
            cmd_dict['pass'] = False
            output_dict['command_list'].append(cmd_dict)
            return False
        else:
            cmd_dict['pass'] = True
        output_dict['command_list'].append(cmd_dict)
        cmd_dict = {}
        cmd = 'ping -c %s -W %s %s' % (count, timeout, dst_ip)
        output = ssh_cmd(ssh, cmd).split('\n')
        cmd_dict['cmd'] = cmd
        cmd_dict['output'] = output
        for line in output:
            m = re.search('(\d+) packets transmitted, (\d+) packets received', line)
            if m:
                tx_pkts = float(m.group(1))
                rx_pkts = float(m.group(2))
                if rx_pkts/tx_pkts >= 0.75:
                    result = True
                break
    except (KeyboardInterrupt, SystemExit):
        print '\nkeyboardinterrupt caught (again)'
        print '\n...Program Stopped Manually!'
        raise
    cmd_dict['pass'] = result
    output_dict['command_list'].append(cmd_dict)
    return result