
    v                     p    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ d	Zd
Zd Zd Zy)zGUtility function for OS Config Troubleshooter to check agent freshness.    )absolute_import)division)unicode_literals)
exceptions)apis)base)utilsosconfigzUnknown
The version of OS Config agent running on this instance is unknown. Visit https://cloud.google.com/compute/docs/manage-os#check-install on how to check if the agent is installed and running.c                 D    | t         j                  j                  k(  rdS dS )Nv1alphav1)r   ReleaseTrackALPHA)release_tracks    Plib/googlecloudsdk/command_lib/compute/os_config/troubleshoot/agent_freshness.py_GetReleaseTrackr   "   s     #t'8'8'>'>>HDH    c                    d}d}t        j                  t        t        |            }|j                  }dj                  | j                  ||j                        }d}		 |j                  |j                  j                  ||j                  j                  j                  j                              }	|	j&                  j(                  s|t        z  }t        j                   ||      S d}|	j&                  j(                  D ]8  }|j*                  }|j-                  d      s!|j/                  d      dk7  s6d	} n |s|d
z  }t        j                   ||      S |	j&                  j(                  D ]Q  }|j*                  }|j-                  d      s!|j/                  d      dk7  s6|dz  }t        j                   ||      c S  d	}|dz  }t        j                   ||      S # t        j                  $ r" |t        z  }t        j                   ||      cY S t        j"                  $ r8}
|t        j$                  |
      z  }t        j                   ||      cY d}
~
S d}
~
ww xY w)z1Checks whether the OS Config agent is up to date.Fz%> Is the OS Config agent up to date? z/projects/{}/locations/{}/instances/{}/inventoryN)nameviewinstalledPackagezgoogle-osconfig-agentTzNo
The OS Config agent is not installed on this VM. See https://cloud.google.com/compute/docs/manage-os#agent-install on how to install the agent.availablePackagezNo
The version of OS Config agent running on this VM instance is not the latest version. See https://cloud.google.com/compute/docs/manage-os/upgrade-vm-manager#update-agent on how to update the agent.Yes)r   GetClientInstance_API_CLIENT_NAMEr   (projects_locations_instances_inventoriesformatr   GetMESSAGES_MODULE7OsconfigProjectsLocationsInstancesInventoriesGetRequestViewValueValuesEnumFULLr   HttpNotFoundError_UNKNOWN_MESSAGEr	   ResponseHttpForbiddenErrorUnknownMessageitemsadditionalPropertieskey
startswithfind)projectinstancezoner   continue_flagresponse_messageclientinventory_servicer   	inventoryeinstalled_flagitemr+   s                 r   Checkr9   &   s<   -<!!"2"2="AC&EE	:	A	AllD(--
)$);!%%	@	@''DD  	 
A 
'(I 
	-	-((>>-)9:: .oo22d
((C
~~ #)@ AR Gn 3 
	'
 >>-)9:: oo22d
((C
~~ #)@ AR G) ^^M+;<< 3 -e	'7	88[ 
	%	% ;((>>-)9::		&	& ;,,Q//>>-)9::;s%   AG 2II$-IIIN)__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   9googlecloudsdk.command_lib.compute.os_config.troubleshootr	   r   r%   r   r9    r   r   <module>rA      s<    N &  ' ' , ( K = IA9r   