def run_driver(self, driver_name):
        # Reading runtime configuration
        runtime_config = RuntimeConfiguration(
            os.path.join(self._driver_path, driver_name + '_runtime_config.yml'))

        # Creating XMl logger instance
        xml_file_name = driver_name + '--' + datetime.now().strftime('%d-%b-%Y--%H-%M-%S') + '.xml'
        xml_logger = XMLLogger(os.path.join(self._log_path, driver_name, xml_file_name))

        # Creating command logger instance
        command_logger = get_qs_logger(log_group=driver_name,
                                       log_file_prefix=driver_name + '_commands', log_category='COMMANDS')
        log_level = runtime_config.read_key('LOGGING.LEVEL', 'INFO')
        command_logger.setLevel(log_level)

        command_logger.info('Starting driver {0} on port {1}, PID: {2}'.format(driver_name, self._port, os.getpid()))

        # Importing and creating driver commands instance
        driver_commands = importlib.import_module('{}.driver_commands'.format(driver_name), package=None)
        driver_instance = driver_commands.DriverCommands(command_logger, runtime_config)

        # Creating command executor instance
        command_executor = CommandExecutor(driver_instance, command_logger)

        # Creating listener instance
        server = DriverListener(command_executor, xml_logger, command_logger)

        # Start listening
        server.start_listening(port=self._port)
예제 #2
0
 def __init__(self, host, logger):
     self._logger = logger
     self._snmp_handler = self._init_snmp_handler(
         ReadWriteSNMPV2Parameters(
             host,
             RuntimeConfiguration().read_key('SNMP.READ_COMMUNITY'),
             RuntimeConfiguration().read_key('SNMP.WRITE_COMMUNITY')))
    def __init__(self, logger):
        self._logger = logger
        self._cli = CLI(session_pool=SessionPoolManager(max_pool_size=1))
        self._defined_session_types = {
            'SSH': SSHSession,
            'TELNET': FiberzoneTelnetSession
        }

        self._session_types = RuntimeConfiguration().read_key(
            'CLI.TYPE') or self._defined_session_types.keys()
        self._ports = RuntimeConfiguration().read_key('CLI.PORTS')

        self._host = None
        self._username = None
        self._password = None
예제 #4
0
    def __init__(self, logger):
        self._logger = logger
        self._cli = CLI(session_pool=SessionPoolManager(max_pool_size=1))
        self._defined_session_types = {
            "SSH": RomeSSHSession,
            "TELNET": RomeTelnetSession,
        }

        self._session_types = (RuntimeConfiguration().read_key("CLI.TYPE")
                               or self._defined_session_types.keys())
        self._ports = RuntimeConfiguration().read_key("CLI.PORTS")

        self._host = None
        self._username = None
        self._password = None
    def __init__(self, logger):
        self._logger = logger
        self._cli = CLI(session_pool=SessionPoolManager(max_pool_size=1))
        self.modes = CommandModeHelper.create_command_mode()
        self._defined_session_types = {
            'SSH': VWSSHSession,
            'TELNET': TelnetSession
        }

        self._session_types = RuntimeConfiguration().read_key(
            'CLI.TYPE', ['SSH']) or self._defined_session_types.keys()
        self._ports = RuntimeConfiguration().read_key('CLI.PORTS', '22')

        self._host = None
        self._username = None
        self._password = None
예제 #6
0
    def __init__(self, logger, runtime_config):
        """
        :param logger:
        :param cloudshell.layer_one.core.helper.runtime_configuration.RuntimeConfiguration runtime_config:
        """
        self._logger = logger
        self._runtime_config = runtime_config
        self._cli = CLI(session_pool=SessionPoolManager(max_pool_size=1))
        self.modes = CommandModeHelper.create_command_mode()
        self._defined_session_types = {
            VWSSHSession.SESSION_TYPE: VWSSHSession,
            TelnetSession.SESSION_TYPE: TelnetSession
        }

        self._session_types = self._runtime_config.read_key(
            'CLI.TYPE',
            [VWSSHSession.SESSION_TYPE]) or self._defined_session_types.keys()
        self._ports = RuntimeConfiguration().read_key('CLI.PORTS', {})

        self._host = None
        self._username = None
        self._password = None
