Пример #1
0
    def delete_acl(self):
        """ Delete L3 Access Control List(ACL). 
        
        Attempt to delete L3-ACL which is already applied to the network interface raises exception.
        
        @raise OnepRemoteProcedureException: If error occurs when remote procedure call is made to network element.
        @raise OnepConnectionException: If connection to network element fails.
        """
        if self._acl_header:
            try:
                attached = self.get_applied_interfaces()
                for remove in attached:
                    self.log.debug('removing ACL from interface')
                    self.remove_from_interface(remove[0], remove[1])

                self.log.debug('Delete named ACL')
                self._acl_client.deleteNamedAcl_IDL(self._element.session_handle._id, self._acl_header.name, self._acl_handle, self._acl_header.lifetime, self._acl_header.addrFamily)
                self.log.info('Returned from deleteNamedAcl_IDL idl call to delete L3-acl')
            except ExceptionIDL as e:
                raise OnepRemoteProcedureException(e)
            except TException as e:
                raise OnepConnectionException(e.message, e)
        else:
            try:
                self.log.debug('Delete ACL')
                self._acl_client.deleteAcl_IDL(self._element.session_handle._id, self._acl_handle)
                self.log.info('Returned from deleteAcl_IDL idl call to delete L3-acl')
            except ExceptionIDL as e:
                raise OnepRemoteProcedureException(e)
            except TException as e:
                raise OnepConnectionException(e.message, e)
            if self in self._element._l3_acl_list:
                self._element._l3_acl_list.remove(self)
Пример #2
0
 def get_element_version(cls, element, ssName):
     """
     This method gets the Service Set version of the given Network Element.
     
     @param element: The Network Element to get the version from.
     @param ssName: Specifies the Service Set whose version is requested.
     @return:  Version object for the Service Set. If any of the input parameters  
             is null or unsupported, null will be returned.
     @raise OnepConnectionException:
                 The exception is thrown when the Network Element
                 is not connected.
     @raise OnepRemoteProcedureException:
                 The exception is thrown when an error has occurred in the remote
                 procedure call made to the Network Element.
     """
     if element == None or ssName == None:
         return
     if not element.is_connected():
         raise OnepConnectionException('network element is not connected')
     try:
         ver_idl = element.api_client.NetworkElement_getVersionIDL(
             element.session_handle._id, ssName)
         if ver_idl != None:
             return Version(ver_idl.major, ver_idl.minor, ver_idl.maint)
         raise OnepRemoteProcedureException()
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
Пример #3
0
 def fetch_session_attributes(self, retrieve_list = None):
     """ 
         Retrieves the attributes from a session record in database. 
         
         @param retrieve_list
             The retrieve_list specifies a list of Attribute to be retrieved. 
             If the optional retrieve_list is None or an empty list, 
             all attributes will be retrieved. 
             If the retrieve_list is not null, only a subset of 
             the attributes listed in the retrieveList will be retrieved.
                 
         @return the list of attributes retrieved.
     
         @throws OnepIllegalArgumentException
             The exception is thrown when any of input parameter is 
             invalid.
         @throws OnepConnectionException
             The exception is thrown when the network element 
             is not connected.
         @throws OnepRemoteProcedureException
             The exception is thrown when an error has 
             occurred in the remote procedure call made to the 
             network element.
         """
     if self._ne == None or self._ne.session_handle == None:
         raise OnepConnectionException()
     retrieve_id_list = Attribute.toIDLList(retrieve_list, self._ne)
     try:
         result_list = self._parent._identity_client.Sanet_Get_Attributes_IDL(self._ne.session_handle.id, self._session_label, retrieve_id_list)
         return result_list
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e.getCode(), e.getText(), e)
     except TException as e:
         raise OnepConnectionException(e.getMessage(), e)
