
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr	  SSK
Jr  SSK
Jr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  S rS r\R>                  " \R@                  RB                  \R@                  RD                  5       " S S\RF                  5      5       r$S r%\RL                  \R>                  " \R@                  RN                  5       " S S\RF                  5      5       5       r(g)z*Implements command to list guest policies.    )absolute_import)division)unicode_literals)
list_pager)ops_agents_policy)+guest_policy_to_ops_agents_policy_converter)9os_policy_assignment_to_cloud_ops_agents_policy_converter)!cloud_ops_agents_policy_validator)guest_policy_validator)utils)base)
exceptions)log)
propertiesc                 \    SnU R                  SS5      n[        U5      U:  a  USU S-   $ U$ )z2Returns a length-limited guest policy description.   description Nz...)getlen)resourcemax_lenr   s      9lib/surface/compute/instances/ops_agents/policies/list.py _TransformGuestPolicyDescriptionr   #   sI     ']B/+$w. hw

 @4?@    c                 |    U R                   R                  S5        U R                   R                  S[        05        g).Parses input flags and sets up output formats.z
        table(
          id.basename(),
          description(),
          create_time,
          update_time
        )
      r   N)display_info	AddFormatAddTransformsr   parsers    r   _Argsr#   ,   s<     	 !
  	##679r   c                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
ListAlphaBeta;   aj  List Google Cloud's operations suite agents (Ops Agents) policies.

{command} lists policies that facilitate agent management across Compute
Engine instances based on user specified instance filters. These policies
install, specify versioning, enable autoupgrade, and remove Ops Agents.

The command returns a list of policies, including the ``ID'', ``DESCRIPTION'',
``CREATE_TIME'', and ``UPDATE_TIME'' for each policy. If no policies are
found, it returns an empty list. If malformed policies are found, they are
included in the result list with the descriptions replaced by ``<MALFORMED>'',
and a warning is shown.
{description}zS      To list guest policies in the current project, run:

      $ {command}
      DESCRIPTIONEXAMPLESc                     [        U 5        gSee base class.N)r#   r!   s    r   ArgsListAlphaBeta.ArgsU   s     
&Mr   c              #     #    U R                  5       n[        R                  " USS9n[        R                  " USS9n[        R
                  R                  R                  R                  5       nUR                  UR                  [        R                  " U5      S9nUR                  n[        R                  " UUUR                   ["        R$                  [        R&                  " U5      SSS9 H  n [(        R*                  " U5      v   M     g! [,        R.                   a_    [0        R2                  " SUR4                  5        [6        R8                  " SSS	SUR4                  UR:                  UR<                  S
9v    M  f = f7f)r-   v1beta)api_version_overridepageSizeparentguestPoliciesr4   limit	predicate
batch_sizefieldbatch_size_attributea  Encountered a malformed policy. The Ops Agents policy [%s] may have been modified directly by the OS Config guest policy API / gcloud commands. If so, please delete and re-create with the Ops Agents policy gcloud commands. If not, this may be an internal error.Nz<MALFORMED>)
assignmentagent_rulesr   etagnameupdate_timecreate_time)ReleaseTrackosconfig_api_utilsGetClientInstanceGetClientMessagesr   VALUEScoreproject	GetOrFail(OsconfigProjectsGuestPoliciesListRequest	page_sizeosconfig_command_utilsGetProjectUriPathprojects_guestPoliciesr   YieldFromListr8   r   IsOpsAgentPolicyGetListBatchSize	converter"ConvertGuestPolicyToOpsAgentPolicyr   BadArgumentExceptionr   warningr@   agent_policyOpsAgentPolicy
updateTime
createTime)	selfargsrelease_trackclientmessagesrI   requestserviceguest_policys	            r   RunListAlphaBeta.RunZ   sZ    %%'M11H6F!33H6H $$,,668G??%77@ @ G ++G"00jj(99)::4@'
::<HH ,, 

 	
 ))%""$//$//
 	

s+   C0F3DFA/F?FFF N
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr.   rc   __static_attributes__re   r   r   r%   r%   ;   s1     
		-  +
r   r%   c                 \    U R                  SSSS9  U R                  R                  S5        g)r   z--zoneTz9          Zone for which you want to list agent policies.)requiredhelpz
        table(
          policy_id.basename(),
          rollout_state,
          update_time.date("%Y-%m-%dT%H:%M:%SZ")
          )
      N)add_argumentr   r   r!   s    r   _ArgsGArs      s;    =   	 !
 r   c                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
List   a7  List a Google Cloud Observability agents policy for the Ops Agent.

{command} lists policies that facilitate agent management across Compute
Engine instances based on user specified instance filters. These policies
install, specify versioning, and remove agents.

The command returns a list of policies, including the ``POLICY_ID'',
``ROLLOUT_STATE'', and ``UPDATE_TIME'' for each policy. If no policies are
found, then the command returns an empty list. If policies were found but they
don't match as agents policies, then those policies won't be shown in the
list.
r'   z`      To list agents policies in the current project, run:

      $ {command} --zone=ZONE
      r(   c                     [        U 5        gr,   )rs   r!   s    r   r.   	List.Args   s     FOr   c           
   #   :  #    U R                  5       n[        R                  " U5      n[        R                  " U5      n[        R
                  R                  R                  R                  5       nUR                  UR                  [        R                  " XQR                  5      S9nUR                  n[        R                   " UUUR"                  [$        R&                  [        R(                  " U5      SSS9 H  n[*        R,                  " U5      v   M     g7f)r-   r3   osPolicyAssignmentsr4   r7   N)rC   rD   rE   rF   r   rG   rH   rI   rJ   7OsconfigProjectsLocationsOsPolicyAssignmentsListRequestrL   rM   GetProjectLocationUriPathzone&projects_locations_osPolicyAssignmentsr   rP   r8   r
   IsCloudOpsAgentsPolicyrR   to_ops_agents_policy/ConvertOsPolicyAssignmentToCloudOpsAgentsPolicy)	r[   r\   r]   r^   r_   rI   r`   ra   	os_policys	            r   rc   List.Run   s     %%'M11-@F!33MBH$$,,668GNN%??YY
 O G ;;G--jj3JJ)::4@#'	 
N
Ns   DDre   Nrf   re   r   r   ru   ru      s1     %
-  r   ru   N))rk   
__future__r   r   r   apitools.base.pyr   3googlecloudsdk.api_lib.compute.instances.ops_agentsr   rW   >googlecloudsdk.api_lib.compute.instances.ops_agents.convertersr   rS   r	   r   >googlecloudsdk.api_lib.compute.instances.ops_agents.validatorsr
   r   (googlecloudsdk.api_lib.compute.os_configr   rD   googlecloudsdk.callioper   r   ,googlecloudsdk.command_lib.compute.os_configrM   googlecloudsdk.corer   r   r   r#   ReleaseTracksrC   BETAALPHAListCommandr%   rs   UniverseCompatibleGAru   re   r   r   <module>r      s    1 &  ' ' a D ] l a P ( . X # *@9 D%%**D,=,=,C,CDI
D$$ I
 EI
X" D%%(()84 8 * 8r   