コード例 #1
0
ファイル: run_nms_cmd.py プロジェクト: amsaha/don
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
ファイル: ping.py プロジェクト: basivireddy/don
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
コード例 #4
0
ファイル: collector.py プロジェクト: amsaha/don
def exec_on_remote(cmd):
    node_details = get_vm_credentials()
    creds = node_details.get('network')
    # print "sudo "+cmd
    ssh = connect_to_box(creds['hostname'],creds['username'],creds['password'])
    (stdin,out,err) = ssh.exec_command(cmd)
    if len(err.read()):
        return []
    return out.read().splitlines()    
コード例 #5
0
ファイル: collector.py プロジェクト: amsaha/don
def exec_on_remote(cmd):
    node_details = get_vm_credentials()
    creds = node_details.get('network')
    # print "sudo "+cmd
    ssh = connect_to_box(creds['hostname'], creds['username'],
                         creds['password'])
    (stdin, out, err) = ssh.exec_command(cmd)
    if len(err.read()):
        return []
    return out.read().splitlines()
コード例 #6
0
ファイル: collector.py プロジェクト: amsaha/don
def get_vm_info_from_compute(cmd):
    output = execute_cmd(['nova', 'hypervisor-list'], sudo=False, shell=False, env=myenv).split('\n');
    compute_list = get_hypervisor(output)
    vm_info = []
    compute_creds = get_vm_credentials()
    for node in compute_list:
        creds = compute_creds.get('hypervisor').get(node,compute_creds.get('hypervisor')['default'])
        ssh = connect_to_box(node,creds['username'],creds['password'])
        (stdin,out,err) = ssh.exec_command('sudo ' + cmd)
        vm_info.extend(out.read().splitlines())
        ssh.close()
    return vm_info
コード例 #7
0
def get_vm_info_from_compute(cmd):
    output = execute_cmd(['nova', 'hypervisor-list'],
                         sudo=False, shell=False, env=myenv).split('\n')
    compute_list = get_hypervisor(output)
    vm_info = []
    compute_creds = get_vm_credentials()
    for node in compute_list:
        creds = compute_creds.get('hypervisor').get(
            node, compute_creds.get('hypervisor')['default'])
        ssh = connect_to_box(node, creds['username'], creds['password'])
        (stdin, out, err) = ssh.exec_command('sudo ' + cmd)
        vm_info.extend(out.read().splitlines())
        ssh.close()
    return vm_info