Пример #4
0
    def find_session_by_attributes(self, match_list, retrieve_list = None):
        """
        Finds sessions matching the attributes specified in match_list. 
        The attributes associated with each of the found sessions will be
        retrieved and returned as the values of the dictionary.
        
        If the optional retrieve_list is None, all attributes will be retrieved. 
        If the retrieve_list is not null, only a subset of the attributes listed 
        in the retrieve_list will be retrieved. 
        
        @param match_list:
            The attributes and their corresponding values in the match_list 
            specifies the sessions that match these attributes.
        @param retrieve_list:
            The retrieve_list specifies a list of attribute to be retrieved. 
            If it is None or missing, all attributes will be retrieved; otherwise 
            only a subset of the attributes listed in the retrieve_list
            will be retrieved.
                    
        @return A dictionary that contains Identity sessions as keys and list of Attribute
            as corresponding values. 
                
        @throws OnepIllegalArgumentException
            The exception is thrown when any of input parameter is 
            invalid.
        @throws OnepConnectionException
            The exception is thrown when the network element 
            is not connected.
        @throws OnepRemoteProcedureException
            The exception is thrown when an error has 
            occurred in the remote procedure call made to the 
            network element.
        """
        if self._ne == None or self._ne.session_handle == None:
            raise OnepConnectionException()
        match_idl_list = Attribute.toIDLList(match_list, self._ne)
        if match_idl_list == None:
            match_idl_list = []
        retrieve_id_list = Attribute.toIDLList(retrieve_list, self._ne)
        try:
            if retrieve_list == None:
                ss_id_list = self._identity_client.Sanet_Find_By_Attributes_IDL(self._ne.session_handle.id, match_idl_list)
            else:
                ss_id_list = self._identity_client.Sanet_Find_By_Attributes_With_Reqd_List_IDL(self._ne.session_handle.id, match_idl_list, retrieve_id_list)
            if ss_id_list == None:
                return 
            else:
                ss_map = {}
                for ss_idl in ss_id_list:
                    if ss_idl == None:
                        continue
                    ss = IdentitySession(self, self._ne, ss_idl.sessionNum)
                    attr_list = _from_idl_list(ss_idl.attr_list, self._ne)
                    ss_map[ss] = attr_list

                return ss_map
        except ExceptionIDL as e:
            raise OnepRemoteProcedureException(e.getCode(), e.getText(), e)
        except TException as e:
            raise OnepConnectionException(e.getMessage(), e)
Пример #5
0
 def remove_from_interface(self, nif, nif_direction):
     """ Remove an ACl from the Interface.
         
         ACL is removed from network interface.
         
         @param nif: Network Interface instance.
         @type nif: L{NetworkInterface<onep.interfaces.NetworkInterface.NetworkInterface>}
         
         @param nif_direction: Direction Enum.
         @type nif_direction: L{Direction}
     
         @raise OnepIllegalArgumentException: If nif or directin is invalid.
         @raise OnepRemoteProcedureException: If error occurs when remote procedure call is made to network element.
         @raise OnepConnectionException: If connection to network element fails.
         """
     try:
         self._validate_nif_and_dir(nif, nif_direction)
         if self._acl_header:
             self._acl_client.removeNamedAclFromInterface_IDL(self._acl_header.name, self._acl_header.type, nif.xos_handle, nif_direction, self._acl_header.addrFamily)
         else:
             self._acl_client.removeAclFromInterface_IDL(self._acl_handle, nif.xos_handle, nif_direction)
         self.log.info('Returned from removeAclFromInterface_IDL idl call to remove acl to interface')
     except OnepIllegalArgumentException as e:
         raise e
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
     nif_tuple = (nif, self.Direction.enumval(nif_direction))
     if nif_tuple in self._nif_acl_info:
         self._nif_acl_info.remove(nif_tuple)
Пример #6
0
 def set_vlan_admin_state(self, id, shutdown):
     """
             Set VLAN adminstrative state
     
             @param id -- int - VLAN ID - range <1-4095>
     
             @param shutdown -- boolean (True is default)
     
             @raise OnepIllegalArgumentException:
             The exception is thrown when any of the arguments is invalid.
             @raise OnepConnectionException:
             The exception is thrown when the connection to a network element 
             has failed. 
             @raise OnepRemoteProcedureException:
             The exception is thrown when an error has occurred in the
             remote procedure call made to a network element.
     
             """
     self._validate_vlan(id)
     if not isinstance(shutdown, bool):
         raise OnepIllegalArgumentException('VLAN admin state is boolean')
     try:
         self.log.debug('vlan shutdown %s' % str(shutdown))
         self.client.setVlanAdminState_IDL(self.handle, id, int(shutdown))
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
Пример #7
0
 def __init__(self, element, lifetime):
     """ Constructor of class L2Acl.
     
             Instantiate a new L2 Access Control List(ACL).
     
             @param element: Network Element instance.
             @type element: L{NetworkElement<onep.element.NetworkElement.NetworkElement>}
     
             @param lifetime: Life time of L2 Acl.
             @type lifetime: L{OnepLifetime<OnepLifetime>}
     
             @raise OnepIllegalArgumentException: If element or lifetime is invalid.
             @raise OnepRemoteProcedureException: If error occurs when remote procedure call is made to network element.
             @raise OnepConnectionException: If connection to network element fails.
             """
     self.log = logging.getLogger('onep.' + __name__)
     super(L2Acl, self).__init__(element)
     try:
         self._validate_lifetime(lifetime)
     except OnepIllegalArgumentException as e:
         raise e
     self._l2_ace_list = list()
     self._lifetime = lifetime
     self._acl_client = Client(element.api_protocol)
     try:
         self._acl_handle = self._acl_client.createAcl_IDL(
             element.session_handle._id, self._ONEP_L2ACL, self._lifetime,
             0)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
     self._element._l2_acl_list.append(self)
