コード例 #1
0
    def create(self):
        """creates the junos state machine"""

        ##########################################################
        # State Definition
        ##########################################################
        shell = State('shell', patterns.shell_prompt)
        enable = State('enable', patterns.enable_prompt)
        config = State('config', patterns.config_prompt)

        ##########################################################
        # Path Definition
        ##########################################################
        config_dialog = Dialog([
            [
                patterns.commit_changes_prompt, 'sendline(yes)', None, True,
                False
            ],
        ])
        enable_to_shell = Path(enable, shell, 'exit', None)
        shell_to_enable = Path(shell, enable, 'cli', None)

        enable_to_config = Path(enable, config, 'configure', None)
        config_to_enable = Path(config, enable, 'exit', config_dialog)

        # Add State and Path to State Machine
        self.add_state(shell)
        self.add_state(enable)
        self.add_state(config)

        self.add_path(enable_to_shell)
        self.add_path(shell_to_enable)

        self.add_path(enable_to_config)
        self.add_path(config_to_enable)
コード例 #2
0
    def create(self):
        p = patterns.ASAPatterns()

        enable = State('enable', p.enable_prompt)
        disable = State('disable', p.disable_prompt)
        config = State('config', p.config_prompt)

        enable_to_disable = Path(enable, disable, 'disable', None)
        enable_to_config = Path(enable, config, 'config term', None)

        disable_to_enable = Path(disable, enable, 'enable',
                                 Dialog([statements.enable_password]))

        config_to_enable = Path(config, enable, 'end', None)

        self.add_state(enable)
        self.add_state(disable)
        self.add_state(config)

        self.add_path(enable_to_disable)
        self.add_path(enable_to_config)
        self.add_path(config_to_enable)
        self.add_path(disable_to_enable)

        self.add_default_statements(default_statement_list)
コード例 #3
0
    def create(self):
        super().create()
        self.remove_path('disable', 'enable')
        self.remove_path('rommon', 'disable')
        self.remove_path('enable', 'disable')
        self.remove_state('disable')
        # Adding SHELL state to NXOS platform.
        shell = State('shell', patterns.shell_prompt)
        enable = self.get_state('enable')
        # Loader state
        loader = State('loader', patterns.loader_prompt)
        # Guestshell state
        guestshell = State('guestshell', patterns.guestshell_prompt)

        enable_to_shell = Path(enable, shell, 'run bash', None)
        shell_to_enable = Path(shell, enable, 'exit', None)

        enable_to_guestshell = Path(enable, guestshell, 'guestshell', None)
        guestshell_to_enable = Path(guestshell, enable, 'exit', None)

        # Add State and Path to State Machine
        self.add_state(shell)
        self.add_state(loader)
        self.add_state(guestshell)
        self.add_path(enable_to_shell)
        self.add_path(shell_to_enable)
        self.add_path(enable_to_guestshell)
        self.add_path(guestshell_to_enable)
コード例 #4
0
    def crash_restart(self):
        '''Send configuration to shut

           Args:
               uut (`obj`): Device object.
               abstract (`obj`): Abstract object.
               steps (`step obj`): aetest step object

           Returns:
               None

           Raises:
               pyATS Results
        '''
        if not hasattr(self.device, 'debug_plugin'):
            raise Exception('No debug plugin has been loaded on the device.')

        ha = self.abstract.sdk.libs.abstracted_libs.ha.HA(
            device=self.device, tftp=self.device.tftp)
        # https://devxsupport.cisco.com/scp/tickets.php?id=39483
        State('config', r'Linux')
        State('exec', r'Linux')

        ha.load_debug_plugin(self.device.debug_plugin)

        # Set pattern
        self.device.execute('kill -{cm} {p}\n'.\
                              format(p=self.previous_pid,
                                     cm=self.obj.crash_method),
                            timeout=10)
        self.device.execute('exit', timeout=10)

        restore_state = State(name='config', pattern=r'^.(%N\(config\))#\s?')
