コード例 #1
1
ファイル: nxos_nxapi.py プロジェクト: likewg/DevOps
def load(module, commands, result):
    candidate = NetworkConfig(indent=2, contents='\n'.join(commands))
    config = get_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        commands = dumps(configobjs, 'commands').split('\n')
        result['updates'] = commands
        if not module.check_mode:
            load_config(module, commands, result)
        result['changed'] = True
コード例 #2
0
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(
        src=dict(required=True),
        force=dict(default=False, type='bool'),
        include_defaults=dict(default=False, type='bool'),
        backup=dict(default=False, type='bool'),
        replace=dict(default=False, type='bool'),
        config=dict()
    )

    argument_spec.update(eapi.eapi_argument_spec)

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    cls = get_ansible_module()

    module = cls(argument_spec=argument_spec,
                 mutually_exclusive=mutually_exclusive,
                 supports_check_mode=True)

    warnings = check_args(module)

    result = {'changed': False}
    if warnings:
        result['warnings'] = warnings

    src = module.params['src']
    candidate = NetworkConfig(contents=src, indent=3)

    if module.params['backup']:
        result['__backup__'] = get_config()

    if not module.params['force']:
        contents = get_current_config(module)
        configobj = NetworkConfig(contents=contents, indent=3)
        commands = candidate.difference(configobj)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c).strip() for c in commands if c]
    else:
        commands = [c.strip() for c in str(candidate).split('\n')]

    # FIXME not implemented yet!!
    if replace:
        if module.params['transport'] == 'cli':
            module.fail_json(msg='config replace is only supported over eapi')
        commands = str(candidate).split('\n')

    if commands:
        commands = filter_exit(commands)
        commit = not module.check_mode
        load_config(commands, commit=commit)
        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
コード例 #3
0
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(src=dict(required=True),
                         force=dict(default=False, type='bool'),
                         include_defaults=dict(default=False, type='bool'),
                         backup=dict(default=False, type='bool'),
                         replace=dict(default=False, type='bool'),
                         config=dict())

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = NetworkModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    replace = module.params['replace']

    commands = list()
    running = None

    result = dict(changed=False)

    candidate = NetworkConfig(contents=module.params['src'], indent=3)

    if replace:
        if module.params['transport'] == 'cli':
            module.fail_json(msg='config replace is only supported over eapi')
        commands = str(candidate).split('\n')
    else:
        contents = get_config(module)
        if contents:
            running = NetworkConfig(contents=contents, indent=3)
            result['_backup'] = contents

        if not module.params['force']:
            commands = candidate.difference((running or list()))
            commands = dumps(commands, 'commands').split('\n')
            commands = [str(c) for c in commands if c]
        else:
            commands = str(candidate).split('\n')

    commands = filter_exit(commands)
    if commands:
        if not module.check_mode:
            response = module.config.load_config(commands,
                                                 replace=replace,
                                                 session='eos_template',
                                                 commit=True)

            module.cli('no configure session eos_template')
            result['responses'] = response
        result['changed'] = True

    result['updates'] = commands
    module.exit_json(**result)
コード例 #4
0
ファイル: _eos_template.py プロジェクト: likewg/DevOps
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(
        src=dict(required=True),
        force=dict(default=False, type='bool'),
        include_defaults=dict(default=False, type='bool'),
        backup=dict(default=False, type='bool'),
        replace=dict(default=False, type='bool'),
        config=dict()
    )

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = NetworkModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    replace = module.params['replace']

    commands = list()
    running = None

    result = dict(changed=False)

    candidate = NetworkConfig(contents=module.params['src'], indent=3)

    if replace:
        if module.params['transport'] == 'cli':
            module.fail_json(msg='config replace is only supported over eapi')
        commands = str(candidate).split('\n')
    else:
        contents = get_config(module)
        if contents:
            running = NetworkConfig(contents=contents, indent=3)
            result['_backup'] = contents

        if not module.params['force']:
            commands = candidate.difference((running or list()))
            commands = dumps(commands, 'commands').split('\n')
            commands = [str(c) for c in commands if c]
        else:
            commands = str(candidate).split('\n')

    commands = filter_exit(commands)
    if commands:
        if not module.check_mode:
            response = module.config.load_config(commands, replace=replace,
                                                 commit=True)
            result['responses'] = response
        result['changed'] = True

    result['updates'] = commands
    module.exit_json(**result)
