summaryrefslogtreecommitdiff
path: root/lib/ansible/module_utils/ordnance.py
blob: d87176c51cd0abe6c9ede56c8c495771020224bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
_DEVICE_CONFIGS = {}

def get_config(module, flags=[]):
    cmd = 'show running-config '
    cmd += ' '.join(flags)
    cmd = cmd.strip()

    try:
        return _DEVICE_CONFIGS[cmd]
    except KeyError:
        rc, out, err = module.exec_command(cmd)
        if rc != 0:
            module.fail_json(msg='unable to retrieve current config', stderr=err)
        cfg = str(out).strip()
        _DEVICE_CONFIGS[cmd] = cfg
        return cfg