
                         b   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 Z e
j&                  e
j(                  j*                  e
j(                  j,                  e
j(                  j.                         G d de
j0                               Zy)z2gcloud dns response-policies rules create command.    )absolute_import)division)unicode_literals)util)apis)base)
exceptions)flags)resource_args)logc                     t        j                         j                  |        t        j                         j                  |        t        j                         j                  |        | j                  ddd       y)z+Adds the common arguments for all versions.z
--dns-nameTz3DNS name (wildcard or exact) to apply this rule to.)requiredhelpN)r
   GetLocalDataResourceRecordSetsAddToParserGetResponsePolicyRulesBehaviorGetLocationArgadd_argument)parsers    1lib/surface/dns/response_policies/rules/create.py_AddArgsCommonr      sd    &&(44V<&&(44V<$$V,@  B    c                   6    e Zd ZdZed        Zed        Zd Zy)Createa>  Creates a new Cloud DNS response policy rule.

      ## EXAMPLES

      To create a new response policy rule with local data rrsets, run:

        $ {command} myresponsepolicyrule --response-policy="myresponsepolicy"
        --dns-name="www.zone.com."
        --local-data=name=www.zone.com.,type=CNAME,ttl=21600,rrdatas=zone.com.

      To create a new response policy rule with behavior, run:

        $ {command} myresponsepolicyrule --response-policy="myresponsepolicy"
        --dns-name="www.zone.com." --behavior=bypassResponsePolicy

      To create a new response policy rule with behavior in a zonal response
      policy in us-east1-a, run:

        $ {command} myresponsepolicyrule --response-policy="myresponsepolicy"
        --dns-name="www.zone.com." --behavior=bypassResponsePolicy
        --location=us-east1-a
  c                     | j                         t        j                   j                  t        j                   j                  fv S )N)ReleaseTrackr   BETAALPHA)clss    r   _BetaOrAlphazCreate._BetaOrAlphaF   s:    $"3"3"8"8"&"3"3"9"9"; ; ;r   c                     t        j                  | j                               }t        |       t	        j
                  |d|       |j                  j                  d       y )Nz	to create)verbapi_versionjson)r   GetApiFromTrackr   r   r   AddResponsePolicyRuleArgdisplay_info	AddFormat)r   r   r#   s      r   ArgszCreate.ArgsK   sL    &&s'7'7'9:K6**[k;
!!&)r   c           	         t        j                  | j                         |      }t        j                  |      }t	        j
                  d|      }t        j                  |      }|j                  |j                  t        j                  ||d      d      }|j                         }|j                  |      }|j                  |_        |j                  d      r&|j                  d      rt        j                   d	      |j                  d      rt#        j$                  ||      |_        n|j                  d      rg }	|j(                  D ]s  }
|j+                  |
j-                  d
      |
j-                  d      |
j-                  d      |
j-                  d      j/                  d            }|	j1                  |       u |j3                  |	      }||_        |j7                  |j8                  |j:                  |      }|dk(  r|j<                  |_        |j>                  jA                  |      }tC        jD                  |d       |S )NdnsresponsePolicies)parentzdns.responsePolicyRules)
collection)ruleNamebehavior
local_dataz<Only one of arguments [--behavior, --local-data] is allowed.nametypettlrrdatas|)r2   r3   r4   r5   )
localDatas)responsePolicyprojectresponsePolicyRulev2ResponsePolicyRule)kind)#r   GetApiFromTrackAndArgsr   GetApiClientr   GetMessagesModuleGetRegistryParseresponse_policy_ruleGetParamsForRegistryNamer<   dns_namednsNameIsSpecifiedr	   ConflictingArgumentsExceptioncommand_util ParseResponsePolicyRulesBehaviorr0   r1   ResourceRecordSetgetsplitappendResponsePolicyRuleLocalData	localData#DnsResponsePolicyRulesCreateRequestresponse_policyr9   locationresponsePolicyRulesr   r   CreatedResource)selfargsr#   clientmessagesregistryresponse_policy_rule_refresponse_policy_rule_namerC   rrsetsrrsetresource_record_setr1   create_requestresults                  r   Runz
Create.RunS   s+   --d.?.?.A4HK{+F%%e[9H ,H'~~!!!!+t<NO,  .  . !9 = = ?#66* 7 , $(== 
#(8(8(F44
HJ J 
#&2&S&S
'#			,	'f??%&886"6"		% IIi(..s3	 9 5
 	)* # 77 8 j'1$AA++(00/ B 1N
 d $n''..~>F07KLMr   N)__name__
__module____qualname____doc__classmethodr    r)   rc    r   r   r   r   ,   s4    . ; ; * *3r   r   N)rg   
__future__r   r   r   googlecloudsdk.api_lib.dnsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r	   googlecloudsdk.command_lib.dnsr
   r   rJ   googlecloudsdk.corer   r   ReleaseTracksr   r   r   GAUpdateCommandr   ri   r   r   <module>rs      s    9 &  ' + , ( . 0 8 ? #
B D%%++T->->-C-C%%((*XT X*Xr   