Пример #1
0
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
Пример #2
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 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
Пример #4
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))
Пример #5
0
def to_command(module, commands):
    if is_local_nxapi(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,
    )

    commands = transform(to_list(commands))

    for item in commands:
        if is_json(item["command"]):
            item["output"] = "json"

    return commands
Пример #6
0
 def _transform_to_complex_commands(self, commands):
     spec = dict(
         command=dict(key=True),
         output=dict(default='text', choices=['text', 'one-line']),
     )
     transform = ComplexList(spec, self.module)
     result = transform(commands)
     return result
Пример #7
0
def to_commands(module, commands):
    spec = {
        'command': dict(key=True),
        'prompt': dict(),
        'answer': dict()
    }
    transform = ComplexList(spec, module)
    return transform(commands)
Пример #8
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))
Пример #9
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
Пример #10
0
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
Пример #11
0
def parse_commands(module, warnings):
    command = ComplexList(
        dict(command=dict(key=True), prompt=dict(), answer=dict()), module)
    commands = command(module.params['commands'])
    items = []

    for item in 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'])
        else:
            items.append(item)
    return items
Пример #12
0
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
Пример #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 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
Пример #14
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
Пример #15
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
Пример #16
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
Пример #17
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
Пример #18
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
Пример #19
0
def transform_commands(module):
    transform = ComplexList(
        dict(
            command=dict(key=True),
            output=dict(),
            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),
            version=dict(
                type="str", default="latest", choices=["latest", "1"]
            ),
        ),
        module,
    )

    return transform(module.params["commands"])
Пример #20
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
Пример #21
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),
            version=dict(type="str", default="latest"),
        ),
        module,
    )

    return transform(to_list(commands))
Пример #22
0
def to_command(module, commands):
    if is_local_nxapi(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)

    commands = transform(to_list(commands))

    for item in commands:
        if is_json(item['command']):
            item['output'] = 'json'

    return commands