コード例 #5
0
    def create(self):
        super().create()

        self.remove_path('enable', 'rommon')
        self.remove_path('rommon', 'disable')
        self.remove_state('rommon')
        # incase there is no previous shell state regiestered
        try:
            self.remove_path('shell', 'enable')
            self.remove_path('enable', 'shell')
            self.remove_state('shell')
        except Exception:
            pass

        rommon = State('rommon', patterns.rommon_prompt)
        enable_to_rommon = Path(self.get_state('enable'), rommon, 'reload',
                                Dialog(reload_statement_list))
        rommon_to_disable = Path(rommon, self.get_state('disable'),
                                 boot_from_rommon,
                                 Dialog(connection_statement_list))
        self.add_state(rommon)
        self.add_path(enable_to_rommon)
        self.add_path(rommon_to_disable)

        shell = State('shell', patterns.shell_prompt)
        enable_to_shell = Path(self.get_state('enable'), shell,
                               'request platform software system shell')
        shell_to_enable = Path(shell, self.get_state('enable'), 'exit', None)
        self.add_state(shell)
        self.add_path(enable_to_shell)
        self.add_path(shell_to_enable)
コード例 #6
0
    def create(self):
        # Create States
        disable_state = State(AsaSmStates.DISABLE_STATE.value, self.patterns.prompt.disable_prompt)
        enable_state = State(AsaSmStates.ENABLE_STATE.value, self.patterns.prompt.enable_prompt)
        config_state = State(AsaSmStates.CONFIG_STATE.value, self.patterns.prompt.config_prompt)

        # Add states
        self.add_state(disable_state)
        self.add_state(enable_state)
        self.add_state(config_state)

        # Create paths
        enable_dialog = Dialog(
            [self.statements.disable_to_enable_statement,
             self.statements.set_enable_pwd_statement,
             self.statements.repeat_enable_pwd_statement,
            ]
        )
        disable_to_enable_path = Path(disable_state, enable_state, 'enable', enable_dialog)
        enable_to_disable_path = Path(enable_state, disable_state, 'disable', None)
        enable_to_config_path = Path(enable_state, config_state, 'config t', None)
        config_to_enable_path = Path(config_state, enable_state, 'end', None)

        # Add paths
        self.add_path(disable_to_enable_path)
        self.add_path(enable_to_disable_path)
        self.add_path(enable_to_config_path)
        self.add_path(config_to_enable_path)
コード例 #7
0
    def create(self):
        enable = State('enable', patterns.enable_prompt)
        boot = State('boot', patterns.loader_prompt)

        self.add_state(enable)
        self.add_state(boot)
        self.add_default_statements(default_statement_list)
コード例 #8
0
    def create(self):
        enable = State('enable', patterns.enable_prompt)
        config = State('config', patterns.config_prompt)
        shell = State('shell', patterns.shell_prompt)
        loader = State('loader', patterns.loader_prompt)
        guestshell = State('guestshell', patterns.guestshell_prompt)

        enable_to_config = Path(enable, config, 'config term', None)
        config_to_enable = Path(config, enable, 'end', None)

        enable_to_shell = Path(enable, shell, 'run bash', None)
        shell_to_enable = Path(shell, enable, 'exit', None)

        enable_to_guestshell = Path(enable, guestshell, 'guestshell', None)
        guestshell_to_enable = Path(guestshell, enable, 'exit', None)

        # Add State and Path to State Machine
        self.add_state(enable)
        self.add_state(config)
        self.add_state(shell)
        self.add_state(loader)
        self.add_state(guestshell)

        self.add_path(enable_to_config)
        self.add_path(config_to_enable)
        self.add_path(enable_to_shell)
        self.add_path(shell_to_enable)
        self.add_path(enable_to_guestshell)
        self.add_path(guestshell_to_enable)

        self.add_default_statements(default_statement_list)
コード例 #9
0
    def create(self):
        shell = State('shell', patterns.shell_prompt)
        enable = State('enable', patterns.enable_prompt)
        config = State('config', patterns.config_prompt)

        self.add_state(shell)
        self.add_state(enable)
        self.add_state(config)

        shell_dialog = Dialog(
            [[patterns.shell_prompt, 'sendline(exec)', None, True, False]])

        config_dialog = Dialog([[
            patterns.commit_changes_prompt, 'sendline(yes)', None, True, False
        ], [
            patterns.commit_replace_prompt, 'sendline(yes)', None, True, False
        ],
                                [
                                    patterns.configuration_failed_message,
                                    self.handle_failed_config, None, True,
                                    False
                                ]])

        shell_to_enable = Path(shell, enable, 'exec', None)
        enable_to_config = Path(enable, config, 'configure terminal', None)
        config_to_enable = Path(config, enable, 'end', config_dialog)

        self.add_path(shell_to_enable)
        self.add_path(enable_to_config)
        self.add_path(config_to_enable)

        self.add_default_statements(self.default_commands)