Пример #8
0
 def create_vlan(self, vlan):
     """
             Create VLAN encapsulation ID
     
             @param vlan - dict
     
                    Keys    Values
                    ----    ------
                    id   -- int - VLAN ID - range <1-4095>
                    name -- string - VLAN name (maximum 64 characters) : Optional
     
             @raise OnepIllegalArgumentException:
             The exception is thrown when any of the arguments is invalid.
             @raise OnepConnectionException:
             The exception is thrown when the connection to a network element 
             has failed. 
             @raise OnepRemoteProcedureException:
             The exception is thrown when an error has occurred in the
             remote procedure call made to a network element.
     
             """
     validate(vlan, dict)
     self._validate_vlan(vlan['id'])
     name = ''
     if vlan.has_key('name') and vlan['name']:
         self._validate_vlan_name(vlan['name'])
         name = vlan['name']
     vlan_idl = VlanParam_IDL(vlan['id'], 0, name, 0, 0)
     try:
         self.log.debug(str(vlan_idl))
         self.client.createVlan_IDL(self.handle, vlan_idl)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
Пример #9
0
 def set_vlan_state(self, id, state):
     """
             Set VLAN state
     
             @param id -- int - VLAN ID - range <1-4095>
     
             @param state -- OnepConstants.VlanState
                                 ACTIVE (default)
                                 SUSPEND
     
             @raise OnepIllegalArgumentException:
             The exception is thrown when any of the arguments is invalid.
             @raise OnepConnectionException:
             The exception is thrown when the connection to a network element 
             has failed. 
             @raise OnepRemoteProcedureException:
             The exception is thrown when an error has occurred in the
             remote procedure call made to a network element.
     
             """
     self._validate_vlan(id)
     if state != OnepConstants.VlanState.ACTIVE and state != OnepConstants.VlanState.SUSPEND:
         raise OnepIllegalArgumentException('VLAN state invalid')
     try:
         self.log.debug('set vlan state %d' % state)
         self.client.setVlanState_IDL(self.handle, id, state)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
Пример #10
0
    def get_parser_state(self):
        """
                Returns the state of the parser after the last command interpretation.
        
                @raise OnepConnectionException:
                            The exception is thrown when the connection to a network element
                            has failed.
                @raise OnepRemoteProcedureException:
                            The exception is thrown when an error has occurred in the
                            remote procedure call made to a network element.
                @raise OnepException:
                            The exception is thrown when the server returns an invalid CPU
                            sampling interval value.
        
                @return: The parser state
        
                """
        if self.state == VtyService.OnepVtyState.ONEP_VTY_STATE_DISCONNECTED or self.state == VtyService.OnepVtyState.ONEP_VTY_STATE_IDLE_TIMEOUT:
            raise OnepConnectionException('VTY must be connected to retrieve parser state')
        try:
            execState = self.api_client.ExecutionCmd_stateGetIDL(self.element.session_handle._id, self.exec_handle)
            lst = []
            for result in execState.cmdResults:
                cmdIDL = self.CmdResults(result.inputLine, result.parseReturnCode, result.errorLocation)
                lst.append(cmdIDL)

            self.p_state = VtyService.ParserState(execState.prompt, execState.overallReturnCode, lst)
        except ExceptionIDL as e:
            raise OnepRemoteProcedureException(e)
        except TException as e:
            raise OnepConnectionException(e.message, e)
        return self.p_state
