Example #1
0
def map_params_to_obj(module):
    obj = {
        'hostname': module.params['hostname'],
        'domain_lookup': module.params['domain_lookup'],
        'system_mtu': module.params['system_mtu']
    }

    domain_name = ComplexList(dict(
        name=dict(key=True),
        vrf=dict()
    ), module)

    domain_search = ComplexList(dict(
        name=dict(key=True),
        vrf=dict()
    ), module)

    name_servers = ComplexList(dict(
        server=dict(key=True),
        vrf=dict()
    ), module)

    for arg, cast in [('domain_name', domain_name), ('domain_search', domain_search),
                      ('name_servers', name_servers)]:
        if module.params[arg] is not None:
            obj[arg] = cast(module.params[arg])
        else:
            obj[arg] = None

    return obj
def to_commands(module, commands):
    spec = {
        'command': dict(key=True),
        'prompt': dict(),
        'answer': dict()
    }
    transform = ComplexList(spec, module)
    return transform(commands)
Example #3
0
def to_request(module, requests):
    transform = ComplexList(
        dict(
            path=dict(key=True),
            method=dict(),
            data=dict(type='dict'),
        ), module)
    return transform(to_list(requests))
Example #4
0
def to_command(module, commands):
    default_output = 'text'
    transform = ComplexList(
        dict(command=dict(key=True),
             output=dict(default=default_output),
             prompt=dict(),
             answer=dict()), module)

    commands = transform(to_list(commands))

    return commands
Example #5
0
def to_command(module, commands):
    transform = ComplexList(
        dict(
            command=dict(key=True),
            output=dict(default='text'),
            prompt=dict(type='list'),
            answer=dict(type='list'),
            sendonly=dict(type='bool', default=False),
            check_all=dict(type='bool', default=False),
        ), module)
    return transform(to_list(commands))
def map_params_to_obj(module):
    obj = {
        'hostname': module.params['hostname'],
        'domain_name': module.params['domain_name'],
        'domain_list': module.params['domain_list']
    }

    lookup_source = ComplexList(dict(interface=dict(key=True), vrf=dict()),
                                module)

    name_servers = ComplexList(
        dict(server=dict(key=True), vrf=dict(default='default')), module)

    for arg, cast in [('lookup_source', lookup_source),
                      ('name_servers', name_servers)]:
        if module.params[arg] is not None:
            obj[arg] = cast(module.params[arg])
        else:
            obj[arg] = None

    return obj
def parse_commands(module, warnings):
    command = ComplexList(
        dict(command=dict(key=True), prompt=dict(), answer=dict()), module)
    commands = command(module.params['commands'])
    for index, item in enumerate(commands):
        if module.check_mode and not item['command'].startswith('show'):
            warnings.append(
                'only show commands are supported when using check mode, not '
                'executing `%s`' % item['command'])
        elif item['command'].startswith('conf'):
            module.fail_json(
                msg='aruba_command does not support running config mode '
                'commands.  Please use aruba_config instead')
    return commands
def parse_commands(module, warnings):
    command = ComplexList(
        dict(command=dict(key=True), prompt=dict(), answer=dict()), module)
    commands = command(module.params['commands'])
    for index, item in enumerate(commands):
        if module.check_mode and not item['command'].startswith('show'):
            warnings.append(
                'only show commands are supported when using check mode, not '
                'executing `%s`' % item['command'])
        elif item['command'].startswith('conf'):
            warnings.append(
                'commands run in config mode with aireos_command are not '
                'idempotent.  Please use aireos_config instead')
    return commands
Example #9
0
def map_params_to_obj(module):
    obj = {
        'hostname': module.params['hostname'],
        'lookup_source': module.params['lookup_source'],
        'lookup_enabled': module.params['lookup_enabled'],
    }

    domain_name = ComplexList(dict(name=dict(key=True), vrf=dict()), module)

    domain_search = ComplexList(dict(name=dict(key=True), vrf=dict()), module)

    name_servers = ComplexList(dict(server=dict(key=True), vrf=dict()), module)

    for arg, cast in [('domain_name', domain_name),
                      ('domain_search', domain_search),
                      ('name_servers', name_servers)]:

        if module.params[arg]:
            obj[arg] = cast(module.params[arg])
        else:
            obj[arg] = None

    return obj
Example #10
0
def parse_commands(module, warnings):
    transform = ComplexList(
        dict(command=dict(key=True),
             output=dict(),
             prompt=dict(),
             answer=dict()), module)

    commands = transform(module.params['commands'])

    for _, item in enumerate(commands):
        if module.check_mode and not item['command'].startswith('dis'):
            warnings.append(
                'Only display commands are supported when using check_mode, not '
                'executing %s' % item['command'])

    return commands
Example #11
0
def parse_commands(module, warnings):
    command = ComplexList(
        dict(command=dict(key=True),
             prompt=dict(),
             answer=dict(),
             check_all=dict(type='bool', default='False'),
             newline=dict(type='bool', default='True')), module)
    commands = command(module.params['commands'])
    for item in list(commands):
        if module.check_mode:
            if not item['command'].startswith('show'):
                warnings.append(
                    'Only show commands are supported when using check mode, not executing configure terminal'
                )
                commands.remove(item)
    return commands
Example #12
0
def to_command(module, commands):
    if is_local_eapi(module):
        default_output = 'json'
    else:
        default_output = 'text'

    transform = ComplexList(dict(
        command=dict(key=True),
        output=dict(default=default_output),
        prompt=dict(type='list'),
        answer=dict(type='list'),
        newline=dict(type='bool', default=True),
        sendonly=dict(type='bool', default=False),
        check_all=dict(type='bool', default=False),
    ), module)

    return transform(to_list(commands))
Example #13
0
def parse_commands(module, warnings):
    command = ComplexList(
        dict(command=dict(key=True), prompt=dict(), answer=dict()), module)
    commands = command(module.params['commands'])
    for item in list(commands):
        configure_type = re.match(r'conf(?:\w*)(?:\s+(\w+))?', item['command'])
        if module.check_mode:
            if configure_type and configure_type.group(1) not in (
                    'confirm', 'replace', 'revert', 'network'):
                module.fail_json(
                    msg='voss_command does not support running config mode '
                    'commands. Please use voss_config instead')
            if not item['command'].startswith('show'):
                warnings.append(
                    'only show commands are supported when using check mode, not '
                    'executing `%s`' % item['command'])
                commands.remove(item)
    return commands
Example #14
0
def parse_commands(module, warnings):
    command = ComplexList(dict(
        command=dict(key=True),
        prompt=dict(),
        answer=dict()
    ), module)
    commands = command(module.params['commands'])
    for item in list(commands):
        command_split = re.match(r'^(\w*)(.*)$', item['command'])
        if module.check_mode and not item['command'].startswith('show'):
            warnings.append(
                'only show commands are supported when using check mode, not '
                'executing `%s`' % item['command']
            )
            commands.remove(item)
        elif command_split and command_split.group(1) not in ('check', 'clear', 'debug', 'history',
                                                              'ls', 'mrinfo', 'mtrace', 'nslookup',
                                                              'ping', 'rtlookup', 'show', 'traceroute'):
            module.fail_json(
                msg='some commands were not recognized. exos_command can only run read-only'
                    'commands. For configuration commands, please use exos_config instead'
            )
    return commands