コード例 #10
0
    def create(self):
        cisco_exec = State('cisco_exec', patterns.cisco_prompt)
        cisco_config = State('cisco_config', patterns.cisco_config_prompt)
        vshell = State('cisco_vshell', patterns.shell_prompt)

        self.add_state(cisco_exec)
        self.add_state(cisco_config)
        self.add_state(vshell)

        cisco_exec_to_config = Path(cisco_exec, cisco_config, 'config term',
                                    None)

        # Ignore config changes on state change
        # config commits are done as part of the configure method
        cisco_config_dialog = Dialog([
            # Uncommitted changes found, commit them? [yes/no/CANCEL] no
            [
                patterns.cisco_commit_changes_prompt, 'sendline(no)', None,
                True, False
            ],
        ])

        cisco_config_to_exec = Path(cisco_config, cisco_exec, 'end',
                                    cisco_config_dialog)

        cisco_exec_to_vshell = Path(cisco_exec, vshell, 'vshell', None)
        vshell_to_cisco_exec = Path(vshell, cisco_exec, 'exit', None)

        self.add_path(cisco_exec_to_config)
        self.add_path(cisco_config_to_exec)
        self.add_path(cisco_exec_to_vshell)
        self.add_path(vshell_to_cisco_exec)

        self.add_default_statements(default_statement_list)
コード例 #11
0
    def create(self):
        # Create States and their state patterns
        prelogin_state = State('prelogin_state',
                               self.patterns.prompt.prelogin_prompt)
        admin_state = State('admin_state', self.patterns.prompt.admin_prompt)
        sudo_state = State('sudo_state', self.patterns.prompt.sudo_prompt)

        # Add our states to the state machine
        self.add_state(admin_state)
        self.add_state(sudo_state)
        self.add_state(prelogin_state)

        # Create paths for switching between states
        admin_to_sudo = Path(admin_state, sudo_state, 'sudo su -',
                             self.dialogs.d_admin_to_sudo)

        sudo_to_admin = Path(sudo_state, admin_state, "exit", None)

        prelogin_to_admin = Path(
            prelogin_state, admin_state, 'admin',
            Dialog([self.statements.login_password_statement]))

        admin_to_prelogin = Path(admin_state, prelogin_state, 'exit', None)

        # Add paths to the State Machine
        self.add_path(admin_to_sudo)
        self.add_path(sudo_to_admin)
        self.add_path(prelogin_to_admin)
        self.add_path(admin_to_prelogin)

        # after inactivity timer, it will go back to prelogin:
        self.add_default_statements(self.statements.login_password)
コード例 #12
0
    def create(self):
        enable = State('enable', patterns.enable_prompt)
        config = State('config', patterns.config_prompt)
        shell = State('shell', patterns.shell_prompt)
        loader = State('loader', patterns.loader_prompt)
        guestshell = State('guestshell', patterns.guestshell_prompt)
        module = State('module', patterns.module_prompt)
        module_elam = State('module_elam', patterns.module_elam_prompt)
        module_elam_insel = State('module_elam_insel', patterns.module_elam_insel_prompt)
        debug = State('debug', patterns.debug_prompt)
        sqlite = State('sqlite', patterns.sqlite_prompt)

        enable_to_config = Path(enable, config, send_config_cmd, None)
        config_to_enable = Path(config, enable, 'end', Dialog([
            Statement(pattern=patterns.commit_changes_prompt,
                      action='sendline(no)',
                      loop_continue=True)
        ]))

        enable_to_shell = Path(enable, shell, 'run bash', None)
        shell_to_enable = Path(shell, enable, 'exit', None)

        enable_to_guestshell = Path(enable, guestshell, 'guestshell', None)
        guestshell_to_enable = Path(guestshell, enable, 'exit', None)

        enable_to_module = Path(enable, module, attach_module, None)
        module_to_enable = Path(module, enable, 'exit', None)
        module_elam_to_module = Path(module_elam, module, 'exit', None)
        module_elam_insel_to_module = Path(module_elam_insel, module_elam, 'exit', None)

        debug_to_enable = Path(debug, enable, 'exit', None)
        sqlite_to_debug = Path(sqlite, debug, '.exit', None)

        # Add State and Path to State Machine
        self.add_state(enable)
        self.add_state(config)
        self.add_state(shell)
        self.add_state(loader)
        self.add_state(guestshell)
        self.add_state(module)
        self.add_state(module_elam)
        self.add_state(module_elam_insel)
        self.add_state(debug)
        self.add_state(sqlite)

        self.add_path(enable_to_config)
        self.add_path(config_to_enable)
        self.add_path(enable_to_shell)
        self.add_path(shell_to_enable)
        self.add_path(enable_to_guestshell)
        self.add_path(guestshell_to_enable)
        self.add_path(enable_to_module)
        self.add_path(module_to_enable)
        self.add_path(module_elam_to_module)
        self.add_path(module_elam_insel_to_module)
        self.add_path(debug_to_enable)
        self.add_path(sqlite_to_debug)

        self.add_default_statements(default_statement_list)