コード例 #5
0
ファイル: _eos_template.py プロジェクト: snowsky/ansible-1
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(src=dict(required=True),
                         force=dict(default=False, type='bool'),
                         include_defaults=dict(default=False, type='bool'),
                         backup=dict(default=False, type='bool'),
                         replace=dict(default=False, type='bool'),
                         config=dict())

    argument_spec.update(eos_argument_spec)

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = AnsibleModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    warnings = list()
    check_args(module, warnings)

    result = {'changed': False}
    if warnings:
        result['warnings'] = warnings

    src = module.params['src']
    candidate = NetworkConfig(contents=src, indent=3)

    if module.params['backup']:
        result['__backup__'] = get_config(module)

    if not module.params['force']:
        contents = get_current_config(module)
        configobj = NetworkConfig(contents=contents, indent=3)
        commands = candidate.difference(configobj)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c).strip() for c in commands if c]
    else:
        commands = [c.strip() for c in str(candidate).split('\n')]

    #commands = str(candidate).split('\n')

    if commands:
        commands = filter_exit(commands)
        commit = not module.check_mode
        replace = module.params['replace'] or False
        load_config(module, commands, commit=commit, replace=replace)
        result['changed'] = True

    result['commands'] = commands
    result['updates'] = commands

    module.exit_json(**result)
コード例 #6
0
ファイル: eos_eapi.py プロジェクト: 2ndQuadrant/ansible
def load(module, instance, commands, result):
    candidate = NetworkConfig(indent=3)
    candidate.add(commands, parents=['management api http-commands'])

    config = get_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        commands = dumps(configobjs, 'commands').split('\n')
        result['updates'] = commands
        load_config(module, instance, commands, result)
コード例 #7
0
def load(module, instance, commands, result):
    candidate = NetworkConfig(indent=3)
    candidate.add(commands, parents=['management api http-commands'])

    config = get_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        commands = dumps(configobjs, 'commands').split('\n')
        result['updates'] = commands
        load_config(module, instance, commands, result)
コード例 #8
0
def load(module, commands, result):
    candidate = NetworkConfig(indent=2, contents='\n'.join(commands))
    config = get_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        commands = dumps(configobjs, 'commands').split('\n')
        result['updates'] = commands
        if not module.check_mode:
            load_config(module, commands, result)
        result['changed'] = True
コード例 #9
0
def main():

    argument_spec = dict(lines=dict(aliases=['commands'],
                                    required=True,
                                    type='list'),
                         before=dict(type='list'),
                         after=dict(type='list'),
                         match=dict(default='line',
                                    choices=['line', 'strict', 'exact']),
                         replace=dict(default='line',
                                      choices=['line', 'block']),
                         force=dict(default=False, type='bool'),
                         config=dict())

    argument_spec.update(asa_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    lines = module.params['lines']

    result = {'changed': False}

    candidate = NetworkConfig(indent=1)
    candidate.add(lines)

    acl_name = parse_acl_name(module)

    if not module.params['force']:
        contents = get_acl_config(module, acl_name)
        config = NetworkConfig(indent=1, contents=contents)

        commands = candidate.difference(config)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c) for c in commands if c]
    else:
        commands = str(candidate).split('\n')

    if commands:
        if module.params['before']:
            commands[:0] = module.params['before']

        if module.params['after']:
            commands.extend(module.params['after'])

        if not module.check_mode:
            load_config(module, commands)

        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
コード例 #10
0
def main():

    argument_spec = dict(
        lines=dict(aliases=['commands'], required=True, type='list'),
        before=dict(type='list'),
        after=dict(type='list'),
        match=dict(default='line', choices=['line', 'strict', 'exact']),
        replace=dict(default='line', choices=['line', 'block']),
        force=dict(default=False, type='bool'),
        config=dict()
    )

    module = NetworkModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    lines = module.params['lines']

    before = module.params['before']
    after = module.params['after']

    match = module.params['match']
    replace = module.params['replace']

    result = dict(changed=False)

    candidate = NetworkConfig(indent=1)
    candidate.add(lines)

    acl_name = parse_acl_name(module)

    if not module.params['force']:
        contents = get_config(module, acl_name)
        config = NetworkConfig(indent=1, contents=contents)

        commands = candidate.difference(config)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c) for c in commands if c]
    else:
        commands = str(candidate).split('\n')

    if commands:
        if not module.check_mode:
            response = module.config(commands)
            result['responses'] = response
        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