Пример #11
0
 def _add_to_l2_acl(self, acl):
     """
     """
     if self._acl != None:
         raise OnepIllegalArgumentException('ace is already added to acl')
     try:
         self._validate_sequence(self._sequence)
         self._validate_permit(self._permit)
         self._validate_mac(self._src_mac, 'Source')
         self._validate_mac_mask(self._src_mac_mask, 'Source')
         self._validate_mac(self._dst_mac, 'Destination')
         self._validate_mac_mask(self._dst_mac_mask, 'Destination')
     except OnepIllegalArgumentException as e:
         raise e
     self.log.info('Basic Validation of all L2-ace parameters completed.')
     self._acl = acl
     ace_param = L2AceParam_IDL(
         c_int(self._sequence).value, self._permit, self._src_mac,
         self._src_mac_mask, self._dst_mac, self._dst_mac_mask)
     self.log.info(
         'Successfully created L2-ace parameters through idl call L2AceParam_IDL'
     )
     try:
         self._ace_handle = acl._acl_client.addL2Ace_IDL(
             acl._acl_handle, ace_param)
         self.log.info(
             'Returned from addL2Ace_IDL idl call to add a L2-ace in L2-acl'
         )
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
Пример #12
0
 def __init__(self, element, type):
     """
             Construct a Topology object as seen by a protocol in an element.
     
             @param element: The NetworkElement from which to initiate the
             discovery of topology.
             @type element: L{NetworkElement<src.element.NetworkElement>}
             @param type: Type of topology as seen by a protocol
             @type type: L{int}
             @raise OnepIllegalArgumentException: The exception is thrown when
             element or type is not valid
             """
     if element == None:
         raise OnepIllegalArgumentException('element', 'invalid')
     if type == None:
         raise OnepIllegalArgumentException('type', 'invalid')
     validate(element, NetworkElement)
     validate(type, int)
     if type not in range(0, 567):
         raise OnepIllegalArgumentException('Invalid', 'type')
     self._network_element = element
     self._type = type
     TopologyClass._counter += 1
     self._key = TopologyClass._counter
     TopologyClass._topology_key_map = {}
     TopologyClass._topology_key_map[self._key] = self
     try:
         self.get_graph()
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e)
Пример #13
0
 def remove_interface_from_vlan(self, id, intf):
     """
             Remove VLAN encapsuation from an interface
     
             @param id -- int - VLAN ID - range <1-4095>
     
             @param intf -- NetworkInterface class
     
             @raise OnepIllegalArgumentException:
             The exception is thrown when any of the arguments is invalid.
             @raise OnepConnectionException:
             The exception is thrown when the connection to a network element 
             has failed. 
             @raise OnepRemoteProcedureException:
             The exception is thrown when an error has occurred in the
             remote procedure call made to a network element.
     
             """
     self._validate_vlan(id)
     if not hasattr(intf, 'xos_handle'):
         raise OnepIllegalArgumentException('not interface object')
     try:
         self.log.debug('remove %s from vlan %d' % (intf.name, id))
         self.client.removeIntfFromVlan_IDL(self.handle, intf.xos_handle,
                                            id)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
Пример #14
0
 def set_vlan_name(self, id, name):
     """
             Set VLAN name
     
             @param id -- int - VLAN ID - range <1-4095>
     
             @param name -- string VLAN text name
     
             @raise OnepIllegalArgumentException:
             The exception is thrown when any of the arguments is invalid.
             @raise OnepConnectionException:
             The exception is thrown when the connection to a network element 
             has failed. 
             @raise OnepRemoteProcedureException:
             The exception is thrown when an error has occurred in the
             remote procedure call made to a network element.
     
             """
     self._validate_vlan(id)
     self._validate_vlan_name(name)
     try:
         self.log.debug('set vlan name %s', name)
         self.client.setVlanName_IDL(self.handle, id, name)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