コード例 #13
0
    def create(self):
        cisco_exec = State('cisco_exec', patterns.cisco_prompt)
        juniper_exec = State('juniper_exec', patterns.juniper_prompt)
        cisco_config = State('cisco_config', patterns.cisco_config_prompt)
        juniper_config = State('juniper_config',
                               patterns.juniper_config_prompt)

        self.add_state(cisco_exec)
        self.add_state(juniper_exec)
        self.add_state(cisco_config)
        self.add_state(juniper_config)

        cisco_to_juniper_exec = Path(cisco_exec, juniper_exec, 'switch cli',
                                     None)
        juniper_to_cisco_exec = Path(juniper_exec, cisco_exec, 'switch cli',
                                     None)

        cisco_exec_to_juniper_config = Path(cisco_config, juniper_config,
                                            'switch cli', None)
        juniper_exec_to_cisco_config = Path(juniper_config, cisco_config,
                                            'switch cli', None)

        cisco_exec_to_config = Path(cisco_exec, cisco_config, 'config', None)
        juniper_exec_to_config = Path(juniper_exec, juniper_config,
                                      'configure', None)

        # Ignore config changes on state change
        # config commits are done as part of the configure method
        cisco_config_dialog = Dialog([
            # Uncommitted changes found, commit them? [yes/no/CANCEL] no
            [
                patterns.cisco_commit_changes_prompt, 'sendline(no)', None,
                True, False
            ],
        ])
        juniper_config_dialog = Dialog([
            # Discard changes and continue? [yes,no] yes
            [
                patterns.juniper_commit_changes_prompt, 'sendline(yes)', None,
                True, False
            ],
        ])

        cisco_config_to_exec = Path(cisco_config, cisco_exec, 'end',
                                    cisco_config_dialog)
        juniper_config_to_exec = Path(juniper_config, juniper_exec, 'exit',
                                      juniper_config_dialog)

        self.add_path(cisco_to_juniper_exec)
        self.add_path(juniper_to_cisco_exec)
        self.add_path(cisco_exec_to_juniper_config)
        self.add_path(juniper_exec_to_cisco_config)
        self.add_path(cisco_exec_to_config)
        self.add_path(juniper_exec_to_config)
        self.add_path(cisco_config_to_exec)
        self.add_path(juniper_config_to_exec)
        self.add_default_statements(default_statement_list)
コード例 #14
0
 def create(self):
     shell = State('shell', p.prompt)
     config = State('config', p.config_prompt)
     shell_to_config = Path(shell, config, 'config term', None)
     config_to_shell = Path(config, shell, 'end', None)
     self.add_state(shell)
     self.add_state(config)
     self.add_path(shell_to_config)
     self.add_path(config_to_shell)