コード例 #11
0
ファイル: _ios_template.py プロジェクト: zouzheng1988/ansible
def main():
    """ main entry point for module execution
    """
    argument_spec = dict(
        src=dict(),
        force=dict(default=False, type='bool'),
        include_defaults=dict(default=True, type='bool'),
        backup=dict(default=False, type='bool'),
        config=dict(),
    )

    argument_spec.update(ios_cli.ios_cli_argument_spec)

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    cls = get_ansible_module()
    module = cls(argument_spec=argument_spec,
                 mutually_exclusive=mutually_exclusive,
                 supports_check_mode=True)

    warnings = list()
    check_args(module, warnings)

    candidate = NetworkConfig(contents=module.params['src'], indent=1)

    result = {'changed': False}
    if warnings:
        result['warnings'] = warnings

    if module.params['backup']:
        result['__backup__'] = get_config(module=module)

    if not module.params['force']:
        contents = get_current_config(module)
        configobj = NetworkConfig(contents=contents, indent=1)
        commands = candidate.difference(configobj)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c).strip() for c in commands if c]
    else:
        commands = [c.strip() for c in str(candidate).split('\n')]

    if commands:
        if not module.check_mode:
            load_config(module, commands)
        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
コード例 #12
0
def main():
    """ main entry point for module execution
    """
    argument_spec = dict(
        src=dict(),
        force=dict(default=False, type='bool'),
        include_defaults=dict(default=True, type='bool'),
        backup=dict(default=False, type='bool'),
        config=dict(),
    )

    # Removed the use of provider arguments in 2.3 due to network_cli
    # connection plugin.  To be removed in 2.5
    argument_spec.update(_transitional_argument_spec())

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = LocalAnsibleModule(argument_spec=argument_spec,
                                mutually_exclusive=mutually_exclusive,
                                supports_check_mode=True)

    warnings = check_args(module)

    result = dict(changed=False, warnings=warnings)

    candidate = NetworkConfig(contents=module.params['src'], indent=1)

    result = {'changed': False}

    if module.params['backup']:
        result['__backup__'] = get_config()

    if not module.params['force']:
        contents = get_current_config(module)
        configobj = NetworkConfig(contents=contents, indent=1)
        commands = candidate.difference(configobj)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c).strip() for c in commands if c]
    else:
        commands = [c.strip() for c in str(candidate).split('\n')]

    if commands:
        if not module.check_mode:
            load_config(commands)
        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
コード例 #13
0
def main():

    argument_spec = dict(lines=dict(aliases=['commands'],
                                    required=True,
                                    type='list'),
                         before=dict(type='list'),
                         after=dict(type='list'),
                         match=dict(default='line',
                                    choices=['line', 'strict', 'exact']),
                         replace=dict(default='line',
                                      choices=['line', 'block']),
                         force=dict(default=False, type='bool'),
                         config=dict())

    module = NetworkModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    lines = module.params['lines']

    before = module.params['before']
    after = module.params['after']

    match = module.params['match']
    replace = module.params['replace']

    candidate = NetworkConfig(indent=1)
    candidate.add(lines)

    module.filter = check_input_acl(lines, module)

    if not module.params['force']:
        contents = get_config(module)
        config = NetworkConfig(indent=1, contents=contents)
        commands = candidate.difference(config)
        commands = dumps(commands, 'commands').split('\n')
    else:
        commands = str(candidate).split('\n')

    if commands:
        if not module.check_mode:
            commands = [str(c) for c in commands if c]
            response = module.config(commands)
            result['responses'] = response
        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
コード例 #14
0
def load_config(module, commands, result):
    candidate = NetworkConfig(device_os='sros', contents='\n'.join(commands))
    config = get_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        commands = dumps(configobjs, 'lines')
        commands = sanitize_config(commands.split('\n'))

        result['updates'] = commands

        # send the configuration commands to the device and merge
        # them with the current running config
        if not module.check_mode:
            module.config(commands)

        result['changed'] = True
