def to_request(module, requests): transform = ComplexList(dict( path=dict(key=True), method=dict(), data=dict(type='dict'), ), module) return transform(to_list(requests))
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 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
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
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 map_params_to_obj(module): obj = { 'hostname': module.params['hostname'], '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] 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='sros_command does not support running config mode ' 'commands. Please use sros_config instead') return commands
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
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
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))
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='nos_command does not support running config mode ' 'commands. Please use nos_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
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
def to_commands(module, commands): spec = {'command': dict(key=True), 'prompt': dict(), 'answer': dict()} transform = ComplexList(spec, module) return transform(commands)