
    d                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ  G d de	      Z
 G d d	e	      Z G d
 de      Z G d de	      Z G d de      Zy)    N)logger)AgentGlobals)
AgentError)textutilc                       e Zd ZdZdZdZy)GoalStateChannel
WireServerHostGAPluginEmptyN)__name__
__module____qualname__r	   r
   r        W/usr/lib/python3/dist-packages/azurelinuxagent/common/protocol/extensions_goal_state.pyr   r      s    J!LEr   r   c                       e Zd ZdZdZdZy)GoalStateSourceFabric	FastTrackr   N)r   r   r   r   r   r   r   r   r   r   r       s    FIEr   r   c                   $     e Zd ZdZd fd	Z xZS )VmSettingsParseErrorz8
    Error raised when the VmSettings are malformed
    c                 J    t         t        |   ||       || _        || _        y N)superr   __init__etagvm_settings_text)selfmessager   r   inner	__class__s        r   r   zVmSettingsParseError.__init__*   s$    "D27EB	 0r   r   )r   r   r   __doc__r   __classcell__r!   s   @r   r   r   &   s    1 1r   r   c                   L   e Zd ZdZd Zed        Zed        Zej                  d        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zed        Zed        Zd Zed        Zed        Zed        Zed        Zd Zd Zed        Zed        Zy)ExtensionsGoalStatea  
    ExtensionsGoalState represents the extensions information in the goal state; that information can originate from
    ExtensionsConfig when the goal state is retrieved from the WireServe or from vmSettings when it is retrieved from
    the HostGAPlugin.

    NOTE: This is an abstract class. The corresponding concrete classes can be instantiated using the ExtensionsGoalStateFactory.
    c                     d| _         y NF_is_outdatedr   s    r   r   zExtensionsGoalState.__init__8   s
    !r   c                     t               )z
        Returns a string that includes the incarnation number if the ExtensionsGoalState was created from ExtensionsConfig, or the etag if it
        was created from vmSettings.
        NotImplementedErrorr+   s    r   idzExtensionsGoalState.id;   s     "##r   c                     | j                   S )a  
        A goal state can be outdated if, for example, the VM Agent is using Fast Track and support for it stops (e.g. the VM is migrated
        to a node with an older version of the HostGAPlugin) and now the Agent is fetching goal states via the WireServer.
        r)   r+   s    r   is_outdatedzExtensionsGoalState.is_outdatedC   s        r   c                     || _         y r   r)   r   values     r   r1   zExtensionsGoalState.is_outdatedK   s
    !r   c                     t               r   r-   r+   s    r   svd_sequence_numberz'ExtensionsGoalState.svd_sequence_numberO       !##r   c                     t               r   r-   r+   s    r   activity_idzExtensionsGoalState.activity_idS   r7   r   c                     t               r   r-   r+   s    r   correlation_idz"ExtensionsGoalState.correlation_idW   r7   r   c                     t               r   r-   r+   s    r   created_on_timestampz(ExtensionsGoalState.created_on_timestamp[   r7   r   c                     t               )z^
        Whether the goal state was retrieved from the WireServer or the HostGAPlugin
        r-   r+   s    r   channelzExtensionsGoalState.channel_       
 "##r   c                     t               )zM
        Whether the goal state originated from Fabric or Fast Track
        r-   r+   s    r   sourcezExtensionsGoalState.sourcef   r@   r   c                     t               r   r-   r+   s    r   status_upload_blobz&ExtensionsGoalState.status_upload_blobm   r7   r   c                     t               r   r-   r+   s    r   status_upload_blob_typez+ExtensionsGoalState.status_upload_blob_typeq   r7   r   c                     t               r   r-   r3   s     r   _set_status_upload_blob_typez0ExtensionsGoalState._set_status_upload_blob_typeu   s    !##r   c                     t               r   r-   r+   s    r   required_featuresz%ExtensionsGoalState.required_featuresx   r7   r   c                     t               r   r-   r+   s    r   on_holdzExtensionsGoalState.on_hold|   r7   r   c                     t               r   r-   r+   s    r   agent_familiesz"ExtensionsGoalState.agent_families   r7   r   c                     t               r   r-   r+   s    r   
