Example #1
0
def _load_config(module, config):
    """Sends configuration commands to the remote device
    """
    rc, out, err = exec_command(module, 'mmi-mode enable')
    if rc != 0:
        module.fail_json(msg='unable to set mmi-mode enable', output=err)
    rc, out, err = exec_command(module, 'system-view immediately')
    if rc != 0:
        module.fail_json(msg='unable to enter system-view', output=err)

    for index, cmd in enumerate(config):
        rc, out, err = exec_command(module, cmd)
        if rc != 0:
            print_msg = cli_err_msg(cmd.strip(), err)
            exec_command(module, "quit")
            rc, out, err = exec_command(module, cmd)
            if rc != 0:
                print_msg1 = cli_err_msg(cmd.strip(), err)
                if not re.findall(r"unrecognized command found", print_msg1):
                    print_msg = print_msg1
                exec_command(module, "return")
                exec_command(module, "system-view immediately")
                rc, out, err = exec_command(module, cmd)
                if rc != 0:
                    print_msg2 = cli_err_msg(cmd.strip(), err)
                    if not re.findall(r"unrecognized command found",
                                      print_msg2):
                        print_msg = print_msg2
                    module.fail_json(msg=print_msg)

    exec_command(module, 'return')
Example #2
0
def _load_config(module, config):
    """Sends configuration commands to the remote device
    """
    connection = Connection(module._socket_path)
    rc, out, err = exec_command(module, 'system-view')
    if rc != 0:
        module.fail_json(msg='unable to enter system-view', output=err)
    current_view_prompt = system_view_prompt = connection.get_prompt()

    for index, cmd in enumerate(config):
        level = command_level(cmd)
        current_view_prompt = connection.get_prompt()
        rc, out, err = exec_command(module, cmd)
        if rc != 0:
            print_msg = cli_err_msg(cmd.strip(), err)
            # re-try command max 3 times
            for i in (1, 2, 3):
                current_view_prompt = connection.get_prompt()
                if current_view_prompt != system_view_prompt and not_user_view(
                        current_view_prompt):
                    exec_command(module, "quit")
                    current_view_prompt = connection.get_prompt()
                    # if current view is system-view, break.
                    if current_view_prompt == system_view_prompt and level > 0:
                        break
                elif current_view_prompt == system_view_prompt or not not_user_view(
                        current_view_prompt):
                    break
                rc, out, err = exec_command(module, cmd)
                if rc == 0:
                    print_msg = None
                    break
            if print_msg is not None:
                module.fail_json(msg=print_msg)
Example #3
0
    def load_config(self, config):
        """Sends configuration commands to the remote device"""

        rc, out, err = exec_command(self.module, 'mmi-mode enable')
        if rc != 0:
            self.module.fail_json(msg='unable to set mmi-mode enable',
                                  output=err)
        rc, out, err = exec_command(self.module, 'system-view immediately')
        if rc != 0:
            self.module.fail_json(msg='unable to enter system-view',
                                  output=err)

        for cmd in config:
            rc, out, err = exec_command(self.module, cmd)
            if rc != 0:
                if "unrecognized command found" in err.lower():
                    self.module.fail_json(
                        msg=
                        "Error:The parameter is incorrect or the interface does not support this parameter."
                    )
                else:
                    self.module.fail_json(msg=cli_err_msg(cmd.strip(), err))

        exec_command(self.module, 'return')