Пример #15
0
 def delete_session(self):
     """
     Deletes the session record from the database.
     
     @throws OnepIllegalArgumentException
         The exception is thrown when any of input parameter is 
         invalid.
     @throws OnepConnectionException
         The exception is thrown when the network element 
         is not connected.
     @throws OnepRemoteProcedureException
         The exception is thrown when an error has 
         occurred in the remote procedure call made to the 
         network element.
     """
     if self._ne == None or self._ne.session_handle() == None:
         raise OnepConnectionException()
     try:
         self._parent._identity_client.Sanet_Delete_Session_IDL(
             self._ne.session_handle.id, self._session_label)
         self._session_label = -1
         return
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e)
Пример #16
0
 def update_session_attributes(self, attr_list):
     """
          Updates the attributes of the session record in database. 
     
          The method will fail if the session record hasn't been created previously using 
          add_session(). Only the attributes passed in will be updated while retaining 
          the older values for other attributes, if any. 
          
          @param attr_list List of attributes that needed to be updated.
          
          @throws OnepIllegalArgumentException
              The exception is thrown when any of input parameter is 
              invalid.
          @throws OnepConnectionException
              The exception is thrown when the network element 
              is not connected.
          @throws OnepRemoteProcedureException
              The exception is thrown when an error has 
              occurred in the remote procedure call made to the 
              network element.        
          """
     if attr_list == None:
         raise OnepIllegalArgumentException('attr_list', 'null')
     if self._ne == None or self._ne.session_handle == None:
         raise OnepConnectionException()
     attr_idl_list = Attribute.toIDLList(attr_list, self._ne)
     try:
         self._parent._identity_client.Sanet_Set_Attributes_IDL(
             self._ne.session_handle.id, self._session_label, attr_idl_list,
             1)
         return
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e)
Пример #17
0
 def close(self):
     """
             Close a vty.
     
             @raise OnepConnectionException:
                         The exception is thrown when the connection to a network element
                         has failed.
             @raise OnepRemoteProcedureException:
                         The exception is thrown when an error has occurred in the
                         remote procedure call made to a network element.
             @raise OnepException:
                         The exception is thrown when the server returns an invalid CPU
                         sampling interval value.
     
             """
     if self.state == self.OnepVtyState.ONEP_VTY_STATE_DISCONNECTED or self.state == self.OnepVtyState.ONEP_VTY_STATE_IDLE_TIMEOUT:
         raise OnepException('VTY is already closed')
     try:
         self.api_client.ExecutionCmd_closeIDL(
             self.element.session_handle._id, self.exec_handle)
     except TException as e:
         raise OnepConnectionException(e.message, e)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     self.state = self.OnepVtyState.ONEP_VTY_STATE_DISCONNECTED
Пример #18
0
    def deactivate_policy(self, *activations):
        """
        De-activates the policy from its targets that are specified in the ActivationHolder list.
        
        @param activations: The activation holder.
        @type activations: List of L{ActivationHolder<onep.policyservice.bulk.ActivationHolder>}
        
        @raise OnepRemoteProcedureException: error when remote procedure call is made to network element.
        @raise OnepConnectionException: If connection to network element fails.        
        """
        try:
            activate_idl_list = list()
            policy_type = 0
            for activation in activations:
                self._check_element(activation._element)
                if isinstance(activation, ActivationHolder):
                    activation._op_code = PolicyMap.PolicyOperation.ONEP_POLICY_OP_DEACTIVATE
                    if policy_type and policy_type != activation._policy.capabilities.policy_type:
                        raise OnepIllegalArgumentException(
                            'Cannot deactivate policies with differing capabilities'
                        )
                    policy_type = activation._policy.capabilities.policy_type
                    activate_idl_list.append(activation._to_idl())

            self.log.info('deactivate_policy: activate_idl_list:%s',
                          str(activate_idl_list))
            self._class_client.Policy_submitPmapActivateIDL(
                self._session_id, policy_type, activate_idl_list)
            self.log.info('deactivate_policy executed with success.')
        except ExceptionIDL as e:
            raise OnepRemoteProcedureException(e)
        except TException as e:
            raise OnepConnectionException(e.message, e)
Пример #19
0
 def set_output_format(self, format):
     """
     Set the output format for vty
     This API can only be used before the vty is opened.
     It will raise an exception if vty is already open.
     
     @param format: The vty output format to be set on the network element
     @type format: L{OnepVtyOutputFormat<onep.vty.VtyService.OnepVtyOutputFormat>}
     @raise OnepConnectionException:
                 The exception is thrown when the connection to a network element
                 has failed.
     @raise OnepRemoteProcedureException:
                 The exception is thrown when an error has occurred in the
                 remote procedure call made to a network element.
     @raise OnepException:
                 The exception is thrown when the vty is already open and this 
                 API is called.
     """
     if not VtyService.OnepVtyOutputFormat._is_valid(format):
         raise OnepIllegalArgumentException("The input parameter 'format' is invalid.")
     if self.state is not self.OnepVtyState.ONEP_VTY_STATE_DISCONNECTED:
         raise OnepException('VTY is already open. Please, close it before changing the output format.')
     try:
         self.api_client.ExecutionCmd_setOutputFormatIDL(self.element.session_handle._id, self.exec_handle, format)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