コード例 #15
0
ファイル: sros_rollback.py プロジェクト: 2ndQuadrant/ansible
def load_config(module, commands, result):
    candidate = NetworkConfig(device_os='sros', contents='\n'.join(commands))
    config = get_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        commands = dumps(configobjs, 'lines')
        commands = sanitize_config(commands.split('\n'))

        result['updates'] = commands

        # send the configuration commands to the device and merge
        # them with the current running config
        if not module.check_mode:
            module.config(commands)

        result['changed'] = True
コード例 #16
0
ファイル: sros_rollback.py プロジェクト: ernstp/ansible
def main():
    """ main entry point for module execution
    """
    argument_spec = dict(
        rollback_location=dict(),

        local_max_checkpoints=dict(type='int'),
        remote_max_checkpoints=dict(type='int'),

        rescue_location=dict(),

        state=dict(default='present', choices=['present', 'absent'])
    )

    argument_spec.update(sros_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    state = module.params['state']

    result = dict(changed=False)

    commands = list()
    invoke(state, module, commands)

    candidate = NetworkConfig(indent=4, contents='\n'.join(commands))
    config = get_device_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        #commands = dumps(configobjs, 'lines')
        commands = dumps(configobjs, 'commands')
        commands = sanitize_config(commands.split('\n'))

        result['updates'] = commands
        result['commands'] = commands

        # send the configuration commands to the device and merge
        # them with the current running config
        if not module.check_mode:
            load_config(module, commands)

        result['changed'] = True

    module.exit_json(**result)
コード例 #17
0
def main():
    """ main entry point for module execution
    """
    argument_spec = dict(
        src=dict(),
        force=dict(default=False, type='bool'),
        include_defaults=dict(default=True, type='bool'),
        backup=dict(default=False, type='bool'),
        config=dict(),
    )

    argument_spec.update(nxos_argument_spec)

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = AnsibleModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    result = dict(changed=False)

    candidate = NetworkConfig(contents=module.params['src'], indent=2)

    contents = get_current_config(module)
    if contents:
        config = NetworkConfig(contents=contents, indent=2)
        result['__backup__'] = str(contents)

    if not module.params['force']:
        commands = candidate.difference(config)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c) for c in commands if c]
    else:
        commands = str(candidate).split('\n')

    if commands:
        if not module.check_mode:
            load_config(module, commands)
        result['changed'] = True

    result['updates'] = commands
    result['commands'] = commands

    module.exit_json(**result)
コード例 #18
0
ファイル: sros_rollback.py プロジェクト: saran410/Devops
def main():
    """ main entry point for module execution
    """
    argument_spec = dict(rollback_location=dict(),
                         local_max_checkpoints=dict(type='int'),
                         remote_max_checkpoints=dict(type='int'),
                         rescue_location=dict(),
                         state=dict(default='present',
                                    choices=['present', 'absent']))

    argument_spec.update(sros_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    state = module.params['state']

    result = dict(changed=False)

    commands = list()
    invoke(state, module, commands)

    candidate = NetworkConfig(indent=4, contents='\n'.join(commands))
    config = get_device_config(module)
    configobjs = candidate.difference(config)

    if configobjs:
        #commands = dumps(configobjs, 'lines')
        commands = dumps(configobjs, 'commands')
        commands = sanitize_config(commands.split('\n'))

        result['updates'] = commands
        result['commands'] = commands

        # send the configuration commands to the device and merge
        # them with the current running config
        if not module.check_mode:
            load_config(module, commands)

        result['changed'] = True

    module.exit_json(**result)
コード例 #19
0
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(
        src=dict(),
        force=dict(default=False, type='bool'),
        backup=dict(default=False, type='bool'),
        config=dict(),
    )

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = NetworkModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    result = dict(changed=False)

    candidate = NetworkConfig(contents=module.params['src'], indent=1)

    contents = get_config(module)

    if contents:
        config = NetworkConfig(contents=contents[0], indent=1)
        result['_backup'] = contents[0]

    commands = list()
    if not module.params['force']:
        commands = dumps(candidate.difference(config), 'commands')
    else:
        commands = str(candidate)

    if commands:
        commands = commands.split('\n')
        if not module.check_mode:
            response = module.config(commands)
            result['responses'] = response
        result['changed'] = True

    result['updates'] = commands
    module.exit_json(**result)
コード例 #20
0
ファイル: _nxos_template.py プロジェクト: likewg/DevOps
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(
        src=dict(),
        force=dict(default=False, type='bool'),
        include_defaults=dict(default=True, type='bool'),
        backup=dict(default=False, type='bool'),
        config=dict(),
    )

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = NetworkModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    result = dict(changed=False)

    candidate = NetworkConfig(contents=module.params['src'], indent=2)

    contents = get_config(module)
    if contents:
        config = NetworkConfig(contents=contents, indent=2)
        result['_backup'] = str(contents)

    if not module.params['force']:
        commands = candidate.difference(config)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c) for c in commands if c]
    else:
        commands = str(candidate).split('\n')

    if commands:
        if not module.check_mode:
            response = module.config(commands)
            result['responses'] = response
        result['changed'] = True

    result['updates'] = commands
    module.exit_json(**result)
