def set_attribute_value(self, cs_address, attribute_name, attribute_value): """ Set attribute value to the device :param cs_address: address, '192.168.42.240/1/21' :type cs_address: str :param attribute_name: attribute name, "Port Speed" :type attribute_name: str :param attribute_value: value, "10000" :type attribute_value: str :return: attribute value :rtype: cloudshell.layer_one.core.response.response_info.AttributeValueResponseInfo :raises Exception: if command failed """ address = Address.from_cs_address(cs_address) if address.is_chassis() or address.is_slot(): raise LayerOneDriverException( self.__class__.__name__, 'SetAttributeValue for Chassis or Slot/Blade is not supported') else: attribute_setter = self._ports_attributes_setters.get( attribute_name) if attribute_setter: attribute_setter(address, attribute_value) else: raise LayerOneDriverException( self.__class__.__name__, 'SetAttributeValue is not supported for attribute {}'. format(attribute_name)) return AttributeValueResponseInfo(attribute_value)
def set_attribute_value(self, cs_address, attribute_name, attribute_value): """ Set attribute value to the device :param cs_address: address, '192.168.42.240/1/21' :type cs_address: str :param attribute_name: attribute name, "Port Speed" :type attribute_name: str :param attribute_value: value, "10000" :type attribute_value: str :return: attribute value :rtype: cloudshell.layer_one.core.response.response_info.AttributeValueResponseInfo :raises Exception: if command failed Example: with self._cli_handler.config_mode_service() as session: command = AttributeCommandFactory.set_attribute_command(cs_address, attribute_name, attribute_value) session.send_command(command) return AttributeValueResponseInfo(attribute_value) """ if attribute_name == 'Auto Negotiation': with self._cli_handler.default_mode_service() as session: with ActionsManager(self._system_actions, session) as system_actions: system_actions.set_auto_negotiation( self._convert_port_address(cs_address), attribute_value) else: raise LayerOneDriverException( self.__class__.__name__, 'SetAttributeValue for address {} is not supported'.format( cs_address))
def get_attribute_value(self, cs_address, attribute_name): """ Retrieve attribute value from the device :param cs_address: address, '192.168.42.240/1/21' :type cs_address: str :param attribute_name: attribute name, "Port Speed" :type attribute_name: str :return: attribute value :rtype: cloudshell.layer_one.core.response.response_info.AttributeValueResponseInfo :raises Exception: if command failed Example: with self._cli_handler.config_mode_service() as session: command = AttributeCommandFactory.get_attribute_command(cs_address, attribute_name) value = session.send_command(command) return AttributeValueResponseInfo(value) """ if attribute_name == 'Serial Number': if len(cs_address.split('/')) == 1: with self._cli_handler.default_mode_service() as session: autoload_actions = AutoloadActions(session, self._logger) board_table = autoload_actions.board_table() return AttributeValueResponseInfo( board_table.get('chassis-serial')) else: return AttributeValueResponseInfo('NA') else: raise LayerOneDriverException( self.__class__.__name__, 'GetAttributeValue command is not supported')
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)
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 _snmp_handler_factory(self): """ SNMP handler factory :return: :rtype: simpler_networks.snmp.snmp_handler_factory.SnmpHandlerFactory """ if self.__snmp_handler_factory: return self.__snmp_handler_factory raise LayerOneDriverException( self.__class__.__name__, 'SNMP factory called before initialization')
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_attribute_value(self, cs_address, attribute_name): """ Retrieve attribute value from the device :param cs_address: address, '192.168.42.240/1/21' :type cs_address: str :param attribute_name: attribute name, "Port Speed" :type attribute_name: str :return: attribute value :rtype: cloudshell.layer_one.core.response.response_info.AttributeValueResponseInfo :raises Exception: if command failed Example: value = self._attribute_flow.get(cs_address, attribute_name) return AttributeValueResponseInfo(value) """ raise LayerOneDriverException( self.__class__.__name__, 'GetAttributeValue command is not supported')