Пример #20
0
 def add_replay_route_event_listener(self, listener, scope, client_data):
     """
     Adds a replay route event listener to the RIB object.
     
     @param listener: The ReplayRouteEventListener object that 
     handles the events. 
     @type listener: L{ReplayRouteEventListener<onep.routing.ReplayRouteEventListener>}
     
     @param scope: Indicate which table in the Application Route Table get
     notification from.
     @type scope: L{L3UnicastScope<onep.routing.L3UnicastScope>}
     
     @param client_data: The client data associated with the listener. This
     client data will be part of input parameters when the
     handleEvent method in the listener is invoked.
     
     @return: EventHandle, a numeric ID associated with this event
     registration. The eventHandle is used to unregister
     the listener using the remove_route_state_listener method
     If registration fails, -1 is returned.        
     @rtype: C{int}
     
     @raise OnepIllegalArgumentException: The exception is thrown when the 
     listener or other parameters is not valid.
     
     @raise OnepConnectionException: The exception is thrown when 
     connection to a network element has failed.
     
     @raise OnepRemoteProcedureException: The exception is thrown when 
     an error has occurred in the remote procedure call made to a
     network element
     """
     if listener == None:
         raise OnepIllegalArgumentException('ReplayRouteEventListener',
                                            'null')
     scopeIdl = None
     if isinstance(scope, (L3UnicastScope, )):
         scopeIdl = scope._to_idl()
     if scopeIdl == None:
         raise OnepIllegalArgumentException('scope', 'invalid')
     try:
         eventProp = self._parent_rss._routing_client.RoutingReplayRouteEvent_registerIDL(
             self._parent_rss.network_element.session_handle._id, scopeIdl)
         self.log.info(
             'Returning from RoutingReplayRouteEvent_registerIDL ')
         if eventProp != None:
             self._parent_rss.network_element.event_manager.add_listener(
                 eventProp.eventHandle, listener, client_data)
             self.log.debug(
                 'Registered ReplayRouteEventListener listener, eventHandle='
                 + str(eventProp.eventHandle))
             return eventProp.eventHandle
         raise OnepException(
             'Internal error while registering the Listener')
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e)
Пример #21
0
 def _set_show_data(self, element, data_name, data_value):
     if data_name == None:
         raise OnepIllegalArgumentException('dataName', 'None')
     try:
         self._api_client.ApplManagedData_setShowDataIDL(
             element.session_handle._id, data_name, data_value)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
Пример #22
0
 def request_event_unregister(self, eventHandle):
     """
         For internal use only
     
         """
     try:
         self.element.api_client.Event_unregisterIDL(self.element.session_handle._id, eventHandle)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
Пример #23
0
    def submit_policy_map(self, *policy_maps):
        """ Submits a list of policy maps.
        
        This will create the policy maps in the network element.
        
        @param policy_maps: The policy maps.
        @type policy_maps: Variable length argument list of L{PolicyMap<onep.policyservice.PolicyMap.PolicyMap>}
        
        @raise OnepIllegalArgumentException: If an PolicyMap in *policy_maps is invalid.
        @raise OnepRemoteProcedureException: If error occurs when remote procedure call is made to network element.
        @raise OnepConnectionException: If connection to network element fails.        
        """
        try:
            pmap_idl_list = []
            policy_type = 0
            for policy_map in policy_maps:
                self._check_element(policy_map._element)
                if not isinstance(policy_map, PolicyMap):
                    raise OnepIllegalArgumentException(
                        'Invalid policy map in *policy_maps.')
                if policy_type and policy_type != policy_map.capabilities.policy_type:
                    raise OnepIllegalArgumentException(
                        'Cannot submit policies with differing capabilities')
                policy_type = policy_map.capabilities.policy_type
                policy_map._op_code = PolicyMap.PolicyOperation.ONEP_POLICY_OP_CREATE
                pmap_idl_list.append(policy_map._to_idl())
                entries = policy_map.get_entry_list()

            if len(pmap_idl_list) == 0:
                raise OnepIllegalArgumentException(
                    '*policy_maps has no valid PolicyMap.')
            self.log.info('submit_policy_map: pmap_idl_list:%s',
                          str(pmap_idl_list))
            results = self._class_client.Policy_submitPmapBulkIDL(
                self._session_id, policy_type, pmap_idl_list)
            self.log.info('submit_policy_map: idl results:%s', str(results))
            if results:
                for (
                        i,
                        policy_map,
                ) in enumerate(policy_maps):
                    policy_map._set_result_idl(results[i])

                self.log.info('submit_policy_map executed with success.')
            else:
                self.log.error('no results for submit policy map')
        except OnepIllegalArgumentException as e:
            raise e
        except ExceptionIDL as e:
            raise OnepRemoteProcedureException(e)
        except TException as e:
            raise OnepConnectionException(e.message, e)
