
    t(                     ,   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&  \RN                  " \RP                  RR                  \RP                  RT                  5       " S S\RV                  5      5       r,\RZ                  \RN                  " \RP                  R\                  5       " S S\RV                  5      5       5       r/g)z2Implements command to create an ops agents policy.    )absolute_import)division)unicode_literals)encoding)cloud_ops_agents_policy)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	)
CreateAlphaBeta)   a	  Create a Google Cloud's operations suite agents (Ops Agents) policy.

*{command}* creates 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 created policy or an error indicating
why the creation fails. The created policy takes effect asynchronously. It
can take 10-15 minutes for the VMs to enforce the newly created policy.
{description}a`            To create a policy named ``ops-agents-test-policy'' that targets a
          single CentOS 7 VM instance named
          ``zones/us-central1-a/instances/test-instance'' for testing or
          development and installs 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" --description="A test policy." --os-types=short-name=centos,version=7 --instances=zones/us-central1-a/instances/test-instance

          To create a policy named ``ops-agents-prod-policy'' that targets all
          CentOS 7 VMs in zone ``us-central1-a'' with either
          ``env=prod,product=myapp'' or ``env=staging,product=myapp'' labels
          and makes 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" --description="A prod policy." --os-types=short-name=centos,version=7 --zones=us-central1-a --group-labels="env=prod,product=myapp;env=staging,product=myapp"

          To create a policy named ``ops-agents-prod-policy'' that targets all
          CentOS 7 VMs in zone ``us-central1-a'' with either
          ``env=prod,product=myapp'' or ``env=staging,product=myapp'' labels
          and makes sure the ops-agent version is pinned
          to specific major versions for staging and production, run:

          $ {command} ops-agents-prod-policy --agent-rules="type=ops-agent,version=1.*.*,enable-autoupgrade=false" --description="A prod policy." --os-types=short-name=centos,version=7 --zones=us-central1-a --group-labels="env=prod,product=myapp;env=staging,product=myapp"
          DESCRIPTIONEXAMPLESc                     [         R                  " U 5        [         R                  " U 5        [         R                  " U 5        g)See base class.N)r   AddSharedArgsAddMutationArgsAddCreateArgsparsers    ;lib/surface/compute/instances/ops_agents/policies/create.pyArgsCreateAlphaBeta.ArgsS   s.     v&  (v&    c                    U R                  5       n[        R                  " USS9n[        R                  " USS9n[        R
                  " UR                  UR                  UR                  UR                  UR                  UR                  5      n[        R                  " U5        [        R                  " XE5      n[         R"                  R$                  R&                  R)                  5       n[*        R,                  " U5      nUR/                  UUR0                  US9n	UR2                  n
U
R5                  U	5      n[6        R8                  " U5      nU$ )r   v1beta)api_version_override)guestPolicyguestPolicyIdparent)ReleaseTrackosconfig_api_utilsGetClientInstanceGetClientMessagesagent_policyCreateOpsAgentPolicydescriptionagent_rulesgroup_labelsos_typeszones	instances	validatorValidateOpsAgentsPolicyto_guest_policy"ConvertOpsAgentPolicyToGuestPolicyr   VALUEScoreproject	GetOrFailosconfig_command_utilsGetProjectUriPath*OsconfigProjectsGuestPoliciesCreateRequest	POLICY_IDprojects_guestPoliciesCreateto_ops_agents"ConvertGuestPolicyToOpsAgentPolicy)selfargsrelease_trackclientmessagesr   guest_policyr?   parent_pathrequestservicecomplete_guest_policys               r#   RunCreateAlphaBeta.RunZ   s2    %%'M11HF "33HH %99

 %%&78"EEL $$,,668G(::7CKAA nn B G
 ++G#NN73%HH r&    N
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr$   rS   __static_attributes__rU   r&   r#   r   r   )   s1    	 %-: ' '"r&   r   c                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
rF      a  Create a Google Cloud Observability agents policy for the Ops Agent.

*{command}* creates 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 created policy or an error indicating
why the creation fails. The created policy takes effect asynchronously. It
can take 10-15 minutes for the VMs to enforce the newly created policy.
r   z
          To create 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   rD   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 agents policy to create. For
          information about the agents policy format, see https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/agent-policies#config-files.)requiredrc   z--zonez4          Zone in which to create the agents policy.z--debug-dry-run
store_truezpIf provided, the resulting OSPolicyAssignment will be printed to standard output and no actual changes are made.)hiddenactionrc   N)add_argumentstrr!   s    r#   r$   Create.Args   s       
 _   8   ?  r&   c                    [         R                  " UR                  5      n[        R                  " UR
                  U5      n[        R                  " U5        [        R                  R                  R                  R                  5       n[        R                  " XAR                  5      n[        R                   " XQR
                  5      n["        R$                  " Xc5      nUR&                  (       a  U$ U R)                  5       n[*        R,                  " U5      n	U	R/                  UUR
                  US9n
[*        R0                  " U5      nUR2                  nUR5                  U
5      n[6        R8                  " UR:                  5      n[6        R<                  " [>        R@                  U5      n[B        RD                  " U5      nURG                  5       $ )r   )oSPolicyAssignmentosPolicyAssignmentIdr,   )$r   	load_pathfiler   CreateOpsAgentsPolicyrD   r   r:   r   r=   r>   r?   r@   rA   GetProjectLocationUriPathzone!GetOsPolicyAssignmentRelativePathto_os_policy_assignment*ConvertOpsAgentsPolicyToOSPolicyAssignmentdebug_dry_runr-   r.   r0   9OsconfigProjectsLocationsOsPolicyAssignmentsCreateRequestr/   &projects_locations_osPolicyAssignmentsrF   r   MessageToPyValueresponsePyValueToMessageosconfigOSPolicyAssignmentto_cloud_ops_agents/ConvertOsPolicyAssignmentToCloudOpsAgentsPolicy	ToPyValue)rI   rJ   configr   r?   rO   assignment_idops_policy_assignmentrK   rM   rP   rL   rQ   rz   !complete_os_policy_assignment_objcomplete_os_policy_assignmentpolicys                    r#   rS   
Create.Run   s    ^^DII&F 0EE  &==>OP$$,,668G(BBK +LL^^M
 	 JJ	
 
 ""%%'M!33MBH 	JJ4!% 	K 	
   11-@F;;G~~g&H(0(A(A)% %-$=$=##%F%! !PP%F r&   rU   NrV   rU   r&   r#   rF   rF      s2    	 %- " "H7r&   rF   N)0r[   
__future__r   r   r   apitools.base.pyr   3googlecloudsdk.api_lib.compute.instances.ops_agentsr   r   r1   >googlecloudsdk.api_lib.compute.instances.ops_agents.convertersr	   rt   r
   rG   r   r;   r   r~   >googlecloudsdk.api_lib.compute.instances.ops_agents.validatorsr   r   r9   (googlecloudsdk.api_lib.compute.os_configr   r.   googlecloudsdk.callioper   @googlecloudsdk.command_lib.compute.instances.ops_agents.policiesr   ,googlecloudsdk.command_lib.compute.os_configrA   googlecloudsdk.corer   r   1googlecloudsdk.generated_clients.apis.osconfig.v1r   r|   ReleaseTracksr-   BETAALPHACommandr   UniverseCompatibleGArF   rU   r&   r#   <module>r      s   " 9 &  ' % W a ` H J \ l s P ( Y X * $ ^ D%%**D,=,=,C,CDRdll R ERj D%%(()qT\\ q * qr&   