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
Beispiel #2
0
    def cli_load_config(self, commands):
        """load config by cli"""

        if not self.module.check_mode:
            load_config(self.module, commands)
    def cli_load_config(self, commands):
        """ Load configure through cli """

        if not self.module.check_mode:
            load_config(self.module, commands)
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
    def cli_load_config(self, commands):
        """ Cli load configuration """

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