Пример #24
0
    def submit_class_map(self, *class_maps):
        """ Submits a list of class maps. 
        
        This will create the class maps in the network element.
        
        @param class_maps: The class maps.
        @type class_maps: Variable length argument list of L{ClassMap<onep.policyservice.ClassMap.ClassMap>}
        
        @raise OnepIllegalArgumentException: If any ClassMap in *class_maps is invalid.
        @raise OnepRemoteProcedureException: If error occurs when remote procedure call is made to network element.
        @raise OnepConnectionException: If connection to network element fails.    
        """
        try:
            class_map_idl_list = []
            policy_type = 0
            for class_map in class_maps:
                self._check_element(class_map._element)
                if not isinstance(class_map, ClassMap):
                    raise OnepIllegalArgumentException(
                        'Invalid class map in *class_maps.')
                if policy_type and policy_type != class_map.capabilities.policy_type:
                    raise OnepIllegalArgumentException(
                        'Cannot submit classes with differing capabilities')
                policy_type = class_map.capabilities.policy_type
                class_map._op_code = ClassMap.ClassOperation.ONEP_CLASS_OP_CREATE
                class_map_idl_list.append(class_map._to_idl())

            if len(class_map_idl_list) == 0:
                raise OnepIllegalArgumentException(
                    '*class_maps has no valid ClassMap.')
            self.log.info('submit_class_map: class_map_idl_list:%s',
                          str(class_map_idl_list))
            results = self._class_client.Policy_submitCmapBulkIDL(
                self._session_id, policy_type, class_map_idl_list)
            self.log.info('submit_class_map: idl results:%s', str(results))
            if results:
                for (
                        i,
                        class_map,
                ) in enumerate(class_maps):
                    class_map._set_result_idl(results[i])

                self.log.info('submit_class_map executed with success.')
            else:
                self.log.error('no results for submit class map')
        except OnepIllegalArgumentException as e:
            raise e
        except ExceptionIDL as e:
            raise OnepRemoteProcedureException(e)
        except TException as e:
            raise OnepConnectionException(e.message, e)
Пример #25
0
 def _remove_from_l2_acl(self, acl):
     """
     """
     try:
         self._ace_handle = acl._acl_client.deleteAce_IDL(
             acl._acl_handle, self._ace_handle)
         self.log.info(
             'Returned from deleteAce_IDL idl call to remove a L2-ace from L2-acl'
         )
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
     self._acl = None
Пример #26
0
 def __init__(self, element, version, instance, config_domain):
     """
     Constructor for ApplicationCli.
     
     @param element:
         The network element to which the application CLI will be applied.
     @type element: L{NetworkElement<onep.element.NetworkElement.NetworkElement>} 
     @param version: 
         The CLI version which the application will use.
     @type version: C{str}
     @param instance: 
         The instance identifier which the application will use.
     @type instance: C{str}
     @param config_domain: 
         The configuration domain identifier which the application will use. This must be supplied 
         for end-node hosted applications.  If application is running in a container, 
         the container name will be used.
     @type config_domain: C{str}
     
     @raise OnepRemoteProcedureException: System failure to serve the request, please check error
             message for more details.
     @raise OnepConnectionException: Transport error, may need to reset the connection, please 
             check the error message for more details.     
     @raise OnepIllegalArgumentException: This exception is thrown if input parameter is None.
     """
     if element == None:
         raise OnepIllegalArgumentException('element', 'None')
     if version == None:
         raise OnepIllegalArgumentException('version', 'None')
     if instance == None:
         raise OnepIllegalArgumentException('instance', 'None')
     if config_domain == None:
         raise OnepIllegalArgumentException('config_domain', 'None')
     self.log = logging.getLogger(__name__)
     self.element = element
     self.version = version
     self.instance = instance
     self.config_domain = config_domain
     self.element.set_appl_managed_data(self)
     self._api_client = ApplmgmtDataIDL.Client(element.api_protocol)
     try:
         val = self._api_client.ApplManagedData_setConfigIDL(
             element.session_handle._id, self.version, self.instance,
             self.config_domain)
         self.log.debug('ApplManagedData_setConfigIDL returns: ' + str(val))
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
Пример #27
0
 def _set_idle_timeout(self, timeout):
     """
             Set VTY idle timeout - zero is infinite
     
             Throws OnepVtyNotClosed if VTY service is still open
     
             """
     if self.is_open():
         raise OnepVtyNotClosed('Vty Service must be closed to set idle timeout')
     try:
         self.api_client.ExecutionCmd_setIdleTimeoutIDL(self.element.session_handle._id, int(timeout))
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
Пример #28
0
    def write(self, s):
        """
                Write a String to a vty on the network element
        
                @raise OnepConnectionException:
                            The exception is thrown when the connection to a network element
                            has failed.
                @raise OnepRemoteProcedureException:
                            The exception is thrown when an error has occurred in the
                            remote procedure call made to a network element.
                @raise OnepException:
                            The exception is thrown when the server returns an invalid CPU
                            sampling interval value.
        
                @param  s: The String to write to the vty
        
                @return: The interpreted result from the Network Element
        
                """
        if self.state == self.OnepVtyState.ONEP_VTY_STATE_DISCONNECTED or self.state == self.OnepVtyState.ONEP_VTY_STATE_IDLE_TIMEOUT:
            raise OnepConnectionException('VTY must be connected to write')
        if not s:
            raise OnepIllegalArgumentException(
                'Input command string is null or empty.')
        try:
            self.data_available = False
            self.cli_result = ''
            self.api_client.ExecutionCmd_writeIDL(
                self.element.session_handle._id, self.exec_handle, s,
                self.typeahead, self._max_response)
            elapsedTime = 0
            while not self.data_available:
                if self.timeout > 0 and elapsedTime >= self.timeout * 100:
                    break
                elapsedTime += 1
                time.sleep(0.01)

            if not self.data_available:
                self.api_client.ExecutionCmd_stopIDL(
                    self.element.session_handle._id, self.exec_handle)
                raise OnepException('VTY Write timed out')
        except ExceptionIDL as e:
            raise OnepRemoteProcedureException(e)
        except TException as e:
            raise OnepConnectionException(e.message, e)
        self.data_available = False
        return self.cli_result
