Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Logging Per Request #64

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/unicon/plugins/aos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
Author: Alex Pfeil
Contact: www.linkedin.com/in/alex-p-352040a0
Contents largely inspired by sample Unicon repo, Knox Hutchinson and pyATS TEAM ([email protected], [email protected]):
https://github.com/CiscoDevNet/pyats-plugin-examples/tree/master/unicon_plugin_example/src/unicon_plugin_example
The order of operations is that the init file is accessed, then the connection_provider file makes the connection using the statements file,
and once the connection is established, the state machine is used. The settings file is where settings can be set. The service implementation file
and services file are where differnt services can be added to this plugin.
'''

from unicon.bases.routers.connection import BaseSingleRpConnection
from .connection_provider import aosSingleRpConnectionProvider
from unicon.plugins.aos.services import aosServiceList
from unicon.plugins.aos.settings import aosSettings
from .statemachine import aosSingleRpStateMachine

#Checking to see if this is necessary. I will most likely take this out.
def wait_and_send_yes(spawn):
time.sleep(0.2)
spawn.sendline('yes')

#This is the main class which calls in all of the other files.
class aosSingleRPConnection(BaseSingleRpConnection):
'''aosSingleRPConnection

This supports logging into an Aruba switch.
'''
os = 'aos'
chassis_type = 'single_rp'
state_machine_class = aosSingleRpStateMachine
connection_provider_class = aosSingleRpConnectionProvider
subcommand_list = aosServiceList
settings = aosSettings()

45 changes: 45 additions & 0 deletions src/unicon/plugins/aos/connection_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'''
Author: Alex Pfeil
Contact: www.linkedin.com/in/alex-p-352040a0
Contents largely inspired by sample Unicon repo, Knox Hutchinson and Cisco:
https://github.com/CiscoDevNet/pyats-plugin-examples/tree/master/unicon_plugin_example/src/unicon_plugin_example
'''
import time

from unicon.bases.routers.connection_provider import \
BaseSingleRpConnectionProvider
from unicon.eal.dialogs import Dialog
from unicon.plugins.aos.statements import (aosConnection_statement_list)
from unicon.plugins.generic.statements import custom_auth_statements
import getpass

#This is the aos Connection Provider It is called in the __init__.py file.
class aosSingleRpConnectionProvider(BaseSingleRpConnectionProvider):
""" Implements Junos singleRP Connection Provider,
This class overrides the base class with the
additional dialogs and steps required for
connecting to any device via generic implementation
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

#This funciton must be member of aosSingleRpConnectionProvider
def get_connection_dialog(self):
con = self.connection
custom_auth_stmt = custom_auth_statements(
self.connection.settings.LOGIN_PROMPT,
self.connection.settings.PASSWORD_PROMPT)
return con.connect_reply + \
Dialog(custom_auth_stmt + aosConnection_statement_list
if custom_auth_stmt else aosConnection_statement_list)

def set_init_commands(self):
con = self.connection
if con.init_exec_commands is not None:
self.init_exec_commands = con.init_exec_commands
self.init_config_commands = con.init_exec_commands
else:
self.init_exec_commands = [
'terminal length 1000',
'terminal width 1000']
self.init_config_commands = []
28 changes: 28 additions & 0 deletions src/unicon/plugins/aos/patterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'''
Author: Alex Pfeil
Contact: www.linkedin.com/in/alex-p-352040a0
Contents largely inspired by sample Unicon repo, Knox Hutchinson and pyATS TEAM ([email protected], [email protected]):
https://github.com/CiscoDevNet/pyats-plugin-examples/tree/master/unicon_plugin_example/src/unicon_plugin_example
'''

#This imports the UniconCorePatterns.
from unicon.patterns import UniconCorePatterns

#Patterns to match different expect statements
class aosPatterns(UniconCorePatterns):
def __init__(self):
super().__init__()
self.login_prompt = r'^.*[Ll]ogin as( for )?(\\S+)?: ?$'
self.password_prompt = r'^.*[Pp]assword( for )?(\\S+)?: ?$'
self.enable_prompt = r'.*>'
self.config_mode = r'.*config.#'
self.password = r'.*ssword:$'
self.executive_prompt = r'.*#$'
self.executive_login = r'.*#.*'
self.config_prompt = r'.*config.*#'
self.proxy = r'.*rhome.*'
self.press_any_key = r'.*any key to conti.*'
self.continue_connecting = r'Are you sure you want to continue connecting (yes/no)?'
self.ssh_key_check = r'.*yes/no/[fingerprint]'
self.start = r'.*These computing resources are solely owned by the Company. Unauthorized\r\naccess, use or modification is a violation of law and could result in\r\ncriminal prosecution. Users agree not to disclose any company information\r\nexcept as authorized by the Company. Your use of the Company computing\r\nresources is consent to be monitored and authorization to search your\r\ncomputer or device to assure compliance with company policies and/or the law.*'
self.learn_os_prompt = r'^(.*?([>\$~%]|[^#\s]#|~ #|~/|^admin:|^#)\s?(\x1b\S+)?)$|(^.*This \(D\)RP Node is not ready or active for login \/configuration.*)'
26 changes: 26 additions & 0 deletions src/unicon/plugins/aos/service_implementation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'''
Author: Alex Pfeil
Contact: www.linkedin.com/in/alex-p-352040a0
Contents largely inspired by sample Unicon repo, Knox Hutchinson and pyATS TEAM ([email protected], [email protected]):
https://github.com/CiscoDevNet/pyats-plugin-examples/tree/master/unicon_plugin_example/src/unicon_plugin_example
'''
#This portion of the script is still a work in progress.
import io
import re
import collections
import warnings

from time import sleep
from datetime import datetime, timedelta

from unicon.core.errors import TimeoutError
from unicon.settings import Settings
from .patterns import aosPatterns

patterns = aosPatterns()
settings = Settings()


def __init__(self, connection, context, **kwargs):
self.start_state = 'exec'
self.end_state = 'exec'
32 changes: 32 additions & 0 deletions src/unicon/plugins/aos/services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'''
Author: Alex Pfeil
Contact: www.linkedin.com/in/alex-p-352040a0
Contents largely inspired by sample Unicon repo, Knox Hutchinson and pyATS TEAM ([email protected], [email protected]):
https://github.com/CiscoDevNet/pyats-plugin-examples/tree/master/unicon_plugin_example/src/unicon_plugin_example
'''
from unicon.plugins.generic.service_implementation import Execute as GenericExec
from unicon.plugins.ios.iosv import IosvServiceList



class Execute(GenericExec):
'''
Demonstrating how to augment an existing service by updating its call
service method
'''
def call_service(self, *args, **kwargs):
# custom... code here

# call parent
super().call_service(*args, **kwargs)

class aosServiceList(IosvServiceList):
'''
class aggregating all service lists for this platform
'''
def __init__(self):
# use the parent servies
super().__init__()
# overwrite and add our own
self.execute = Execute

23 changes: 23 additions & 0 deletions src/unicon/plugins/aos/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'''
Author: Alex Pfeil
Contact: www.linkedin.com/in/alex-p-352040a0
Contents largely inspired by sample Unicon repo and Knox Hutchinson:
https://github.com/CiscoDevNet/pyats-plugin-examples/tree/master/unicon_plugin_example/src/unicon_plugin_example
'''

from unicon.plugins.generic import GenericSettings
#This enables logging in the script.

from unicon.plugins.generic.settings import GenericSettings

class aosSettings(GenericSettings):
def __init__(self):
# inherit any parent settings
super().__init__()
self.CONNECTION_TIMEOUT = 60
self.EXPECT_TIMEOUT = 60
self.ESCAPE_CHAR_CALLBACK_PRE_SENDLINE_PAUSE_SEC = 3
self.HA_INIT_EXEC_COMMANDS = []
self.HA_INIT_CONFIG_COMMANDS = []
self.CONSOLE_TIMEOUT = 60
self.ATTACH_CONSOLE_DISABLE_SLEEP = 100
51 changes: 51 additions & 0 deletions src/unicon/plugins/aos/statemachine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'''
Author: Alex Pfeil
Contact: www.linkedin.com/in/alex-p-352040a0
Contents largely inspired by sample Unicon repo and Knox Hutchinson and Cisco Development Team:
https://github.com/CiscoDevNet/pyats-plugin-examples/tree/master/unicon_plugin_example/src/unicon_plugin_example
'''

from unicon.statemachine import State, Path
from .patterns import aosPatterns
from unicon.plugins.generic.statemachine import GenericSingleRpStateMachine
from unicon.plugins.generic.statements import default_statement_list
patterns=aosPatterns()
class aosSingleRpStateMachine(GenericSingleRpStateMachine):
def create(self):
'''
statemachine class's create() method is its entrypoint. This showcases
how to setup a statemachine in Unicon.
'''
##########################################################
# State Definition
##########################################################
basic_prompt = State('basic_prompt', r'.*>')
config = State('config', r'.*config.*#')
enable = State('enable', r'.*#')

##########################################################
# Path Definition
##########################################################
enable_to_basic_prompt = Path(enable, basic_prompt, 'exit', None)
basic_prompt_to_enable = Path(basic_prompt, enable, 'enable', None)
enable_to_config = Path(enable, config, 'configure terminal', None)
config_to_enable = Path(config, enable, 'exit', None)


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


self.add_path(enable_to_basic_prompt)
self.add_path(basic_prompt_to_enable)
self.add_path(enable_to_config)
self.add_path(config_to_enable)

#self.add_path(proxy_to_shell)
#self.add_path(shell_to_proxy)
self.add_default_statements(default_statement_list)
def learn_os_state(self):
learn_os = State('learn_os', patterns.learn_os_prompt)
self.add_state(learn_os)
Loading