コード例 #15
0
    def create(self):
        # Create States and their state patterns
        fxos_state = State('fxos_state', self.patterns.prompt.fxos_prompt)
        fireos_state = State('fireos_state', self.patterns.prompt.fireos_prompt)
        expert_state = State('expert_state', self.patterns.prompt.expert_prompt)
        sudo_state = State('sudo_state', self.patterns.prompt.sudo_prompt)
        rommon_state = State('rommon_state', self.patterns.prompt.rommon_prompt)
        local_mgmt_state = State('local_mgmt_state', self.patterns.prompt.local_mgmt_prompt)

        # lina cli states
        enable_state = State('enable_state', self.patterns.prompt.enable_prompt)
        disable_state = State('disable_state', self.patterns.prompt.disable_prompt)
        config_state = State('config_state', self.patterns.prompt.config_prompt)

        # Add our states to the state machine
        self.add_state(fxos_state)
        self.add_state(fireos_state)
        self.add_state(expert_state)
        self.add_state(sudo_state)
        self.add_state(rommon_state)
        self.add_state(local_mgmt_state)
        self.add_state(enable_state)
        self.add_state(disable_state)
        self.add_state(config_state)

        # Create paths for switching between states        
        fxos_to_ftd = Path(fxos_state, fireos_state, "connect ftd", None)
        fxos_to_local_mgmt = Path(fxos_state, local_mgmt_state, "connect local-mgmt", None)
        ftd_to_expert = Path(fireos_state, expert_state, "expert", None)
        ftd_expert_to_sudo = Path(expert_state, sudo_state, "sudo su -", self.dialogs.d_expert_to_sudo)
        ftd_sudo_to_expert = Path(sudo_state, expert_state, "exit", None)
        expert_to_ftd = Path(expert_state, fireos_state, "exit", None)
        local_mgmt_to_fxos = Path(local_mgmt_state, fxos_state, "exit", None)
        # there are two paths from fireos_state to fxos_state.
        # 1. if on console, type "exit". if you type "connect fxos" you will be prompted to use "exit".
        # 2. if on mgmt vty, type "connect fxos". if you type "exit", you will lose the vty.
        # the following dialog tries "connect fxos" first, if prompted, uses "exit". it should work on both.
        ftd_to_fxos = Path(fireos_state, fxos_state, "connect fxos", self.dialogs.d_ftd_to_fxos)

        # Create lina cli paths
        enable_to_disable_state = Path(enable_state, disable_state, "disable", None)
        enable_to_config_path = Path(enable_state, config_state, 'conf t', None)
        config_to_enable_path = Path(config_state, enable_state, 'end', None)        

        # Add paths to the State Machine
        self.add_path(fxos_to_ftd)
        self.add_path(ftd_to_fxos)
        self.add_path(fxos_to_local_mgmt)
        self.add_path(local_mgmt_to_fxos)
        self.add_path(ftd_to_expert)
        self.add_path(expert_to_ftd)
        self.add_path(ftd_expert_to_sudo)
        self.add_path(ftd_sudo_to_expert)
        self.add_path(enable_to_disable_state)
        self.add_path(enable_to_config_path)
        self.add_path(config_to_enable_path)

        # after inactivity timer, it will go back to prelogin:
        self.add_default_statements([self.statements.login_incorrect, self.statements.login_password])
コード例 #16
0
    def create(self):
        exec_mode = State('enable', patterns.exec_prompt)
        config_mode = State('config', patterns.config_prompt)

        exec_to_config = Path(exec_mode, config_mode, 'conf', None)
        config_to_exec = Path(config_mode, exec_mode, 'end', None)

        self.add_state(exec_mode)
        self.add_state(config_mode)

        self.add_path(exec_to_config)
        self.add_path(config_to_exec)
コード例 #17
0
    def create(self):
        mdcli = State('mdcli', patterns.mdcli_prompt)
        classiccli = State('classiccli', patterns.classiccli_prompt)

        mdcli_to_classiccli = Path(mdcli, classiccli, '//')
        classiccli_to_mdcli = Path(classiccli, mdcli, '//')

        self.add_state(mdcli)
        self.add_state(classiccli)

        self.add_path(mdcli_to_classiccli)
        self.add_path(classiccli_to_mdcli)
コード例 #18
0
    def crash_restart(self):
        '''Send configuration to shut

           Args:
               uut (`obj`): Device object.
               abstract (`obj`): Abstract object.
               steps (`step obj`): aetest step object

           Returns:
               None

           Raises:
               pyATS Results
        '''
        if not hasattr(self.device.custom, 'debug_plugin'):
            raise Exception('No debug plugin has been loaded on the device.')

        ha = self.abstract.sdk.libs.abstracted_libs.ha.HA(
            device=self.device, filetransfer=self.device.filetransfer)
        # https://devxsupport.cisco.com/scp/tickets.php?id=39483
        State('config', r'Linux')
        State('exec', r'Linux')

        output = ha.load_debug_plugin(self.device.custom.debug_plugin)

        if 'Incompatible' in output:
            raise Exception("Incompatible debug plugin image\n")

        try:
            self.device.execute('kill -{cm} {p}\n'.\
                                format(p=self.previous_pid,
                                        cm=self.obj.crash_method),
                                timeout=10)
        except Exception as e:
            log.info('Exception raised is expected when running trigger '\
                'through management connection. Exception: {e}'.format(e=e))
            # Set pattern
            restore_state = State(name='config',
                                  pattern=r'^.(%N\(config\))#\s?')
            return

        self.device.instantiate()
        if 'vty' == self.device.connectionmgr.connections.cli.via:
            time.sleep(60)
            self.device.destroy()
            self.device.connect(via='vty')
        else:
            self.device.execute('exit', timeout=10)

        # Set pattern
        restore_state = State(name='config', pattern=r'^.(%N\(config\))#\s?')
