def execute_show_command(module, command, output='text'):
    cmds = [{
        'command': command,
        'output': output,
    }]

    return run_commands(module, cmds)
def execute_show_command(command, module, output='json'):
    cmds = [{
        'command': command,
        'output': output,
    }]
    body = run_commands(module, cmds)
    return body
示例#3
0
def execute_show_command(command, module, output='text'):
    command = {
        'command': command,
        'output': output,
    }

    return run_commands(module, [command])
def get_ping_results(command, module):
    cmd = {'command': command, 'output': 'text'}
    ping = run_commands(module, [cmd])[0]

    if not ping:
        module.fail_json(msg="An unexpected error occurred. Check all params.",
                         command=command,
                         destination=module.params['dest'],
                         vrf=module.params['vrf'],
                         source=module.params['source'])

    elif "can't bind to address" in ping:
        module.fail_json(msg="Can't bind to source address.", command=command)
    elif "bad context" in ping:
        module.fail_json(msg="Wrong VRF name inserted.",
                         command=command,
                         vrf=module.params['vrf'])
    else:
        splitted_ping = ping.split('\n')
        reference_point = get_statistics_summary_line(splitted_ping)
        summary, ping_pass = get_summary(splitted_ping, reference_point)
        rtt = get_rtt(splitted_ping, summary['packet_loss'],
                      reference_point + 2)

    return (summary, rtt, ping_pass)
示例#5
0
def match_facility_default(module, facility, want_level):
    ''' Check wanted facility to see if it matches current device default '''

    matches_default = False
    # Sample output from show logging level command
    # Facility        Default Severity        Current Session Severity
    # --------        ----------------        ------------------------
    # bfd                     5                       5
    #
    # 0(emergencies)          1(alerts)       2(critical)
    # 3(errors)               4(warnings)     5(notifications)
    # 6(information)          7(debugging)

    regexl = r'\S+\s+(\d+)\s+(\d+)'
    cmd = {
        'command': 'show logging level {0}'.format(facility),
        'output': 'text'
    }
    facility_data = run_commands(module, cmd)
    for line in facility_data[0].split('\n'):
        mo = re.search(regexl, line)
        if mo and int(mo.group(1)) == int(want_level) and int(
                mo.group(2)) == int(want_level):
            matches_default = True

    return matches_default
示例#6
0
def execute_show_command(module, command):
    format = 'text'
    cmds = [{
        'command': command,
        'output': format,
    }]
    output = run_commands(module, cmds)
    return output
示例#7
0
def execute_show_command(command, module, text=False):
    command = {
        'command': command,
        'output': 'json',
    }
    if text:
        command['output'] = 'text'

    return run_commands(module, command)
def execute_show_command(command, module):
    if 'show run' not in command:
        output = 'json'
    else:
        output = 'text'
    cmds = [{
        'command': command,
        'output': output,
    }]
    return run_commands(module, cmds)[0]
def get_active_vpc_peer_link(module):
    peer_link = None

    try:
        body = run_commands(module, ['show vpc brief | json'])[0]
        peer_link = body['TABLE_peerlink']['ROW_peerlink']['peerlink-ifindex']
    except (KeyError, AttributeError, TypeError):
        return peer_link

    return peer_link
 def run(self, command, output='text'):
     command_string = command
     command = {'command': command, 'output': output}
     resp = run_commands(self.module, [command], check_rc='retry_json')
     try:
         return resp[0]
     except IndexError:
         self.warnings.append(
             'command %s failed, facts for this command will not be populated'
             % command_string)
         return None
def get_hsrp_group_unknown_enum(module, command, hsrp_table):
    '''Some older NXOS images fail to set the attr values when using structured output and
    instead set the values to <unknown enum>. This fallback method is a workaround that
    uses an unstructured (text) request to query the device a second time.
    'sh_preempt' is currently the only attr affected. Add checks for other attrs as needed.
    '''
    if 'unknown enum:' in hsrp_table['sh_preempt']:
        cmd = {'output': 'text', 'command': command.split('|')[0]}
        out = run_commands(module, cmd)[0]
        hsrp_table['sh_preempt'] = 'enabled' if ('may preempt'
                                                 in out) else 'disabled'
    return hsrp_table