
    0                     8   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SKJr  SSKJr  SSKJr  SSKJ r   SSK!J"r#  \RH                  " \RJ                  RL                  \RJ                  RN                  5       " S S\RP                  5      5       r)\RT                  \RH                  " \RJ                  RV                  5       " S S\RP                  5      5       5       r,g)z2Implements command to update an ops agents policy.    )absolute_import)division)unicode_literals)encoding)cloud_ops_agents_policy)cloud_ops_agents_util)ops_agents_policy)9cloud_ops_agents_policy_to_os_assignment_policy_converter)+guest_policy_to_ops_agents_policy_converter)+ops_agents_policy_to_guest_policy_converter)9os_policy_assignment_to_cloud_ops_agents_policy_converter)!cloud_ops_agents_policy_validator)ops_agents_policy_validator)utils)base)parser_utils)
properties)yaml)osconfig_v1_messagesc                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
UpdateAlphaBeta(   a  Update a Google Cloud operations suite agent (Ops Agent) policy.

*{command}* updates 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 the updated policy or an error indicating
why the update fails. The updated policy takes effect asynchronously. It
can take 10-15 minutes for the VMs to enforce the updated policy.

The available flags for the ``update'' command are similar to the flags for
the ``create'' command. All the flags for ``update'' are optional. If a flag
is not specified, it retains the original value. The full value of each flag
needs to be re-stated during ``update''. Take the ``--agents'' flag for
example:

If the original policy specified two agents
(``--agents="type=logging;type=metrics"''), and only one agent
(``--agents="type=logging"'') is specified in a *{command}* command, then the
policy stops managing and enforcing the unspecified agent. In order to remove
the metrics agent in this case, set the package state explicitly to
``removed'' (``--agents="type=logging;type=metrics,package-state=removed"'').

In order to explicitly clear the ``--group-labels'', ``--instances'', and
``--zones'' instance filters, use the following flags as documented below:
``--clear-group-labels'', ``--clear-instances'', and ``--clear-zones'' flags.
{description}a            To update a policy named ``ops-agents-test-policy'' to target a
          single CentOS 7 VM instance named
          ``zones/us-central1-a/instances/test-instance'' for testing or
          development, and install both Logging and Monitoring Agents on that
          VM instance, run:

          $ {command} ops-agents-test-policy --agent-rules="type=logging,enable-autoupgrade=false;type=metrics,enable-autoupgrade=false" --instances=zones/us-central1-a/instances/test-instance --os-types=short-name=centos,version=7

          To update a policy named ``ops-agents-prod-policy'' to target all
          CentOS 7 VMs in zone ``us-central1-a'' with either
          ``env=prod,product=myapp'' labels or ``env=staging,product=myapp''
          labels, and make sure the logging agent and metrics agent versions are
          pinned to specific major versions for staging and production, run:

          $ {command} ops-agents-prod-policy --agent-rules="type=logging,version=1.*.*,enable-autoupgrade=false;type=metrics,version=6.*.*,enable-autoupgrade=false" --group-labels="env=prod,product=myapp;env=staging,product=myapp" --os-types=short-name=centos,version=7 --zones=us-central1-a

          To update a policy named ``ops-agents-labels-policy'' to clear the
          instances filters and use a group labels filter instead to target VMs
          with either ``env=prod,product=myapp'' or
          ``env=staging,product=myapp'' labels, run:

          $ {command} ops-agents-labels-policy --clear-instances --group-labels="env=prod,product=myapp;env=staging,product=myapp"

          To perform the same update as above, conditionally on the fact that
          the policy's etag (retrieved by an earlier command) is
          ``f59741c8-bb5e-4ee6-bf6f-c4ebeb6b06e0'', run:

          $ {command} ops-agents-labels-policy --clear-instances --group-labels="env=prod,product=myapp;env=staging,product=myapp" --etag=f59741c8-bb5e-4ee6-bf6f-c4ebeb6b06e0
          DESCRIPTIONEXAMPLESc                     [         R                  " U 5        [         R                  " U SS9  [         R                  " U 5        g)See base class.F)parserrequiredN)r   AddSharedArgsAddMutationArgsAddUpdateArgsr   s    ;lib/surface/compute/instances/ops_agents/policies/update.pyArgsUpdateAlphaBeta.Argsh   s0     v&  ?v&    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                  [        R                  " SXQR                  5      S9nUR                  nUR                  U5      n[        R                   " U5      n	["        R$                  " U	UR&                  UR(                  UR*                  UR,                  UR.                  (       a  / OUR0                  UR2                  (       a  / OUR4                  UR6                  (       a  / OUR8                  5      n
[:        R<                  " U
5        [>        R@                  " XJURB                  5      nURE                  U[        R                  " SXQR                  5      SS9nURG                  U5      n[        R                   " U5      nU$ )r   v1beta)api_version_overrideprojects)nameN)guestPolicyr-   
updateMask)$ReleaseTrackosconfig_api_utilsGetClientInstanceGetClientMessagesr   VALUEScoreproject	GetOrFail'OsconfigProjectsGuestPoliciesGetRequestosconfig_command_utilsGetGuestPolicyUriPath	POLICY_IDprojects_guestPoliciesGetr   "ConvertGuestPolicyToOpsAgentPolicyr	   UpdateOpsAgentsPolicydescriptionetagagent_rulesos_typesclear_group_labelsgroup_labelsclear_zoneszonesclear_instances	instancesr   ValidateOpsAgentsPolicyr   "ConvertOpsAgentPolicyToGuestPolicyrecipes)OsconfigProjectsGuestPoliciesPatchRequestPatch)selfargsrelease_trackclientmessagesr6   requestservicecurrent_guest_policycurrent_ops_agents_policyupdated_ops_agents_policyupdated_os_config_policycomplete_os_config_policycomplete_ops_agent_policys                 r%   RunUpdateAlphaBeta.Runo   s   %%'M11HF "33HH $$,,668G>>#99
 ? G
 ++G";;w/ K n n! !2 G G!		%%4+<+<DJJ""	!  77!  Kmm-A-I-I  @@,#99
  A G !(g 6 K n n!! %$r(    N
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr&   r\   __static_attributes__r^   r(   r%   r   r   (   s2    : % -D ' '0%r(   r   c                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
Update   a  Update a Google Cloud Observability agents policy for the Ops Agent.

*{command}* modifies 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 the modified policy or an error indicating
why the modification fails. The modified policy takes effect asynchronously.
It can take 10-15 minutes for the VMs to enforce the newly modified policy.
r   z
          To update a Google Cloud Observability agents policy, run:
            $ {command} agent-policy --project=PROJECT --zone=ZONE --file=config.yaml
          r   c                     U R                  S[        SS9  U R                  SSSS9  U R                  SSS	S9  U R                  S
SSSS9  g)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--fileTz          YAML file with a subset of agents policy fields you wish to update. For
          information about the agents policy format, see https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/agent-policies#config-files.)r    rm   z--zonez2          Zone where the agents policy is located.z--debug-dry-run
store_truezpIf provided, the resulting OSPolicyAssignment will be printed to standard output and no actual changes are made.)actionhiddenrm   N)add_argumentstrr$   s    r%   r&   Update.Args   s       
 _   6   ?  r(   c                    U R                  5       n[        R                  R                  R                  R                  5       n[        R                  " X!R                  X1R                  5      n[        R                  " UR                  5      n[        R                  " UUS9n[        R                   " U5        ["        R$                  " X1R                  5      n["        R&                  " XqR                  5      n[(        R*                  " U5      n	[,        R.                  " XS9n
UR0                  (       a  U
$ U	R3                  U
US9n[(        R4                  " U5      nUR6                  nUR9                  U5      n[:        R<                  " [>        R@                  [:        RB                  " URD                  5      5      n[F        RH                  " U5      nURK                  5       $ )r   )update_ops_agents_policyr	   )r-   r	   )oSPolicyAssignmentr-   )&r0   r   r4   r5   r6   r7   r   GetOpsAgentsPolicyFromApir;   zoner   	load_pathfiler   r?   r   rJ   r9   GetProjectLocationUriPath!GetOsPolicyAssignmentRelativePathr1   r3   to_os_policy_assignment*ConvertOpsAgentsPolicyToOSPolicyAssignmentdebug_dry_run8OsconfigProjectsLocationsOsPolicyAssignmentsPatchRequestr2   &projects_locations_osPolicyAssignmentsrN   r   PyValueToMessageosconfigOSPolicyAssignmentMessageToPyValueresponseto_ops_agents_policy/ConvertOsPolicyAssignmentToCloudOpsAgentsPolicy	ToPyValue)rO   rP   rQ   r6   rW   configupdated_policyparent_pathassignment_idrS   os_policy_assignmentupdate_requestrR   rU   update_responseupdated_os_policy_assignmentrX   s                    r%   r\   
Update.Run   s   %%'M$$,,668G 5 O O~~w		!
 ^^DII&F,BB!'3N &==nM(BBK +LL^^M "33MBH
 	 JJ	
 
 !! 	II3 	J 	
   11-@F;;GmmN3O $,#<#<##!!/":":;$  	LL(	
  %..00r(   r^   Nr_   r^   r(   r%   ri   ri      s2    	 %- " "H;1r(   ri   N)-rd   
__future__r   r   r   apitools.base.pyr   3googlecloudsdk.api_lib.compute.instances.ops_agentsr   r   r	   >googlecloudsdk.api_lib.compute.instances.ops_agents.convertersr
   r}   r   r   r   r   >googlecloudsdk.api_lib.compute.instances.ops_agents.validatorsr   r   (googlecloudsdk.api_lib.compute.os_configr   r1   googlecloudsdk.callioper   @googlecloudsdk.command_lib.compute.instances.ops_agents.policiesr   ,googlecloudsdk.command_lib.compute.os_configr9   googlecloudsdk.corer   r   1googlecloudsdk.generated_clients.apis.osconfig.v1r   r   ReleaseTracksr0   BETAALPHACommandr   UniverseCompatibleGAri   r^   r(   r%   <module>r      s    9 &  ' % W U Q ` v v ] l f P ( Y X * $ ^ D%%**D,=,=,C,CDv%dll v% Ev%r D%%(()u1T\\ u1 * u1r(   