コード例 #19
0
 def define_asa_level_states(self):
     available_slots = self.get_available_slots()
     for slot in available_slots:
         state_name = 'slot_' + slot + '_asa_state'
         self.states_dict.update({
             state_name: State(state_name, self.patterns.prompt.asa_prompt)
         })
コード例 #20
0
    def create(self):
        super().create()

        container_shell = State('container_shell',
                                patterns.container_shell_prompt)

        rommon = self.get_state('rommon')
        disable = self.get_state('disable')
        enable = self.get_state('enable')

        self.add_state(container_shell)

        rommon.pattern = patterns.rommon_prompt

        self.remove_path('rommon', 'disable')
        self.remove_path('enable', 'rommon')

        rommon_to_disable = Path(
            rommon, disable, boot_from_rommon,
            Dialog(rommon_boot_statement_list + [boot_timeout_stmt]))
        enable_to_rommon = Path(enable, rommon, 'reload',
                                Dialog(reload_to_rommon_statement_list))

        container_shell_to_enable = Path(container_shell, enable, 'exit', None)

        self.add_path(rommon_to_disable)
        self.add_path(enable_to_rommon)
        self.add_path(container_shell_to_enable)
コード例 #21
0
    def create(self):
        """creates the state machine"""

        ##########################################################
        # State Definition
        ##########################################################

        enable = State('enable', patterns.enable_prompt)
        disable = State('disable', patterns.disable_prompt)
        config = State('config', patterns.config_prompt)
        rommon = State('rommon', patterns.rommon_prompt)
        # standby_enable = State('standby_enable', patterns.standby_enable_prompt)
        # standby_disable = State('standby_disable', patterns.standby_disable_prompt)
        standby_locked = State('standby_locked', patterns.standby_locked)

        ##########################################################
        # Path Definition
        ##########################################################

        enable_to_disable = Path(enable, disable, 'disable', None)
        enable_to_config = Path(enable, config, 'config term', None)
        enable_to_rommon = Path(enable, rommon, 'reload', None)
        disable_to_enable = Path(
            disable, enable, 'enable',
            Dialog([
                statements.enable_password_stmt, statements.bad_password_stmt
            ]))
        config_to_enable = Path(config, enable, 'end', None)
        rommon_to_disable = Path(rommon, disable, 'boot',
                                 Dialog(authentication_statement_list))

        self.add_state(enable)
        self.add_state(config)
        self.add_state(disable)
        self.add_state(rommon)
        # self.add_state(standby_enable)
        # self.add_state(standby_disable)
        self.add_state(standby_locked)

        self.add_path(rommon_to_disable)
        self.add_path(disable_to_enable)
        self.add_path(enable_to_config)
        self.add_path(enable_to_rommon)
        self.add_path(config_to_enable)
        self.add_path(enable_to_disable)

        self.add_default_statements(default_statement_list)
コード例 #22
0
    def create(self):
        self.prompt = self.prompt if hasattr(self, 'prompt') else None
        self.shell_prompt = self.shell_prompt if hasattr(
            self, 'shell_prompt') else None

        shell = State('shell', self.prompt or p.prompt)
        learn_hostname = State('learn_hostname', p.learn_hostname)
        learn_hostname_to_shell = Path(
            learn_hostname, shell,
            set_update_shell_prompt_pattern(self.shell_prompt), None)

        self.add_state(shell)

        # the learn_hostname state must be added as the last state entry, this will make it first
        # in the pattern list when using learn_hostname = True.
        self.add_state(learn_hostname)
        self.add_path(learn_hostname_to_shell)
コード例 #23
0
    def define_contexts(self, contexts=None):
        """
        Add the new states machine for contexts.
        Append the prompts, states and paths for the contexts

        :param contexts: a list with contexts name diffrent than  ['system', 'admin']
                eq. ['ctx1','ctx2']
                if not given, defaulted to ['system', 'admin']
        :return: None
        """

        # add system_state
        if 'system_state' not in [s.name for s in self.sm.states]:
            system_ctx_prompt = 'system_prompt'
            ctx_prompt_value = '[\r\n][\x07]?system>'
            self.sm.patterns.prompt.update(
                {system_ctx_prompt: ctx_prompt_value})
            system_ctx_state = State('system_state', ctx_prompt_value)
            self.sm.add_state(system_ctx_state)
        else:
            system_ctx_state = \
                [s for s in self.sm.states if s.name == 'system_state'][0]

        if not contexts:
            contexts = ['admin']
        else:
            contexts.append('admin')

        for ctx in contexts:
            context_prompt = '{}_ctx_prompt'.format(ctx)
            ctx_prompt_value = '[\r\n][\x07]?{}>'.format(ctx)
            self.sm.patterns.prompt.update({context_prompt: ctx_prompt_value})

            ctx_state = '{}_ctx_state'.format(ctx)
            context_ctx_state = State(ctx_state, ctx_prompt_value)
            self.sm.add_state(context_ctx_state)

            # Create paths
            system_to_ctx = Path(system_ctx_state, context_ctx_state,
                                 'changeto context {}'.format(ctx), None)
            ctx_to_system = Path(context_ctx_state, system_ctx_state, 'exit',
                                 None)

            # Add paths
            self.sm.add_path(system_to_ctx)
            self.sm.add_path(ctx_to_system)
