def init(opts=None): ''' Required. Can be used to initialize the server connection. ''' if opts is None: opts = __opts__ try: this_prompt = None if 'prompt_regex' in opts['proxy']: this_prompt = opts['proxy']['prompt_regex'] elif 'prompt_name' in opts['proxy']: this_prompt = '{0}.*#'.format(opts['proxy']['prompt_name']) else: log.warning( 'nxos proxy configuration does not specify a prompt match.') this_prompt = '.+#$' DETAILS[_worker_name()] = SSHConnection( host=opts['proxy']['host'], username=opts['proxy']['username'], password=opts['proxy']['password'], key_accept=opts['proxy'].get('key_accept', False), ssh_args=opts['proxy'].get('ssh_args', ''), prompt=this_prompt) out, err = DETAILS[_worker_name()].sendline('terminal length 0') except TerminalException as e: log.error(e) return False DETAILS['initialized'] = True
def _init_ssh(opts): ''' Open a connection to the NX-OS switch over SSH. ''' if opts is None: opts = __opts__ try: this_prompt = None if 'prompt_regex' in opts['proxy']: this_prompt = opts['proxy']['prompt_regex'] elif 'prompt_name' in opts['proxy']: this_prompt = '{0}.*#'.format(opts['proxy']['prompt_name']) else: log.warning( 'nxos proxy configuration does not specify a prompt match.') this_prompt = '.+#$' DEVICE_DETAILS[_worker_name()] = SSHConnection( host=opts['proxy']['host'], username=opts['proxy']['username'], password=opts['proxy']['password'], key_accept=opts['proxy'].get('key_accept', False), ssh_args=opts['proxy'].get('ssh_args', ''), prompt=this_prompt) out, err = DEVICE_DETAILS[_worker_name()].sendline('terminal length 0') log.info('SSH session establised for process {}'.format( _worker_name())) except TerminalException as e: log.error(e) return False DEVICE_DETAILS['initialized'] = True DEVICE_DETAILS['no_save_config'] = opts['proxy'].get( 'no_save_config', False)
def init(opts=None): """ Required. Can be used to initialize the server connection. """ if opts is None: opts = __opts__ try: this_prompt = None if "prompt_regex" in opts["proxy"]: this_prompt = opts["proxy"]["prompt_regex"] elif "prompt_name" in opts["proxy"]: this_prompt = "{0}.*#".format(opts["proxy"]["prompt_name"]) else: log.warning( "nxos proxy configuration does not specify a prompt match.") this_prompt = ".+#$" DETAILS[_worker_name()] = SSHConnection( host=opts["proxy"]["host"], username=opts["proxy"]["username"], password=opts["proxy"]["password"], key_accept=opts["proxy"].get("key_accept", False), ssh_args=opts["proxy"].get("ssh_args", ""), prompt=this_prompt, ) out, err = DETAILS[_worker_name()].sendline("terminal length 0") except TerminalException as e: log.error(e) return False DETAILS["initialized"] = True
def init(opts): ''' Required. Can be used to initialize the server connection. ''' try: DETAILS['server'] = SSHConnection( host=__opts__['proxy']['host'], username=__opts__['proxy']['username'], password=__opts__['proxy']['password']) out, err = DETAILS['server'].sendline('help') except TerminalException as e: log.error(e) return False
def init(opts): """ Required. Can be used to initialize the server connection. """ try: DETAILS["server"] = SSHConnection( host=__opts__["proxy"]["host"], username=__opts__["proxy"]["username"], password=__opts__["proxy"]["password"], ) out, err = DETAILS["server"].sendline("help") DETAILS["initialized"] = True except TerminalException as e: log.error(e) return False
def init(opts): ''' Required. Can be used to initialize the server connection. ''' DETAILS['initialized'] = True try: DETAILS[_worker_name()] = SSHConnection( host=opts['proxy']['host'], username=opts['proxy']['username'], password=opts['proxy']['password'], key_accept=opts['proxy'].get('key_accept', False), ssh_args=opts['proxy'].get('ssh_args', ''), prompt='{0}.*#'.format(opts['proxy']['prompt_name'])) out, err = DETAILS[_worker_name()].sendline('terminal length 0') except TerminalException as e: log.error(e) return False
def init(opts=None): ''' Required. Can be used to initialize the server connection. ''' if opts is None: opts = __opts__ try: DETAILS[_worker_name()] = SSHConnection( host=opts['proxy']['host'], username=opts['proxy']['username'], password=opts['proxy']['password'], key_accept=opts['proxy'].get('key_accept', False), ssh_args=opts['proxy'].get('ssh_args', ''), prompt='{0}.*(#|>) '.format(opts['proxy']['prompt_name'])) DETAILS[_worker_name()].sendline('no cli session paging enable') except TerminalException as e: log.error(e) return False DETAILS['initialized'] = True
def _init_ssh(opts=None): """ Open a connection to the NX-OS switch over SSH. """ if opts is None: opts = __opts__ try: this_prompt = None if "prompt_regex" in opts["proxy"]: this_prompt = opts["proxy"]["prompt_regex"] elif "prompt_name" in opts["proxy"]: this_prompt = "{0}.*#".format(opts["proxy"]["prompt_name"]) else: log.warning( "nxos proxy configuration does not specify a prompt match.") this_prompt = ".+#$" DEVICE_DETAILS[_worker_name()] = SSHConnection( host=opts["proxy"]["host"], username=opts["proxy"]["username"], password=opts["proxy"]["password"], key_accept=opts["proxy"].get("key_accept", False), ssh_args=opts["proxy"].get("ssh_args", ""), prompt=this_prompt, ) out, err = DEVICE_DETAILS[_worker_name()].sendline("terminal length 0") log.info("SSH session establised for process {}".format( _worker_name())) except Exception as ex: # pylint: disable=broad-except log.error("Unable to connect to %s", opts["proxy"]["host"]) log.error("Please check the following:\n") log.error( '-- Verify that "feature ssh" is enabled on your NX-OS device: %s', opts["proxy"]["host"], ) log.error("-- Exception Generated: %s", ex) log.error(ex) raise DEVICE_DETAILS["initialized"] = True DEVICE_DETAILS["save_config"] = opts["proxy"].get("save_config", True)
def _init_ssh(opts): ''' Open a connection to the NX-OS switch over SSH. ''' if opts is None: opts = __opts__ try: this_prompt = None if 'prompt_regex' in opts['proxy']: this_prompt = opts['proxy']['prompt_regex'] elif 'prompt_name' in opts['proxy']: this_prompt = '{0}.*#'.format(opts['proxy']['prompt_name']) else: log.warning( 'nxos proxy configuration does not specify a prompt match.') this_prompt = '.+#$' DEVICE_DETAILS[_worker_name()] = SSHConnection( host=opts['proxy']['host'], username=opts['proxy']['username'], password=opts['proxy']['password'], key_accept=opts['proxy'].get('key_accept', False), ssh_args=opts['proxy'].get('ssh_args', ''), prompt=this_prompt) out, err = DEVICE_DETAILS[_worker_name()].sendline('terminal length 0') log.info('SSH session establised for process {}'.format( _worker_name())) except Exception as ex: log.error('Unable to connect to %s', opts['proxy']['host']) log.error('Please check the following:\n') log.error( '-- Verify that "feature ssh" is enabled on your NX-OS device: %s', opts['proxy']['host']) log.error('-- Exception Generated: %s', ex) log.error(ex) exit() DEVICE_DETAILS['initialized'] = True DEVICE_DETAILS['no_save_config'] = opts['proxy'].get( 'no_save_config', False)
def init(opts): ''' Required. Can be used to initialize the server connection. ''' if opts is None: opts = __opts__ try: DETAILS['server'] = SSHConnection( host=opts['proxy']['host'], username=opts['proxy']['username'], password=opts['proxy']['password'], key_accept=opts['proxy'].get('key_accept', False), ssh_args=opts['proxy'].get('ssh_args', ''), prompt='.+[#$]') log.info('SSH Connection established.') out, err = DETAILS['server'].sendline('id') DETAILS['initialized'] = True except TerminalException as e: log.error(e) return False