
                            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 ddlmZ ddlmZ  ej@                  ejB                  jD                  ejB                  jF                         G d dejH                               Z%ejL                   ej@                  ejB                  jN                         G d dejP                                      Z)y)z2Implements command to delete an ops agents policy.    )absolute_import)division)unicode_literals)encoding)
exceptions)cloud_ops_agents_util)9os_policy_assignment_to_cloud_ops_agents_policy_converter)guest_policy_validator)utils)base)parser_utils)log)
properties)osconfig_v1_messagesc                   0    e Zd ZdZdddZed        Zd Zy)DeleteAlphaBetaa  Delete a Google Cloud's operations suite agents (Ops Agents) policy.

  *{command}* deletes 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 a response indicating whether the deletion succeeded.
  After a policy is deleted, it takes 10-15 minutes to be wiped from the
  applicable instances. Deleting a policy does not delete any existing agents
  managed by that policy, but the agents become unmanaged by any policies. To
  remove the agents from the
  instances, first update the policy to set the agent ``package-state'' to
  ``removed'', wait for the policy to take effect, then delete the policy.
  {description}z          To delete 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/delete.pyArgszDeleteAlphaBeta.Args?   s     v&    c                    | j                         }t        j                  |d      }t        j                  |d      }t        j
                  j                  j                  j                         }t        j                  d||j                        }|j                  }|j                  |      }	 |j                  |      }	t'        j(                  |	      s t#        j$                  |j                        |j+                  |      }
|j-                  |
      }t/        j0                  |j                         |S # t        j                   $ r! t#        j$                  |j                        w xY w)r   v1beta)api_version_overrideprojectsname)	policy_id)ReleaseTrackosconfig_api_utilsGetClientInstanceGetClientMessagesr   VALUEScoreproject	GetOrFailosconfig_command_utilsGetGuestPolicyUriPath	POLICY_IDprojects_guestPolicies'OsconfigProjectsGuestPoliciesGetRequestGetapitools_exceptionsHttpNotFoundErrorops_agents_exceptionsPolicyNotFoundErrorr
   IsOpsAgentPolicy*OsconfigProjectsGuestPoliciesDeleteRequestDeleter   DeletedResource)selfargsrelease_trackclientmessagesr,   guest_policy_uri_pathserviceget_requestget_responsedelete_requestdelete_responses               r   RunzDeleteAlphaBeta.RunD   sH   %%'M11HF "33HH $$,,668G2HHGT^^ ++GBB" C KP[[-l "22<@!55OOHH" I N nn^4O' 00 P!55OOPs   1D; ;4E/N__name__
__module____qualname____doc__detailed_helpstaticmethodr   rG    r   r   r   r   $   s1      %- ' 'r   r   c                   0    e Zd ZdZdddZed        Zd Zy)r:   a  Delete a Google Cloud Observability agents policy for the Ops Agent.

  *{command}* deletes a policy that facilitates agent management across
  Compute Engine instances based on user specified instance filters.

  The command returns a response indicating whether the deletion succeeded.
  After a policy is deleted, it takes 10-15 minutes to be wiped from the
  applicable instances. Deleting a policy does not delete any existing agents
  managed by that policy, but the agents become unmanaged by any policies. To
  remove the agents from the instances, first update the policy to set the
  agent ``packageState'' to ``removed'', wait for the policy to take effect,
  then delete the policy.

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

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

  If no policies are found, or the policy is not an agents policy, then the
  command returns a ``NOT_FOUND'' error.
  r   z          To delete 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   r0   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--zoneTz7          Zone of the agents policy you want to delete.)requiredrS   N)add_argumentstrr   s    r   r   zDelete.Args   sB       
 ;  r   c                    | j                         }t        j                  j                  j                  j                         }t        j                  ||j                  ||j                        }t        j                  ||j                        }t        j                  ||j                        }t        j                  |      }|j                  |      }t        j                   |      }	|	j"                  }
|
j%                  |      }t'        j(                  t*        j,                  t'        j.                  |j0                              }t3        j4                  |      }|j7                         S )r   r#   )r&   r   r*   r+   r,   r-   r   GetOpsAgentsPolicyFromApir0   zoner.   GetProjectLocationUriPath!GetOsPolicyAssignmentRelativePathr'   r)   9OsconfigProjectsLocationsOsPolicyAssignmentsDeleteRequestr(   &projects_locations_osPolicyAssignmentsr:   r   PyValueToMessageosconfigOSPolicyAssignmentMessageToPyValueresponseto_ops_agents_policy/ConvertOsPolicyAssignmentToCloudOpsAgentsPolicy	ToPyValue)r<   r=   r>   r,   _parent_pathassignment_idr@   rE   r?   rB   rF   delete_os_policy_assignmentops_agents_policys                 r   rG   z
Delete.Run   s;    %%'M$$,,668G77t~~w			A )BBK +LLT^^M "33MBHJJ 	K 	
   11-@F;;Gnn^4O #+";";##!!/":":;#
 	LL'	
 
 &&((r   NrH   rO   r   r   r:   r:   f   s1    8 %-  (()r   r:   N)*rL   
__future__r   r   r   apitools.base.pyr   r   r4   3googlecloudsdk.api_lib.compute.instances.ops_agentsr   r6   >googlecloudsdk.api_lib.compute.instances.ops_agents.convertersr	   rc   >googlecloudsdk.api_lib.compute.instances.ops_agents.validatorsr
   (googlecloudsdk.api_lib.compute.os_configr   r'   googlecloudsdk.callioper   @googlecloudsdk.command_lib.compute.instances.ops_agents.policiesr   ,googlecloudsdk.command_lib.compute.os_configr.   googlecloudsdk.corer   r   1googlecloudsdk.generated_clients.apis.osconfig.v1r   r_   ReleaseTracksr&   BETAALPHADeleteCommandr   UniverseCompatibleGACommandr:   rO   r   r   <module>r}      s    9 &  ' % > U c ] a P ( Y X # * ^ D%%**D,=,=,C,CD>d(( > E>B D%%(()c)T\\ c) * c)r   