
                            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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  ej8                  ej:                  j<                  ej:                  j>                         G d dej@                               Z!ejD                   ej8                  ej:                  jF                         G d dej@                                      Z$y)z4Implements command to describe an ops agents policy.    )absolute_import)division)unicode_literals)
exceptions)cloud_ops_agents_util)+guest_policy_to_ops_agents_policy_converter)guest_policy_validator)utils)base)parser_utils)
propertiesc                   0    e Zd ZdZdddZed        Zd Zy)DescribeAlphaBetaa  Describe a Google Cloud's operations suite agents (Ops Agents) policy.

  *{command}* describes a policy that facilitates agent management across
  Compute Engine instances based on user specified instance filters. This policy
  installs, specifies versioning, enables autoupgrade, and removes Ops Agents.

  The command returns the content of one policy. For instance:

    agent_rules:
    - enable_autoupgrade: true
      package_state: installed
      type: ops-agent
      version: latest
    assignment:
      group_labels:
      - app: myapp
        env: prod
      os_types:
      - short_name: ubuntu
        version: '18.04'
      zones:
      - us-central1-a
    create_time: '2021-02-02T02:10:25.344Z'
    description: A test policy to install agents
    etag: <ETAG>
    id: projects/<PROJECT_NUMBER>/guestPolicies/ops-agents-test-policy
    update_time: '2021-02-02T02:10:25.344Z'

  If no policies are found, it returns a ``NOT_FOUND'' error.
  {description}z          To describe an Ops Agents policy named ``ops-agents-test-policy'' in
          the current project, run:

            $ {command} ops-agents-test-policy
          DESCRIPTIONEXAMPLESc                 .    t        j                  |        y)See base class.N)r   AddSharedArgsparsers    =lib/surface/compute/instances/ops_agents/policies/describe.pyArgszDescribeAlphaBeta.ArgsM   s     v&    c                    | j                         }t        j                  j                  j                  j                         }t        j                  d||j                        }t        j                  |d      }|j                  }t        j                  |d      }|j                  |      }	 |j                  |      }	t'        j(                  |	      s t#        j$                  |j                        	 t+        j,                  |	      }
|
S # t        j                   $ r! t#        j$                  |j                        w xY w# t.        j0                  $ r! t#        j2                  |j                        w xY w)r   projectsv1beta)api_version_override)name)	policy_id)ReleaseTrackr   VALUEScoreproject	GetOrFailosconfig_command_utilsGetGuestPolicyUriPath	POLICY_IDosconfig_api_utilsGetClientInstanceprojects_guestPoliciesGetClientMessages'OsconfigProjectsGuestPoliciesGetRequestGetapitools_exceptionsHttpNotFoundErrorops_agents_exceptionsPolicyNotFoundErrorr	   IsOpsAgentPolicyto_ops_agents"ConvertGuestPolicyToOpsAgentPolicycalliope_exceptionsBadArgumentExceptionPolicyMalformedError)selfargsrelease_trackr%   guest_policy_uri_pathclientservicemessagesget_requestget_responseops_agents_policys              r   RunzDescribeAlphaBeta.RunR   sV   %%'M$$,,668G2HHGT^^  11HF ++G!33HH BB" C KP[[-l "22<@!55OOQ'JJ

  00 P!55OOP 33 Q!66PPQs   1D 8E 4E4E:N__name__
__module____qualname____doc__detailed_helpstaticmethodr   rD    r   r   r   r   "   s2    @ %- ' 'r   r   c                   0    e Zd ZdZdddZed        Zd Zy)Describea>  Describe a Google Cloud Observability agents policy for the Ops Agent.

  *{command}* describes a policy that facilitates agent management across
  Compute Engine instances based on user specified instance filters. This policy
  installs, specifies versioning, and removes Ops Agents.

  The command returns the content of one policy. For instance:

    agentsRule:
      packageState: installed
      version: latest
    instanceFilter:
      inclusionLabels:
      - labels:
          env: prod

  If no policies are found, then the command returns a `NOT_FOUND` error.
  r   z          To describe an agents policy named `ops-agents-test-policy` in
          the current project, run:

            $ {command} ops-agents-test-policy --zone=ZONE
          r   c                 \    | j                  dt        d       | j                  ddd       y)	r   r)   z          ID of the policy.

          This ID must contain only lowercase letters,
          numbers, and hyphens, end with a number or a letter, be between 1-63
          characters, and be unique within the project.
          )typehelpz--zoneTz$          Zone of the agents policy.)requiredrQ   N)add_argumentstrr   s    r   r   zDescribe.Args   sB       
 (  r   c                     | j                         }t        j                  j                  j                  j                         }t        j                  ||j                  ||j                        j                         S )r   )r"   r   r#   r$   r%   r&   r   GetOpsAgentsPolicyFromApir)   zone	ToPyValue)r:   r;   r<   r%   s       r   rD   zDescribe.Run   s[    %%'M$$,,668G ::t~~w		ikr   NrE   rL   r   r   rN   rN   t   s1    ( %-  (r   rN   N)%rI   
__future__r   r   r   apitools.base.pyr   r0   3googlecloudsdk.api_lib.compute.instances.ops_agentsr   r2   >googlecloudsdk.api_lib.compute.instances.ops_agents.convertersr   r5   >googlecloudsdk.api_lib.compute.instances.ops_agents.validatorsr	   (googlecloudsdk.api_lib.compute.os_configr
   r*   googlecloudsdk.callioper   r7   @googlecloudsdk.command_lib.compute.instances.ops_agents.policiesr   ,googlecloudsdk.command_lib.compute.os_configr'   googlecloudsdk.corer   ReleaseTracksr"   BETAALPHADescribeCommandr   UniverseCompatibleGArN   rL   r   r   <module>ri      s    ; &  ' > U c H a P ( E Y X * D%%**D,=,=,C,CDN,, N ENb D%%(():t## : * :r   