Exemplo n.º 1
0
def monitor_interface_event():
    handle = cps.event_connect()
    cps.event_register(handle,
                       nas_comm.yang.get_value('physical_key', 'keys_id'))
    cps.event_register(
        handle, nas_comm.yang.get_value('logical_if_state_key', 'keys_id'))
    cps.event_register(
        handle, nas_comm.yang.get_value('obs_logical_if_key', 'keys_id'))
    _led_control = media.led_control_get()
    while True:
        o = cps.event_wait(handle)
        obj = cps_object.CPSObject(obj=o)

        if nas_comm.yang.get_value('fp_key', 'keys_id') == obj.get_key():
            _update_fp(obj)
        if nas_comm.yang.get_value('physical_key', 'keys_id') == obj.get_key():
            continue

        if nas_comm.yang.get_value('obs_logical_if_key',
                                   'keys_id') == obj.get_key():
            _process_logical_if_event(obj)

        elif nas_comm.yang.get_value('logical_if_state_key',
                                     'keys_id') == obj.get_key():
            if_index = _get_obj_attr_value(
                obj, 'if/interfaces-state/interface/if-index')
            # check if if_index is present
            if if_index is None:
                nas_if.log_err(
                    'Interface index not present in the interface state event')
                continue
            # Get Interface attributes
            if_obj_list = nas_if.nas_os_if_list(d={'if-index': if_index})
            if if_obj_list is None:
                nas_if.log_err(
                    'Failed to get Interface attributes by ifindex from NAS interface'
                )
                continue
            admin_state = _get_obj_attr_value(
                obj, 'if/interfaces-state/interface/admin-status')
            if admin_state != None:
                # This is admin state change event
                try:
                    set_media_transceiver(if_obj_list[0])
                except:
                    nas_if.log_err(
                        "Unable to set media transceiver for if_index {}".
                        format(str(if_index)))

            if _led_control == True:
                oper_state = _get_obj_attr_value(
                    obj, 'if/interfaces-state/interface/oper-status')
                if oper_state != None:
                    try:
                        set_interface_media_speed(if_obj_list[0])
                    except:
                        nas_if.log_err("Error in setting LED")
                continue
Exemplo n.º 2
0
def monitor_interface_event():
    handle = cps.event_connect()
    cps.event_register(handle, _physical_key)
    cps.event_register(handle, _logical_if_state_key)
    _led_control = media.led_control_get()
    while True:
        o = cps.event_wait(handle)
        obj = cps_object.CPSObject(obj=o)
        if _physical_key == obj.get_key():
            if o['operation'] != 'create':
                continue
            nas_if.log_info("physical port creation event")
            set_media_type_on_port_create(obj)
        elif _logical_if_state_key == obj.get_key():
            if_index = _get_obj_attr_value(
                obj, 'if/interfaces-state/interface/if-index')
            # check if if_index is present
            if if_index == None:
                nas_if.log_err(
                    'Interface index not present in the interface state event')
                continue
            # Get Interface attributes
            admin_state = _get_obj_attr_value(
                obj, 'if/interfaces-state/interface/admin-status')
            if admin_state != None:
                # This is admin state change event
                try:
                    if_obj_list = nas_if.nas_os_if_list(
                        d={'if-index': if_index})
                    set_media_transceiver(if_obj_list[0])
                except:
                    nas_if.log_err("Unable to set media transceiver for ",
                                   str(if_index))
            if _led_control == True:
                oper_state = _get_obj_attr_value(
                    obj, 'if/interfaces-state/interface/oper-status')
                if oper_state != None:
                    try:
                        set_interface_led(if_obj_list[0])
                    except:
                        nas_if.log_err("Error in setting LED")
                continue
def monitor_interface_event():
    handle = cps.event_connect()
    cps.event_register(handle, _physical_key)
    cps.event_register(handle, _logical_if_state_key)
    _led_control = media.led_control_get()
    while True:
        o = cps.event_wait(handle)
        obj = cps_object.CPSObject(obj=o)
        if _physical_key == obj.get_key():
            if o['operation'] != 'create':
                continue
            print "physical port creation event"
            set_media_type_on_port_create(obj)
        elif _logical_if_state_key == obj.get_key():
            if_index = _get_obj_attr_value(obj, 'if/interfaces-state/interface/if-index')
            # check if if_index is present
            if if_index == None:
                print 'Interface index not present in the interface state event'
                continue
            # Get Interface attributes
            admin_state = _get_obj_attr_value(obj, 'if/interfaces-state/interface/admin-status')
            if admin_state != None:
                # This is admin state change event
                try:
                    if_obj_list = nas_if.nas_os_if_list(d={'if-index':if_index})
                    set_media_transceiver(if_obj_list[0])
                except:
                    print "Unable to set media transceiver for ", str(if_index)
            if _led_control == True:
                oper_state = _get_obj_attr_value(obj, 'if/interfaces-state/interface/oper-status')
                if oper_state != None:
                    try:
                        set_interface_led(if_obj_list[0])
                    except:
                        print "Error in setting LED"
                continue