コード例 #24
0
 def define_security_module_level_states(self):
     available_slots = self.get_available_slots()
     for slot in available_slots:
         state_name = 'slot_' + slot + '_fpr_module_state'
         self.states_dict.update({
             state_name: State(state_name,
                               self.patterns.prompt.fpr_module_prompt)
         })
コード例 #25
0
    def create(self):
        # Create States and their state patterns
        prelogin_state = State('prelogin_state',
                               self.patterns.prompt.prelogin_prompt)
        fireos_state = State('fireos_state',
                             self.patterns.prompt.fireos_prompt)
        expert_state = State('expert_state',
                             self.patterns.prompt.expert_prompt)
        sudo_state = State('sudo_state', self.patterns.prompt.sudo_prompt)
        eula_state = State('eula_state', self.patterns.prompt.eula_prompt)
        firstboot_state = State('firstboot_state',
                                self.patterns.prompt.firstboot_prompt)
        liloboot_state = State('liloboot_state',
                               self.patterns.prompt.lilo_boot_prompt)
        liloos_state = State('lilos_state',
                             self.patterns.prompt.lilo_os_prompt)
        lilo_boot_menu_state = State(
            'lilobootmenu_state', self.patterns.prompt.lilo_boot_menu_prompt)

        # Add states
        self.add_state(prelogin_state)
        self.add_state(fireos_state)
        self.add_state(expert_state)
        self.add_state(sudo_state)
        self.add_state(eula_state)
        self.add_state(firstboot_state)
        self.add_state(liloboot_state)
        self.add_state(liloos_state)
        self.add_state(lilo_boot_menu_state)

        # Create paths
        fireos_to_expert_path = Path(fireos_state, expert_state, 'expert',
                                     None)
        expert_to_fireos_path = Path(expert_state, fireos_state, 'exit', None)
        expert_to_sudo_path = Path(
            expert_state, sudo_state, 'sudo su -',
            Dialog([self.statements.sudo_password_statement]))
        sudo_to_expert_path = Path(sudo_state, expert_state, 'exit', None)
        prelogin_to_fireos = Path(
            prelogin_state, fireos_state, 'admin',
            Dialog([self.statements.login_password_statement]))
        fireos_to_prelogin = Path(fireos_state, prelogin_state, 'exit', None)

        # Add paths
        self.add_path(fireos_to_expert_path)
        self.add_path(expert_to_fireos_path)
        self.add_path(expert_to_sudo_path)
        self.add_path(sudo_to_expert_path)
        self.add_path(prelogin_to_fireos)
        self.add_path(fireos_to_prelogin)
