Ejemplo n.º 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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 6
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']
            ) and self.client.module.params['transport'] != 'cli':
                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])
            # This needs to be removed so that the ComplexList used in to_commands
            # will work correctly.
            output = item.pop('output', None)

            if output == 'one-line' and 'one-line' not in item['command']:
                item['command'] += ' one-line'
            elif output == 'text' and 'one-line' in item['command']:
                item['command'] = item['command'].replace('one-line', '')

            results.append(item)
        return results
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def to_commands(module, commands):
    spec = {
        'command': dict(key=True),
        'prompt': dict(),
        'answer': dict()
    }
    transform = ComplexList(spec, module)
    return transform(commands)
Ejemplo n.º 9
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))
Ejemplo n.º 10
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
Ejemplo n.º 11
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
Ejemplo n.º 12
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))
Ejemplo n.º 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='ios_command does not support running config mode '
                    'commands.  Please use ios_config instead')
    return commands
Ejemplo n.º 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 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
def transform_commands(module):
    '''
    Transform the command to a complex list
    '''
    transform = ComplexList(dict(
        command=dict(key=True),
        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(module.params['commands'])
Ejemplo n.º 16
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
Ejemplo n.º 17
0
def to_command(module, commands):
    '''
    Convert command to ComplexList
    '''
    transform = ComplexList(dict(
        command=dict(key=True),
        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))
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 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):
        if item['command'].startswith('conf'):
            module.fail_json(msg='does not support config commands')
        if module.check_mode:
            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 list(commands)
Ejemplo n.º 20
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
Ejemplo n.º 21
0
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
Ejemplo n.º 22
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 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 configure_type and configure_type.group(1) not in (
                'confirm', 'replace', 'revert', 'network'):
            module.fail_json(
                msg='ios_command does not support running config mode '
                'commands.  Please use ios_config instead')
    return commands
Ejemplo n.º 23
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(module.jsonify(item))

    return items
def parse_commands(module, warnings):
  """parse commands
  see Entity class document of module_utils/network/common/utils.py
  """
  transform = ComplexList(dict(command=dict(key=True), prompt=dict(), answer=dict()), module)

  # commands as dict
  commands = transform(module.params['commands'])

  # check_mode restrict command except 'show'
  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
Ejemplo n.º 25
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))
Ejemplo n.º 26
0
def parse_commands(module, warnings):
    spec = dict(command=dict(key=True),
                output=dict(),
                prompt=dict(),
                answer=dict())

    transform = ComplexList(spec, 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
Ejemplo n.º 27
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
Ejemplo n.º 28
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.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
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
Ejemplo n.º 30
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'),
        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