Skip to main content
Glama

PTP MCP Server

by aneeshkp
ptp_config_parser.cpython-311.pyc14.5 kB
� -�|h�+���dZddlZddlZddlZddlZddlmZmZmZm Z ddl m Z ej e ��Z Gd�d��ZdS)zA PTP Configuration Parser - Parses OpenShift ptpconfig resources �N)�Dict�List�Optional�Any)�datetimec��eZdZdZd�Zddedeeeffd�Zdeeefdeeeffd�Z d eeefdeeeffd �Z d eeefdeeeffd �Z d eeefdeeeffd�Z dedeeeffd�Z dedefd�Zdeeefdeeeffd�Zdeeefdeeeffd�Zdeeefdefd�Zdeeefdeefd�Zdeeefdeeeffd�Zdeeefdeefd�Zdeeefdeeeffd�Zdeeefdeeeffd�ZdS)�PTPConfigParserz0Parser for OpenShift PTP configuration resourcesc��d|_dS)Nz openshift-ptp)� namespace)�selfs �=/home/aputtur/Ai Projects/ptp-mcp-server/ptp_config_parser.py�__init__zPTPConfigParser.__init__s ��(�����Nr �returnc��K�|�|j} dddd|ddg}tj|ddd � ��}|jd krt d |j�����t j|j��}|� |��S#tj $rt d ���t$r0}t� dt|�������d}~wwxYw)z1Get all PTP configurations from OpenShift clusterN�oc�get� ptpconfigz-nz-o�yamlT�)�capture_output�text�timeoutrzFailed to get PTP configs: z"Timeout getting PTP configurationszError getting PTP configs: )r � subprocess�run� returncode� Exception�stderrr� safe_load�stdout�_parse_ptp_configs�TimeoutExpired�logger�error�str)r r �cmd�result�configs�es r �get_ptp_configszPTPConfigParser.get_ptp_configss���� � ���I� ��e�[��i��f��C�  �^��#��� ���F�� �A�%�%�� M�f�m� M� M�N�N�N��n�V�]�3�3�G��*�*�7�3�3� 3���(� B� B� B��@�A�A� A�� � � � �L�L�?�s�1�v�v�?�?� @� @� @� ����� ���s�A0A>�>'C�%+C�C� raw_configsc��|�d��|�d��|�di��gd�}|�dg��D]2}|�|��}|d�|���3|S)z3Parse raw PTP configurations into structured format� apiVersion�kind�metadata)r-r.r/�itemsr0)r�_parse_ptp_config_item�append)r r+�parsed_configs�item� parsed_items r r!z"PTPConfigParser._parse_ptp_configs6s���&�/�/�,�7�7��O�O�F�+�+�#��� �B�7�7��  � �� �O�O�G�R�0�0� 8� 8�D��5�5�d�;�;�K� �7� #� *� *�;� 7� 7� 7� 7��rr4c��|�di��|�|�di����|�di��d�}|S)z'Parse individual PTP configuration itemr/�spec�status)r/r7r8)r�_parse_ptp_spec)r r4r5s r r1z&PTPConfigParser._parse_ptp_config_itemEsY������R�0�0��(�(����&�"�)=�)=�>�>��h�h�x��,�,� � � � �rr7c�4�ggd�}|�dg��D]2}|�|��}|d�|���3|�dg��D]2}|�|��}|d�|���3|S)zParse PTP specification section)�profile� recommendr;r<)r�_parse_ptp_profiler2�_parse_ptp_recommend)r r7� parsed_specr;�parsed_profiler<�parsed_recommends r r9zPTPConfigParser._parse_ptp_specOs����� � � � �x�x� �2�.�.� :� :�G�!�4�4�W�=�=�N� � � "� )� )�.� 9� 9� 9� 9����+�r�2�2� >� >�I�#�8�8��C�C� � � � $� +� +�,<� =� =� =� =��rr;c �t�|�d��|�d��|�d��|�d��|�d��|�|�dd����|�|�di����d �}|S) zParse PTP profile configuration�name�ptpSchedulingPolicy�ptpSchedulingPriority� phc2sysOpts� ptp4lOpts� ptp4lConf��ptpClockThreshold)rCrDrErFrGrHrJ)r�_parse_ptp4l_conf�_parse_ptp_clock_threshold)r r;r@s r r=z"PTPConfigParser._parse_ptp_profilebs����K�K��'�'�#*�;�;�/D�#E�#E�%,�[�[�1H�%I�%I�"�;�;�}�5�5� ���[�1�1��/�/�� � �K��0L�0L�M�M�!%�!@�!@����M`�bd�Ae�Ae�!f�!f� � ���r� conf_textc��|siSiiiiid�}d}|����d��}|D�]}|���}|r|�d��r�/|�d��r@|�d��r+|dd�}|d vr|}nd }|}||d vr i|d |<��d |vr�|�d d��\}} |���}| ���} |d kr%|�| ��|d ||<��|�| ��|||<��|S) z5Parse ptp4l configuration text into structured format)� interfaces�global�servo� transport�clockrP� �#�[�]������)rPrQrRrSrO� )�strip�split� startswith�endswith� _parse_value) r rM� parsed_conf�current_section�lines�line� section_name�interface_name�key�values r rKz!PTPConfigParser._parse_ptp4l_confps���� ��I������  � � �#�����!�!�'�'��-�-��� Q� Q�D��:�:�<�<�D�� �4�?�?�3�/�/� �����s�#�#� �� � �c�(:�(:� �#�A�b�D�z� ��#L�L�L�&2�O�O�'3�O�%1�N�%�[��-F�F�F�DF� �L�1�.�A���d�{�{�!�Z�Z��Q�/�/� ��U��i�i�k�k��� � � � ��"�l�2�2�EI�EV�EV�W\�E]�E]�K� �-�n�=�c�B�B�8<�8I�8I�%�8P�8P�K��0��5���rrgc�R� t|��S#t$rYnwxYw t|��S#t$rYnwxYw|���dvrdS|���dvrdS|�d��r! t|d��S#t$rYnwxYw|S)z/Parse configuration value with appropriate type)�true�1�yesT)�false�0�noF�0x�)�int� ValueError�float�lowerr])r rgs r r_zPTPConfigParser._parse_value�s��� ��u�:�:� ��� � � � �D� ���� ���<�<� ��� � � � �D� ���� �;�;�=�=�0� 0� 0��4� �[�[�]�]�2� 2� 2��5� � � �D� !� !� � ��5�"�~�~�%��� � � ��� ����� s*�� ��1� >�>�B� B$�#B$� thresholdc��|�d��|�d��|�d��d�S)z'Parse PTP clock threshold configuration�holdOverTimeout�maxOffsetThreshold�minOffsetThreshold)rwrxry�r)r rus r rLz*PTPConfigParser._parse_ptp_clock_threshold�sC�� )�}�}�->�?�?�"+�-�-�0D�"E�"E�"+�-�-�0D�"E�"E� � � rr<c��|�d��|�d��|�dg��d�S)z&Parse PTP recommendation configurationr;�priority�match)r;r|r}rz)r r<s r r>z$PTPConfigParser._parse_ptp_recommend�sB��!�}�}�Y�/�/�!� � �j�1�1��]�]�7�B�/�/� � � r�configc���|�di���dg��D]G}|�di��}|�di���d��}|r|cS�HdS)z)Extract clock type from PTP configurationr7r;rHrS� clock_type�Unknownrz)r r~r;� ptp4l_confr�s r �get_clock_typezPTPConfigParser.get_clock_type�s����z�z�&�"�-�-�1�1�)�R�@�@� "� "�G� ���[�"�5�5�J�#�����4�4�8�8��F�F�J�� "�!�!�!�!� "��yrc���|�di���dg��D]G}|�di��}|�di���d��}|�|cS�HdS)z,Extract domain number from PTP configurationr7r;rHrP� domainNumberNrz)r r~r;r��domains r �get_domain_numberz!PTPConfigParser.get_domain_number�s|���z�z�&�"�-�-�1�1�)�R�@�@� � �G� ���[�"�5�5�J��^�^�H�b�1�1�5�5�n�E�E�F��!�� � � �"��trc���i}|�di���dg��D]L}|�di��}|�di��}d|vr |d|d<d|vr |d|d<�M|S)z.Extract priority values from PTP configurationr7r;rHrP� priority1� priority2rz)r r~� prioritiesr;r�� global_confs r �get_prioritieszPTPConfigParser.get_priorities�s���� ��z�z�&�"�-�-�1�1�)�R�@�@� C� C�G� ���[�"�5�5�J�$�.�.��2�6�6�K��k�)�)�*5�k�*B� �;�'��k�)�)�*5�k�*B� �;�'���rc���|�di���dg��D]G}|�di��}|�di���d��}|�|cS�HdS)z*Extract clock class from PTP configurationr7r;rHrP� clockClassNrz)r r~r;r�� clock_classs r �get_clock_classzPTPConfigParser.get_clock_class�s���z�z�&�"�-�-�1�1�)�R�@�@� #� #�G� ���[�"�5�5�J�$�.�.��2�6�6�:�:�<�H�H�K��&�"�"�"�"�'��trc��i}|�di���dg��D][}|�di��}|�di��}d|vr |d|d<d|vr |d|d<d|vr |d|d<�\|S)z-Extract sync intervals from PTP configurationr7r;rHrP�logSyncInterval�logAnnounceInterval�logMinDelayReqIntervalrz)r r~� intervalsr;r�r�s r �get_sync_intervalsz"PTPConfigParser.get_sync_intervals�s���� ��z�z�&�"�-�-�1�1�)�R�@�@� \� \�G� ���[�"�5�5�J�$�.�.��2�6�6�K� �K�/�/�/:�;L�/M� �+�,�$� �3�3�3>�?T�3U� �/�0�'�;�6�6�6A�BZ�6[� �2�3���rc�T�dgggd�}|�di���d��s d|d<|d�d��|�|��}|�+|d ks|d kr|d �d |�d���|�|��}|�!|dkr|d�d��|�|��}|���D]3\}}|dks|dkr"|d�d|�d|�d����4|S)z8Validate PTP configuration and return validation resultsT)�valid�errors�warnings�recommendationsr7r;Fr�r�zNo profiles definedN��+r�zDomain number z( is outside ITU-T G.8275.1 range (24-43)��z#Invalid clock class (must be 0-255)rzInvalid z value z (must be 0-255))rr2r�r�r�r0)r r~�validation_resultr�r�r�� priority_name�priority_values r �validate_configzPTPConfigParser.validate_configs������!�  � ���z�z�&�"�%�%�)�)�)�4�4� F�).� �g� &� �h� '� .� .�/D� E� E� E��'�'��/�/�� � �6�B�;�;�&�2�+�+� �j� )� 0� 0�Q��Q�Q�Q� � � � �*�*�6�2�2� � � "�{�S�'8�'8� �h� '� .� .�/T� U� U� U��(�(��0�0� �-7�-=�-=�-?�-?� � � )�M�>���!�!�^�c�%9�%9�!�(�+�2�2�U�}�U�U�^�U�U�U�����!� r)N)�__name__� __module__� __qualname__�__doc__rr%rrr*r!r1r9r=rKr_rLr>r�rrqr�r�r�r�r��rr r r s�������:�:�)�)�)���s��d�3��8�n�����B �d�3��8�n� ��c�3�h�� � � � ��4��S��>��d�3��8�n������D��c��N��t�C��H�~�����& �$�s�C�x�.� �T�#�s�(�^� � � � �-�3�-�4��S��>�-�-�-�-�^�#��#�����< �D��c��N� �t�C�QT�H�~� � � � � �d�3��8�n� ��c�3�h�� � � � ��T�#�s�(�^���������S�#�X���8�C�=����� �T�#�s�(�^� ��S�#�X�� � � � ��d�3��8�n���#��������c�3�h���D��c��N����� "!�d�3��8�n�"!��c�3�h��"!�"!�"!�"!�"!�"!rr )r��json�loggingrr�typingrrrrr� getLoggerr�r#r r�rr �<module>r�s����� � � � ��������� � � � �,�,�,�,�,�,�,�,�,�,�,�,������� �� �8� $� $��Y!�Y!�Y!�Y!�Y!�Y!�Y!�Y!�Y!�Y!r

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aneeshkp/ptp-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server