Пример #29
0
 def delete_session_by_attributes(self,
                                  match_list,
                                  enforce_multi_delete=False):
     """
         Deletes sessions matching the attributes specified in match_list. 
         The attributes and their corresponding values in the match_list need to be 
         specified in order to find the sessions that match these attributes. 
     
         If multiple sessions are found and the enforce_multi_delete parameter 
         is True, then all found sessions will be deleted. If multiple sessions 
         are found but the enforce_multi_delete parameter is False, then none of the 
         found sessions will be deleted.
     
         @param match_list:
             The attributes and their corresponding values in the match_list 
             specifies the sessions that match these attributes.
         @param enforce_multi_delete:
             This parameter determines whether to proceed with the deletion when 
             multiple sessions are found. If the  parameter is true, 
             then all found sessions will be deleted. Otherwise, none of the 
             found sessions will be deleted.
                        
         @throws OnepIllegalArgumentException
             The exception is thrown when any of input parameter is 
             invalid.
         @throws OnepConnectionException
             The exception is thrown when the network element 
             is not connected.
         @throws OnepRemoteProcedureException
             The exception is thrown when an error has 
             occurred in the remote procedure call made to the 
             network element.
         """
     if self._ne == None or self._ne.session_handle == None:
         raise OnepConnectionException()
     match_id_list = Attribute.toIDLList(match_list, self._ne)
     if match_id_list == None:
         match_id_list = []
     try:
         self._identity_client.Sanet_Delete_Session_By_Attrs_IDL(
             self._ne.session_handle.id, match_id_list,
             1 if enforce_multi_delete else 0)
         return
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e)
Пример #30
0
 def __init__(self, element):
     """
             Constructor
     
             @raise OnepIllegalArgumentException
                         The exception is thrown when the input argument is invalid
             @raise OnepConnectionException:
                         The exception is thrown when the connection to a network element
                         has failed.
             @raise OnepRemoteProcedureException:
                         The exception is thrown when an error has occurred in the
                         remote procedure call made to a network element.
             @raise OnepException:
                         The exception is thrown when the server returns an invalid CPU
                         sampling interval value.
     
             @param  element: The Network Element on which to open the vty
     
             """
     self._max_response = 0
     self.timeout = 0
     self.typeahead = ''
     self.p_state = None
     self.exec_handle = 0
     self.data_available = False
     self.state = self.OnepVtyState.ONEP_VTY_STATE_DISCONNECTED
     VtyService.log = logging.getLogger(__name__)
     self.log.debug('Initializing Vty Service')
     if element == None:
         raise OnepIllegalArgumentException('element')
     if not element.is_connected():
         raise OnepConnectionException(
             'Network Element must be connected to open a VTY')
     self.element = element
     self.api_client = Client(element.api_protocol)
     try:
         self.exec_handle = self.api_client.ExecutionCmd_newIDL(
             element.session_handle._id)
     except ExceptionIDL as e:
         raise OnepRemoteProcedureException(e)
     except TException as e:
         raise OnepConnectionException(e.message, e)
     self.cli_result = str()
     self.listener = VtyService.Listener()
     element.event_manager.add_vty_listener(self.exec_handle, self.listener,
                                            self)