Exemplo n.º 1
0
def run(module, result):
    match = module.params['match']
    replace = module.params['replace']
    candidate = get_candidate(module)

    if match != 'none':
        config = get_running_config(module)
        path = module.params['parents']
        configobjs = candidate.difference(config, match=match, replace=replace, path=path)
    else:
        configobjs = candidate.items

    if configobjs:
        commands = dumps(configobjs, 'commands').split('\n')
        if module.params['lines']:

            commands = conversion_lines(commands)

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

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

        command_display = []
        for per_command in commands:
            if per_command.strip() not in ['quit', 'return', 'system-view']:
                command_display.append(per_command)

        result['commands'] = command_display
        result['updates'] = command_display
        if not module.check_mode:
            load_config(module, commands)
        if result['commands']:
            result['changed'] = True
Exemplo n.º 2
0
    def cli_load_config(self):
        """load config by cli"""

        if not self.module.check_mode:
            if len(self.commands) > 1:
                load_config(self.module, self.commands)
                self.changed = True
Exemplo n.º 3
0
def run(module, result):
    match = module.params['match']
    replace = module.params['replace']

    candidate = get_candidate(module)

    if match != 'none':
        config = get_running_config(module)
        path = module.params['parents']
        configobjs = candidate.difference(config,
                                          match=match,
                                          replace=replace,
                                          path=path)
    else:
        configobjs = candidate.items

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

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

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

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

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

        result['changed'] = True
Exemplo n.º 4
0
def run(module, result):
    match = module.params['match']
    replace = module.params['replace']

    candidate = get_candidate(module)

    if match != 'none':
        config = get_running_config(module)
        path = module.params['parents']
        configobjs = candidate.difference(config, match=match, replace=replace, path=path)
    else:
        configobjs = candidate.items

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

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

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

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

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

        result['changed'] = True
Exemplo n.º 5
0
    def cli_load_config(self, commands):
        """load config by cli"""

        if not self.module.check_mode:
            load_config(self.module, commands)
Exemplo n.º 6
0
    def cli_load_config(self, commands):
        """ Load config by cli """

        if not self.module.check_mode:
            load_config(self.module, commands)
Exemplo n.º 7
0
    def cli_load_config(self, commands):
        """ Cli method to load config """

        if not self.module.check_mode:
            load_config(self.module, commands)
Exemplo n.º 8
0
    def cli_load_config(self, commands):
        """ Cli load configuration """

        if not self.module.check_mode:
            load_config(self.module, commands)
Exemplo n.º 9
0
def run(module, result):
    match = module.params['match']
    replace = module.params['replace']

    candidate = get_candidate(module)

    if match != 'none':
        before = get_running_config(module)
        path = module.params['parents']
        configobjs = candidate.difference(before,
                                          match=match,
                                          replace=replace,
                                          path=path)
    else:
        configobjs = candidate.items

    if configobjs:
        out_type = "commands"
        if module.params["src"] is not None:
            out_type = "raw"
        commands = dumps(configobjs, out_type).split('\n')

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

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

        command_display = []
        for per_command in commands:
            if per_command.strip() not in ['quit', 'return', 'system-view']:
                command_display.append(per_command)

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

        if not module.check_mode:
            if module.params['parents'] is not None:
                load_config(module, commands)
            else:
                _load_config(module, commands)
        if match != "none":
            after = get_running_config(module)
            path = module.params["parents"]
            if path is not None and match != 'line':
                before_objs = before.get_block(path)
                after_objs = after.get_block(path)
                update = []
                if len(before_objs) == len(after_objs):
                    for b_item, a_item in zip(before_objs, after_objs):
                        if b_item != a_item:
                            update.append(a_item.text)
                else:
                    update = [item.text for item in after_objs]
                if len(update) == 0:
                    result["changed"] = False
                    result['updates'] = []
                else:
                    result["changed"] = True
                    result['updates'] = update
            else:
                configobjs = after.difference(before,
                                              match=match,
                                              replace=replace,
                                              path=path)
                if len(configobjs) > 0:
                    result["changed"] = True
                else:
                    result["changed"] = False
                    result['updates'] = []
        else:
            result['changed'] = True
Exemplo n.º 10
0
    def cli_load_config(self, commands):
        """ Load configure through cli """

        if not self.module.check_mode:
            load_config(self.module, commands)
Exemplo n.º 11
0
    def cli_load_config(self, commands):
        """ Cli method to load config """

        if not self.module.check_mode:
            load_config(self.module, commands)
Exemplo n.º 12
0
    def cli_load_config(self, commands):
        """ Cli load configuration """

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