コード例 #26
0
    def create(self):
        # Create States and their state patterns
        prelogin_state = State('prelogin_state', self.patterns.prompt.prelogin_prompt)
        mio_state = State('mio_state', self.patterns.prompt.mio_prompt)
        admin_state = State('admin_state', self.patterns.prompt.admin_prompt)
        sudo_state = State('sudo_state', self.patterns.prompt.sudo_prompt)
        fireos_state = State('fireos_state', self.patterns.prompt.fireos_prompt)
        liloboot_state = State('liloboot_state', self.patterns.prompt.lilo_boot_prompt)
        liloos_state = State('lilos_state', self.patterns.prompt.lilo_os_prompt)
        lilo_boot_menu_state = State('lilobootmenu_state', self.patterns.prompt.lilo_boot_menu_prompt)

        # Add our states to the state machine
        self.add_state(prelogin_state)
        self.add_state(mio_state)
        self.add_state(admin_state)
        self.add_state(sudo_state)
        self.add_state(fireos_state)
        self.add_state(liloboot_state)
        self.add_state(liloos_state)
        self.add_state(lilo_boot_menu_state)

        # Create paths for switching between states
        mio_to_admin = Path(mio_state,
                            admin_state,
                            "connect host",
                            self.dialogs.d_mio_to_admin)
        admin_to_sudo = Path(admin_state,
                             sudo_state,
                             "sudo su -",
                             self.dialogs.d_admin_to_sudo)
        sudo_to_admin = Path(sudo_state, admin_state, "exit", None)
        admin_to_mio = Path(admin_state, mio_state, "\030", None)
        prelogin_to_admin = Path(prelogin_state, admin_state, 'admin',
                                 Dialog([self.statements.login_password_statement]))

        admin_to_prelogin = Path(admin_state, prelogin_state, 'exit', None)

        # transitions from and to 'fireos_state' state
        fireos_to_admin_path = Path(fireos_state, admin_state, 'expert', None)
        admin_to_fireos_path = Path(admin_state, fireos_state, 'exit', None)
        fireos_to_prelogin = Path(fireos_state, prelogin_state, 'exit', None)

        # Add paths to the State Machine
        self.add_path(mio_to_admin)
        self.add_path(admin_to_sudo)
        self.add_path(sudo_to_admin)
        self.add_path(admin_to_mio)
        self.add_path(prelogin_to_admin)
        self.add_path(admin_to_prelogin)
        self.add_path(fireos_to_admin_path)
        self.add_path(admin_to_fireos_path)
        self.add_path(fireos_to_prelogin)

        # after inactivity timer, it will go back to prelogin:
        self.add_default_statements([self.statements.login_password, self.statements.login_incorrect])
コード例 #27
0
    def create(self):
        enable = State('enable', patterns.enable_prompt)
        config = State('config', patterns.config_prompt)
        shell = State('shell', patterns.shell_prompt)
        setup = State('setup', list(setup_patterns.__dict__.values()))

        self.add_state(enable)
        self.add_state(config)
        self.add_state(setup)
        self.add_state(shell)

        enable_to_config = Path(enable, config, 'configure', None)
        config_to_enable = Path(config, enable, 'end', None)

        self.add_path(enable_to_config)
        self.add_path(config_to_enable)

        self.add_default_statements(default_statement_list)
コード例 #28
0
    def create(self):
        super().create()

        # Remove standby_locked state
        self.remove_state('standby_locked')

        # Add RPR state
        rpr = State('rpr', patterns.rpr_state)
        self.add_state(rpr)
コード例 #29
0
    def create(self):
        """creates the generic state machine"""

        ##########################################################
        # State Definition
        ##########################################################

        enable = State('enable', patterns.enable_prompt)
        disable = State('disable', patterns.disable_prompt)
        config = State('config', patterns.config_prompt)
        rommon = State('rommon', patterns.rommon_prompt)

        ##########################################################
        # Path Definition
        ##########################################################

        enable_to_disable = Path(enable, disable, 'disable',
                                 Dialog([statements.syslog_msg_stmt]))
        enable_to_rommon = Path(enable, rommon, 'reload', None)
        enable_to_config = Path(enable, config, config_transition,
                                Dialog([statements.syslog_msg_stmt]))
        disable_to_enable = Path(
            disable, enable, 'enable',
            Dialog([
                statements.enable_password_stmt, statements.bad_password_stmt,
                statements.syslog_stripper_stmt
            ]))
        config_to_enable = Path(config, enable, 'end',
                                Dialog([statements.syslog_msg_stmt]))
        rommon_to_disable = Path(rommon, disable, 'boot',
                                 Dialog(authentication_statement_list))

        self.add_state(enable)
        self.add_state(config)
        self.add_state(disable)
        self.add_state(rommon)

        self.add_path(rommon_to_disable)
        self.add_path(disable_to_enable)
        self.add_path(enable_to_config)
        self.add_path(enable_to_rommon)
        self.add_path(config_to_enable)
        self.add_path(enable_to_disable)
        self.add_default_statements(default_statement_list)
コード例 #30
0
    def create(self):
        # Create States
        csp_enable_state = State(CspSmStates.CSP_ENABLE_STATE.value,
                                 self.patterns.prompt.enable_prompt)
        csp_config_state = State(CspSmStates.CSP_CONFIG_STATE.value,
                                 self.patterns.prompt.config_prompt)

        # Add states
        self.add_state(csp_enable_state)
        self.add_state(csp_config_state)

        enable_to_config_path = Path(csp_enable_state, csp_config_state,
                                     'config t', None)
        config_to_enable_path = Path(csp_config_state, csp_enable_state, 'end',
                                     None)

        # Add paths
        self.add_path(enable_to_config_path)
        self.add_path(config_to_enable_path)