コード例 #21
0
ファイル: _ops_template.py プロジェクト: 2ndQuadrant/ansible
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(
        src=dict(type='str'),
        force=dict(default=False, type='bool'),
        backup=dict(default=False, type='bool'),
        config=dict(type='dict'),
    )

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = NetworkModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    if not module.params['transport'] and not HAS_OPS:
        module.fail_json(msg='unable to import ops.dc library')

    result = dict(changed=False)

    contents = get_config(module)
    result['_backup'] = contents

    if module.params['transport'] in ['ssh', 'rest']:
        config = contents

        try:
            src = module.from_json(module.params['src'])
        except ValueError:
            module.fail_json(msg='unable to load src due to json parsing error')

        changeset = diff(src, config)
        candidate = merge(changeset, config)

        updates = dict()
        for path, key, new_value, old_value in changeset:
            path = '%s.%s' % ('.'.join(path), key)
            updates[path] = str(new_value)
        result['updates'] = updates

        if changeset:
            if not module.check_mode:
                module.config(config)
            result['changed'] = True

    else:
        candidate = NetworkConfig(contents=module.params['src'], indent=4)

        if contents:
            config = NetworkConfig(contents=contents, indent=4)

        if not module.params['force']:
            commands = candidate.difference(config)
            commands = dumps(commands, 'commands').split('\n')
            commands = [str(c) for c in commands if c]
        else:
            commands = str(candidate).split('\n')

        if commands:
            if not module.check_mode:
                response = module.config(commands)
                result['responses'] = response
            result['changed'] = True

        result['updates'] = commands

    module.exit_json(**result)
コード例 #22
0
ファイル: ops_template.py プロジェクト: 007root/python
def main():
    """ main entry point for module execution
    """

    argument_spec = dict(
        src=dict(type='str'),
        force=dict(default=False, type='bool'),
        backup=dict(default=False, type='bool'),
        config=dict(type='dict'),
    )

    mutually_exclusive = [('config', 'backup'), ('config', 'force')]

    module = NetworkModule(argument_spec=argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    if not module.params['transport'] and not HAS_OPS:
        module.fail_json(msg='unable to import ops.dc library')

    result = dict(changed=False)

    contents = get_config(module)
    result['_backup'] = contents

    if module.params['transport'] in ['ssh', 'rest']:
        config = contents

        try:
            src = module.from_json(module.params['src'])
        except ValueError:
            module.fail_json(
                msg='unable to load src due to json parsing error')

        changeset = diff(src, config)
        candidate = merge(changeset, config)

        updates = dict()
        for path, key, new_value, old_value in changeset:
            path = '%s.%s' % ('.'.join(path), key)
            updates[path] = str(new_value)
        result['updates'] = updates

        if changeset:
            if not module.check_mode:
                module.config(config)
            result['changed'] = True

    else:
        candidate = NetworkConfig(contents=module.params['src'], indent=4)

        if contents:
            config = NetworkConfig(contents=contents, indent=4)

        if not module.params['force']:
            commands = candidate.difference(config)
            commands = dumps(commands, 'commands').split('\n')
            commands = [str(c) for c in commands if c]
        else:
            commands = str(candidate).split('\n')

        if commands:
            if not module.check_mode:
                response = module.config(commands)
                result['responses'] = response
            result['changed'] = True

        result['updates'] = commands

    module.exit_json(**result)