Beispiel #1
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
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
Beispiel #3
0
def parse_commands(module, warnings):
    spec = dict(command=dict(key=True),
                output=dict(default=module.params['display'],
                            choices=['text', 'json', 'xml']),
                prompt=dict(),
                answer=dict())

    transform = ComplexList(spec, module)
    commands = transform(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'])

        if item['output'] == 'json' and 'display json' not in item['command']:
            item['command'] += '| display json'
        elif item['output'] == 'xml' and 'display xml' not in item['command']:
            item['command'] += '| display xml'
        else:
            if '| display json' in item['command']:
                item['command'] = str(item['command']).replace(
                    ' | display json', '')
            elif '| display xml' in item['command']:
                item['command'] = str(item['command']).replace(
                    ' | display xml', '')
        commands[index] = item

    return commands
Beispiel #4
0
    def parse_commands(self, warnings):
        results = []
        commands = list(deque(set(self.want.commands)))
        spec = dict(
            command=dict(key=True),
            output=dict(default='text', choices=['text', 'one-line']),
        )

        transform = ComplexList(spec, self.client.module)
        commands = transform(commands)

        for index, item in enumerate(commands):
            if not self._is_valid_mode(item['command']):
                warnings.append(
                    'Using "write" commands is not idempotent. You should use '
                    'a module that is specifically made for that. If such a '
                    'module does not exist, then please file a bug. The command '
                    'in question is "%s..."' % item['command'][0:40])
            if item['output'] == 'one-line' and 'one-line' not in item[
                    'command']:
                item['command'] += ' one-line'
            elif item['output'] == 'text' and 'one-line' in item['command']:
                item['command'] = item['command'].replace('one-line', '')
            results.append(item)
        return results
Beispiel #5
0
def to_commands(module, commands):
    spec = {
        'command': dict(key=True),
        'prompt': dict(),
        'answer': dict()
    }
    transform = ComplexList(spec, module)
    return transform(commands)
Beispiel #6
0
def to_command(module, commands):
    default_output = 'text'
    transform = ComplexList(
        dict(command=dict(key=True),
             output=dict(default=default_output),
             prompt=dict(),
             response=dict()), module)

    commands = transform(to_list(commands))

    return commands
Beispiel #7
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()))

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

    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
Beispiel #8
0
def to_command(module, commands):
    if is_eapi(module):
        default_output = 'json'
    else:
        default_output = 'text'

    transform = ComplexList(
        dict(command=dict(key=True),
             output=dict(default=default_output),
             prompt=dict(),
             answer=dict()), module)

    return transform(to_list(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'):
            module.fail_json(
                msg='dellos6_command does not support running config mode '
                'commands.  Please use dellos6_config instead')
    return commands
Beispiel #10
0
def parse_commands(module, warnings):
    cast = ComplexList(
        dict(command=dict(key=True),
             output=dict(),
             prompt=dict(),
             response=dict()))

    commands = cast(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'])
    return commands
Beispiel #11
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, cmd in enumerate(commands):
        if module.check_mode and not cmd['command'].startswith('show'):
            warnings.append('only show commands are supported when using '
                            'check mode, not executing `%s`' % cmd['command'])
        commands[index] = module.jsonify(cmd)

    return commands
def parse_commands(module, warnings):
    transform = ComplexList(
        dict(command=dict(key=True),
             output=dict(),
             prompt=dict(),
             response=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
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(module.jsonify(item))

    return items
def parse_commands(module, warnings):
    transform = ComplexList(
        dict(command=dict(key=True),
             output=dict(),
             prompt=dict(),
             answer=dict()), module)

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

    if module.check_mode:
        for item in list(commands):
            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
Beispiel #15
0
    def parse_commands(self, warnings):
        results = []
        commands = list(deque(set(self.want.commands)))
        spec = dict(
            command=dict(key=True),
            output=dict(default='text', choices=['text', 'one-line']),
        )

        transform = ComplexList(spec, self.client.module)
        commands = transform(commands)

        for index, item in enumerate(commands):
            if item['output'] == 'one-line' and 'one-line' not in item[
                    'command']:
                item['command'] += ' one-line'
            elif item['output'] == 'text' and 'one-line' in item['command']:
                item['command'] = item['command'].replace('one-line', '')
            results.append(item)
        return results
Beispiel #16
0
def to_command(module, commands):
    if is_nxapi(module):
        default_output = 'json'
    else:
        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))

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

    return commands
Beispiel #17
0
def to_command(module, commands):
    if is_nxapi(module):
        default_output = 'json'
    else:
        default_output = 'text'

    transform = ComplexList(
        dict(command=dict(key=True),
             output=dict(default=default_output),
             prompt=dict(),
             response=dict()), module)

    commands = transform(to_list(commands))

    for index, item in enumerate(commands):
        if is_json(item['command']):
            item['output'] = 'json'
        elif is_text(item['command']):
            item['output'] = 'text'

    return commands
Beispiel #18
0
def parse_commands(module, warnings):
    command = ComplexList(
        dict(
            command=dict(key=True),
            prompt=dict(),
            response=dict(),
        ))
    commands = command(module.params['commands'])

    for index, cmd in enumerate(commands):
        if module.check_mode and not cmd['command'].startswith('show'):
            warnings.append('only show commands are supported when using '
                            'check mode, not executing `%s`' % cmd['command'])
        else:
            if cmd['command'].startswith('conf'):
                module.fail_json(msg='vyos_command does not support running '
                                 'config mode commands.  Please use '
                                 'vyos_config instead')
        commands[index] = module.jsonify(cmd)

    return commands
def parse_commands(module, warnings):
    command = ComplexList(dict(
        command=dict(key=True),
        prompt=dict(),
        answer=dict(),
    ), module)

    items = []
    for item in command(module.params['commands']):
        if not item['command'].startswith('/'):
            module.fail_json(msg='commands should always start with `/` to be '
                             'fully qualified; not executing `%s`' % item['command'])

        if module.check_mode and ' print' not in item['command']:
            warnings.append('only print commands are supported when using '
                            'check mode, not executing `%s`' % item['command'])
            continue

        items.append(item)

    return items
Beispiel #20
0
def to_commands(commands):
    transform = ComplexList(
        dict(command=dict(key=True), prompt=dict(), response=dict()))
    return transform(commands)