from unicon.eal.dialogs import Statement from unicon.eal.helpers import sendline from unicon.core.errors import UniconAuthenticationError from unicon.utils import Utils from unicon.plugins.generic.patterns import GenericPatterns from unicon.plugins.utils import ( get_current_credential, common_cred_username_handler, common_cred_password_handler, ) from unicon.utils import to_plaintext from unicon.bases.routers.connection import ENABLE_CRED_NAME pat = GenericPatterns() utils = Utils() ############################################################# # Callbacks ############################################################# def connection_refused_handler(spawn): """ handles connection refused scenarios """ raise Exception('Connection refused to device %s' % (str(spawn))) def connection_failure_handler(spawn): raise Exception('received disconnect from router %s' % (str(spawn)))
import re from unicon.statemachine import State, Path, StateMachine from unicon.eal.dialogs import Dialog, Statement from unicon.core.errors import StateMachineError from unicon.utils import AttributeDict from unicon.plugins.generic.statements import GenericStatements, sudo_password_handler, update_context from unicon.plugins.generic.patterns import GenericPatterns from .patterns import FxosPatterns from .statements import fxos_statements, default_statement_list, boot_wait, boot_to_rommon_statements patterns = FxosPatterns() generic_statements = GenericStatements() generic_patterns = GenericPatterns() def change_fxos_scope(state_machine, spawn, context): scopes = [s for s in context.get('_scope', "").split('/') if s] for scope in scopes: spawn.sendline("scope %s" % scope) spawn.expect(state_machine.get_state('fxos_scope').pattern, trim_buffer=False) def sudo_failed(): raise Exception('sudo failed') def send_ctrl_a_d(state_machine, spawn, context):