예제 #7
0
class L1CliHandler(object):
    def __init__(self, logger):
        self._logger = logger
        self._cli = CLI(session_pool=SessionPoolManager(max_pool_size=1))
        self._defined_session_types = {
            "SSH": RomeSSHSession,
            "TELNET": RomeTelnetSession,
        }

        self._session_types = (RuntimeConfiguration().read_key("CLI.TYPE")
                               or self._defined_session_types.keys())
        self._ports = RuntimeConfiguration().read_key("CLI.PORTS")

        self._host = None
        self._username = None
        self._password = None

    def _new_sessions(self):
        sessions = []
        for session_type in self._session_types:
            session_class = self._defined_session_types.get(session_type)
            if not session_class:
                raise LayerOneDriverException(
                    self.__class__.__name__,
                    "Session type {} is not defined".format(session_type),
                )
            port = self._ports.get(session_type)
            sessions.append(
                session_class(self._host, self._username, self._password,
                              port))
        return sessions

    def define_session_attributes(self, address, username, password):
        """Define session attributes."""
        address_list = address.split(":")
        if len(address_list) > 1:
            raise LayerOneDriverException(self.__class__.__name__,
                                          "Incorrect resource address")
        self._host = address
        self._username = username
        self._password = password

    def get_cli_service(self, command_mode):
        """Create new cli service or get it from pool."""
        if not self._host or not self._username or not self._password:
            raise LayerOneDriverException(
                self.__class__.__name__,
                "Cli Attributes is not defined, call Login command first",
            )
        return self._cli.get_session(self._new_sessions(), command_mode,
                                     self._logger)
class L1CliHandler(object):
    def __init__(self, logger):
        self._logger = logger
        self._cli = CLI(session_pool=SessionPoolManager(max_pool_size=1))
        self._defined_session_types = {
            'SSH': SSHSession,
            'TELNET': FiberzoneTelnetSession
        }

        self._session_types = RuntimeConfiguration().read_key(
            'CLI.TYPE') or self._defined_session_types.keys()
        self._ports = RuntimeConfiguration().read_key('CLI.PORTS')

        self._host = None
        self._username = None
        self._password = None

    def _new_sessions(self):
        sessions = []
        for session_type in self._session_types:
            session_class = self._defined_session_types.get(session_type)
            if not session_class:
                raise LayerOneDriverException(
                    self.__class__.__name__,
                    'Session type {} is not defined'.format(session_type))
            port = self._ports.get(session_type)
            sessions.append(
                session_class(self._host, self._username, self._password,
                              port))
        return sessions

    def define_session_attributes(self, address, username, password):
        """
        Define session attributes
        :param address: 
        :type address: str
        :param username: 
        :param password: 
        :return: 
        """

        address_list = address.split(':')
        if len(address_list) > 1:
            raise LayerOneDriverException(self.__class__.__name__,
                                          'Incorrect resource address')
        self._host = address
        self._username = username
        self._password = password

    def get_cli_service(self, command_mode):
        """
        Create new cli service or get it from pool
        :param command_mode: 
        :return: 
        """
        if not self._host or not self._username or not self._password:
            raise LayerOneDriverException(
                self.__class__.__name__,
                "Cli Attributes is not defined, call Login command first")
        return self._cli.get_session(self._new_sessions(), command_mode,
                                     self._logger)
예제 #9
0
class VWCliHandler(object):
    def __init__(self, logger, runtime_config):
        """
        :param logger:
        :param cloudshell.layer_one.core.helper.runtime_configuration.RuntimeConfiguration runtime_config:
        """
        self._logger = logger
        self._runtime_config = runtime_config
        self._cli = CLI(session_pool=SessionPoolManager(max_pool_size=1))
        self.modes = CommandModeHelper.create_command_mode()
        self._defined_session_types = {
            VWSSHSession.SESSION_TYPE: VWSSHSession,
            TelnetSession.SESSION_TYPE: TelnetSession
        }

        self._session_types = self._runtime_config.read_key(
            'CLI.TYPE',
            [VWSSHSession.SESSION_TYPE]) or self._defined_session_types.keys()
        self._ports = RuntimeConfiguration().read_key('CLI.PORTS', {})

        self._host = None
        self._username = None
        self._password = None

    def _new_sessions(self):
        sessions = []
        for session_type in self._session_types:
            session_class = self._defined_session_types.get(session_type)
            if not session_class:
                raise LayerOneDriverException(
                    self.__class__.__name__,
                    'Session type {} is not defined'.format(session_type))
            port = self._ports.get(session_type)
            sessions.append(
                session_class(self._host, self._username, self._password,
                              port))
        return sessions

    def define_session_attributes(self, address, username, password):
        """
        Define session attributes
        :param address: 
        :type address: str
        :param username: 
        :param password: 
        :return: 
        """

        address_list = address.split(':')
        if len(address_list) > 1:
            raise LayerOneDriverException(self.__class__.__name__,
                                          'Incorrect resource address')
        self._host = address
        self._username = username
        self._password = password
        self._default_mode.set_credentials(username, password)

    def get_cli_service(self, command_mode):
        """
        Create new cli service or get it from pool
        :param command_mode: 
        :return: 
        """
        if not self._host or not self._username or not self._password:
            raise LayerOneDriverException(
                self.__class__.__name__,
                "Cli Attributes is not defined, call Login command first")
        return self._cli.get_session(self._new_sessions(), command_mode,
                                     self._logger)

    @property
    def _default_mode(self):
        """
        :rtype: DefaultCommandMode
        """
        return self.modes[DefaultCommandMode]

    def default_mode_service(self):
        """
        Default mode session
        :return:
        :rtype: cloudshell.cli.cli_service.CliService
        """
        return self.get_cli_service(self._default_mode)