extensionszExtensionsGoalState.extensions   r7   r   c                     t               )z
        Returns the raw text (either the ExtensionsConfig or the vmSettings) with any confidential data removed, or an empty string for empty goal states.
        r-   r+   s    r   get_redacted_textz%ExtensionsGoalState.get_redacted_text   s     "##r   c                     | j                   dvr2t        j                  d| j                         | j	                  d       yy)zL
        Does validations common to vmSettings and ExtensionsConfig
        )	BlockBlobPageBlobz7Status Blob type '{0}' is not valid, assuming BlockBlobrT   N)rF   r   inforD   rH   r+   s    r   _do_common_validationsz*ExtensionsGoalState._do_common_validations   s=     ''/HHKKQSWSjSjk--k: Ir   c                    t        j                   ddddd      }|}| dvr>	 t         j                   j                  t        j                  t        |       dz        z   }t        ||      }|j                  t
        j                  j                        S # t        $ r3}t        j                  dt        j                  |             Y d}~ld}~ww xY w)	z
        Takes 'ticks', a string indicating the number of ticks since midnight 0001-01-01 00:00:00, and
        returns a UTC timestamp  (every tick is 1/10000000 of a second).
        il     r   N i )secondszCan't parse ticks: {0}N)datetimemin	timedeltafloat	Exceptionr   verboser   format_exceptionmaxstrftimeLoggerLogTimeFormatInUTC)ticks_stringminimumas_date_time	exceptions       r   _ticks_to_utc_timestampz+ExtensionsGoalState._ticks_to_utc_timestamp   s     ##D!Q15z)_'0044x7I7IRWXdRehoRo7pp <1$$V]]%E%EFF	  _79R9RS\9]^^_s   =B 	C)C

Cc                 .    | dv rt         j                  S | S )z
        Takes 'id', a string indicating an ID, and returns a null GUID if the string is None or empty; otherwise
        return 'id' unchanged
        rZ   r   	GUID_ZERO)	id_strings    r   _string_to_idz!ExtensionsGoalState._string_to_id   s     
")))r   N)r   r   r   r"   r   propertyr/   r1   setterr6   r9   r;   r=   r?   rB   rD   rF   rH   rJ   rL   rN   rP   rR   rW   staticmethodrl   rq   r   r   r   r&   r&   0   sw   " $ $ ! ! " " $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $$ $ $ $ $ $ $ $ $$; G G   r   r&   c                   
    e Zd Z fdZed        Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zd Zed        Zed        Zed        Zed        Zd Z xZS )EmptyExtensionsGoalStatec                 d    t         t        |           dj                  |      | _        || _        y )Nzincarnation_{0})r   rv   r   format_id_incarnation)r   incarnationr!   s     r   r   z!EmptyExtensionsGoalState.__init__   s+    &68$++K8'r   c                     | j                   S r   )ry   r+   s    r   r/   zEmptyExtensionsGoalState.id   s    xxr   c                     | j                   S r   rz   r+   s    r   r{   z$EmptyExtensionsGoalState.incarnation          r   c                     | j                   S r   r~   r+   s    r   r6   z,EmptyExtensionsGoalState.svd_sequence_number   r   r   c                 "    t         j                  S r   rn   r+   s    r   r9   z$EmptyExtensionsGoalState.activity_id       %%%r   c                 "    t         j                  S r   rn   r+   s    r   r;   z'EmptyExtensionsGoalState.correlation_id   r   r   c                 6    t         j                   j                  S r   )r]   r^   r+   s    r   r=   z-EmptyExtensionsGoalState.created_on_timestamp   s      $$$r   c                 "    t         j                  S r   )r   r   r+   s    r   r?   z EmptyExtensionsGoalState.channel   s    %%%r   c                 "    t         j                  S r   )r   r   r+   s    r   rB   zEmptyExtensionsGoalState.source   s    $$$r   c                      y r   r   r+   s    r   rD   z+EmptyExtensionsGoalState.status_upload_blob       r   c                      y r   r   r+   s    r   rF   z0EmptyExtensionsGoalState.status_upload_blob_type   r   r   c                     t        d      )NzXEmptyExtensionsGoalState is immutable; cannot change the value of the status upload blob)	TypeErrorr3   s     r   rH   z5EmptyExtensionsGoalState._set_status_upload_blob_type   s    rssr   c                     g S r   r   r+   s    r   rJ   z*EmptyExtensionsGoalState.required_features       	r   c                      yr(   r   r+   s    r   rL   z EmptyExtensionsGoalState.on_hold   s    r   c                     g S r   r   r+   s    r   rN   z'EmptyExtensionsGoalState.agent_families   r   r   c                     g S r   r   r+   s    r   rP   z#EmptyExtensionsGoalState.extensions   r   r   c                      yrZ   r   r+   s    r   rR   z*EmptyExtensionsGoalState.get_redacted_text   s    r   )r   r   r   r   rr   r/   r{   r6   r9   r;   r=   r?   rB   rD   rF   rH   rJ   rL   rN   rP   rR   r#   r$   s   @r   rv   rv      s+   (
   ! ! ! ! & & & & % % & & % %    t        r   rv   )r]   azurelinuxagent.commonr   #azurelinuxagent.common.AgentGlobalsr    azurelinuxagent.common.exceptionr   azurelinuxagent.common.utilsr   objectr   r   r   r&   rv   r   r   r   <module>r      sX   $  ) < 7 1v f 1: 1& DB2 Br   