コード例 #1
0
def get_candidate(module):
    candidate = NetworkConfig(indent=1)
    if module.params['src']:
        candidate.load(module.params['src'])
    elif module.params['lines']:
        parents = module.params['parents'] or list()
        candidate.add(module.params['lines'], parents=parents)
    return candidate
コード例 #2
0
def get_candidate(module):
    candidate = NetworkConfig(indent=1)

    if module.params['src']:
        candidate.load(module.params['src'])
    elif module.params['lines']:
        candidate.add(module.params['lines'])
    return candidate
コード例 #3
0
def get_candidate(module):
    candidate = ''
    if module.params['src']:
        candidate = module.params['src']
    elif module.params['lines']:
        candidate_obj = NetworkConfig(indent=3)
        parents = module.params['parents'] or list()
        candidate_obj.add(module.params['lines'], parents=parents)
        candidate = dumps(candidate_obj, 'raw')
    return candidate
コード例 #4
0
    def get_candidate(self):
        candidate = ''
        if self.want.src:
            candidate = self.want.src

        elif self.want.lines:
            candidate_obj = NetworkConfig(indent=1)
            parents = self.want.parents or list()
            candidate_obj.add(self.want.lines, parents=parents)
            candidate = dumps(candidate_obj, 'raw')
        return candidate
コード例 #5
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}
    if len(lines) > 0:
        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)
コード例 #6
0
def get_candidate(module):
    candidate = NetworkConfig(indent=1)
    banners = {}

    if module.params['src']:
        src, banners = extract_banners(module.params['src'])
        candidate.load(src)

    elif module.params['lines']:
        parents = module.params['parents'] or list()
        candidate.add(module.params['lines'], parents=parents)

    return candidate, banners
コード例 #7
0
def get_candidate(module):
    candidate = ''
    if module.params['src']:
        if module.params['replace'] != 'config':
            candidate = module.params['src']
    if module.params['replace'] == 'config':
        candidate = 'config replace {0}'.format(module.params['replace_src'])
    elif module.params['lines']:
        candidate_obj = NetworkConfig(indent=2)
        parents = module.params['parents'] or list()
        candidate_obj.add(module.params['lines'], parents=parents)
        candidate = dumps(candidate_obj, 'raw')
    return candidate
コード例 #8
0
def get_candidate(module):
    candidate = NetworkConfig(indent=1)
    if module.params['src']:
        candidate.load(module.params['src'])
    elif module.params['lines']:
        parents = module.params['parents'] or list()
        commands = module.params['lines'][0]
        if (isinstance(commands, dict)) and (isinstance(
                commands['command'], list)):
            candidate.add(commands['command'], parents=parents)
        elif (isinstance(commands, dict)) and (isinstance(
                commands['command'], str)):
            candidate.add([commands['command']], parents=parents)
        else:
            candidate.add(module.params['lines'], parents=parents)
    return candidate