
    ;                        S r SSKJr  SSKJr  SSKJr  SSK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 rS r\R6                  " \R8                  R:                  5       " S S\R<                  5      5       r\R6                  " \R8                  R@                  5       " S S\5      5       r!\R6                  " \R8                  RD                  5       " S S\!5      5       r#g)z(Command to submit a specified Batch job.    )absolute_import)division)unicode_literalsN)DecodeError)encoding)jobs)arg_parsers)base)resource_args)	arg_utils)
exceptions)log)yaml)filesc                    U R                  5       nUR                  SS[        SS9  UR                  SS[        SS9  UR                  SSS	S
S9  U R                  SS9nUR                  S[        R                  " 5       SS9  UR                  SSS9nUR                  SSS9nUR                  SSS9  UR                  S[        SS9  UR                  SS9nUR                  SSS9  UR                  SSS9  UR                  SSS9  U R                  S[        R
                  " S S!5      S"S9  U R                  S#S$S%S&.[        R                  S'S(9  U R                  S)[        S*S9  U R                  S+[        S,S9  U$ )-zRegister flags for this command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.

Returns:
  network_group flag groups.
z	--networkTzaThe URL for the network resource.
        Must specify subnetwork as well if network is specified)requiredtypehelpz--subnetworkzdThe URL for the subnetwork resource.
        Must specify network as well if subnetwork is specifiedz--no-external-ip-address
store_trueFzRequired if no external public IP address
        is attached to the VM. If no external public IP address,
        additional configuration is required to allow the VM
        to access Google Services.)actiondefaultr   )r   z--configzThe file path of the job config file in either JSON or YAML format.
        It also supports direct input from stdin with '-' or HereDoc
        (in shells with HereDoc support like Bash) with '- <<DELIMITER'. )r   r   zEither specify the config file for the job or
        the first runnable in the task spec. Specify either a script file or
        container arguments for the first runnable in the task spec.)mutexr   zaEither specify a path to a script file to run or provide
        inline text to execute directly.z--script-file-pathz{Path to script file to run as first runnable in task spec.
        File path should be a valid path on the instance volume.)r   z--script-textz+Text to run as first runnable in task spec.z[Options to specify the container arguments for the first
        runnable in the task spec.z--container-image-uriz)The URI to pull the container image from.z--container-entrypointz6Overrides the `ENTRYPOINT` specified in the container.z--container-commands-filezOverrides the `CMD` specified in the container. If there is an
      ENTRYPOINT (either in the container image or with the entrypoint field
      below) then commands are appended as arguments to the ENTRYPOINT.z
--priorityr   c   z-Job priority [0-99] 0 is the lowest priority.z--provisioning-modelz"The STANDARD VM provisioning modelzmThe SPOT VM provisioning model. Ideal for fault-tolerant
            workloads that can withstand preemption.)STANDARDSPOTz@Specify the allowed provisioning model for the compute instances)choicesr   r   z--machine-typezxSpecify the Compute Engine machine type, for
      example, e2-standard-4. Currently only one machine type is supported.z--job-prefixzSpecify the job prefix. A job ID in the format of
      job prefix + %Y%m%d-%H%M%S will be generated. Note that job prefix
      cannot be specified while JOB ID positional argument is
      specified.)	add_groupadd_argumentstrr	   FileContents
BoundedIntr   ChoiceToEnumName)parsernetwork_grouptask_spec_grouprunnable_groupscript_groupcontainer_groups          lib/surface/batch/jobs/submit.py_CommonArgsr*   #   sJ    ""$-C	   C	    &	   $$d$3/##%M   #,,H - .  )), * ,
 D  
 <   #,,& - / :   G   !K   	!!!R(:  
 	:8
 %%M  	 	O   	   
    c                 
   UR                   c  / Ul         UR                   (       d6  UR                   R                  SUR                  UR                  / S9S95        U R                  (       aW  UR                   S   R
                  R                  R                  SUR                  UR                  U R                  S9S95        U R                  (       aW  UR                   S   R
                  R                  R                  SUR                  UR                  U R                  S9S95        U R                  (       d"  U R                  (       d  U R                  (       a  / nU R                  (       a.  [        R                  " U R                  5      R                  5       nUR                   S   R
                  R                  R                  SUR                  UR!                  U R                  U R                  US9S	95        U R"                  (       a  U R"                  Ul        UR$                  cY  U R&                  (       d3  U R(                  (       a  U R*                  (       d  U R,                  (       a  UR/                  5       Ul        U R&                  (       a  UR$                  R0                  c  / UR$                  l        UR$                  R0                  (       d4  UR$                  R0                  R                  SUR3                  5       5        UR$                  R0                  S   R4                  c,  UR7                  5       UR$                  R0                  S   l        U R&                  UR$                  R0                  S   R4                  l        U R(                  (       a  U R*                  (       a  UR$                  R(                  c  UR;                  / S
9UR$                  l        UR$                  R(                  R<                  R                  SUR?                  U R(                  U R*                  U R@                  S95        U R,                  (       Ga#  UR$                  R0                  c  / UR$                  l        UR$                  R0                  (       d4  UR$                  R0                  R                  SUR3                  5       5        UR$                  R0                  S   R4                  c,  UR7                  5       UR$                  R0                  S   l        [B        RD                  " U R,                  UR6                  RF                  5      UR$                  R0                  S   R4                  l$        gg)zBuild the job API message from the args.

Args:
  args: the args from the parser.
  job_msg: the output job message.
  batch_msgs: the related version of the batch message.
Nr   )	runnables)taskSpec)path)script)text)
entrypointimageUricommands)	container)networkInterfaces)network
subnetworknoExternalIpAddress)%
taskGroupsinsert	TaskGroupTaskSpecscript_file_pathr.   r-   RunnableScriptscript_textcontainer_commands_filecontainer_image_uricontainer_entrypointr   ReadFileContents
splitlines	ContainerpriorityallocationPolicymachine_typer7   r8   provisioning_modelAllocationPolicy	instancesInstancePolicyOrTemplatepolicyInstancePolicymachineTypeNetworkPolicyr6   NetworkInterfaceno_external_ip_addressr   ChoiceToEnum ProvisioningModelValueValuesEnumprovisioningModel)argsjob_msg
batch_msgscontainer_cmdss       r)   _BuildJobMsgr\      sV    G				:)<)<r)<)JK 
q"",,33	$$$*?*?$@ 	 	
 
q"",,33	:j&7&7T=M=M&7&NO ""		!	!		"	"N##--

&
&
  q"",,33	 **4411' +  	 	
	 
]]}}G %

,,4??		 	 )::<G	))1+-g(##--((//
Z002 ))!,33;5?5N5N5Pg((+2?C?P?PG&&q)00<	\\doo''/)3)A)A *B *g& $$66==	##LL $ ; ; 	$ 	
 
))1+-g(##--((//
Z002 ))!,33;5?5N5N5Pg((+2##%%FF	
 &&q)00B r+   c                   D    \ rS rSrSr\S 5       r\S 5       rS r	S r
Srg)	Submit   *  Submit a Batch job.

This command creates and submits a Batch job. After you create and
submit the job, Batch automatically queues, schedules, and executes it.

## EXAMPLES

To submit a job with a sample JSON configuration file (config.json) and name
`projects/foo/locations/us-central1/jobs/bar`, run:

  $ {command} projects/foo/locations/us-central1/jobs/bar --config=config.json

To submit a job with a sample YAML configuration file (config.yaml) and
name projects/foo/locations/us-central1/jobs/bar, run:

  $ {command} projects/foo/locations/us-central1/jobs/bar --config=config.yaml

To submit a job through stdin with a sample job configuration and name
`projects/foo/locations/us-central1/jobs/bar`, run:

  $ {command} projects/foo/locations/us-central1/jobs/bar --config=-

    then input json job config via stdin
    {
      job config
    }

To submit a job through HereDoc with a sample job configuration and name
`projects/foo/locations/us-central1/jobs/bar`, run:

  $ {command} projects/foo/locations/us-central1/jobs/bar --config=- << EOF

    {
      job config
    }
    EOF

For details about how to define a job's configuration using JSON, see the
projects.locations.jobs resource in the Batch API Reference.
If you want to define a job's configuration using YAML, convert the JSON
syntax to YAML.
c                 F    [        U 5        [        R                  " U 5        g )N)r*   r   AddSubmitJobResourceArgs)r#   s    r)   ArgsSubmit.Args,  s    **62r+   c                 |    [         R                  " UR                  [        R                  " U5      5      nU$ ! [
        [        [        R                  4 ac     [         R                  " UR                  U5      n U$ ! [
        [        4 a*  n[        R                  " SR                  U5      5      eSnAff = ff = f)zParse into Job message using the config input.

Args:
     batch_msgs: Batch defined proto message.
     config: The input content being either YAML or JSON or the HEREDOC
       input.

Returns:
     The Parsed job message.
zUnable to parse config file: {}N)r   PyValueToMessageJobr   load
ValueErrorAttributeErrorYAMLParseErrorJsonToMessager   r   Errorformat)clsrZ   configresultes        r)   _CreateJobMessageSubmit._CreateJobMessage1  s    L((69JKf M (;(;< LL''
? M +& L@GGJKKLLs'   59 B;!A==B7%B22B77B;c                    UR                   R                  R                  5       nUR                  5       nU R	                  X!5      nU R                  5       n[        R                  " U5      nUR                  nUR                  5       nUR                  (       a  U R                  XqR                  5      n[        XU5        UR                  XCU5      n	[        R                  R!                  SR#                  U	R$                  S95        U	$ )Nz)Job {jobName} was successfully submitted.)jobName)CONCEPTSjobParseParent	_GetJobIdReleaseTrackr   
JobsClientmessagesrg   rp   rs   r\   Creater   statusPrintrn   uid)
selfrX   job_reflocation_refjob_idrelease_trackbatch_clientrZ   rY   resps
             r)   Run
Submit.RunF  s    mm%%'G>>#L^^G*F%%'M??=1L&&JnnG{{&&z;;?g
+vW=DJJ3::488:L Kr+   c                    UR                  5       R                  S5      S   nU[        R                  :w  a'  UR                  (       a  [
        R                  " S5      eUR                  (       a?  UR                  S-   [        R                  R                  5       R                  S5      -   nU$ U[        R                  :X  a  S nU$ )N/zM--job-prefix cannot be specified when JOB ID positional argument is specified-z%Y%m%d-%H%M%S)
RelativeNamesplitr   	INVALIDID
job_prefixr   rm   datetimenowstrftime)r   r   rX   r   s       r)   r{   Submit._GetJobId\  s    !!#))#.r2F(((T__"  

//!!#,,_=>  M 
=**	*fMr+    N)__name__
__module____qualname____firstlineno____doc__staticmethodrc   classmethodrs   r   r{   __static_attributes__r   r+   r)   r^   r^      s:    )V 3 3  (,r+   r^   c                       \ rS rSrSrSrg)
SubmitBetait  r`   r   Nr   r   r   r   r   r   r   r+   r)   r   r   t      )r+   r   c                       \ rS rSrSrSrg)SubmitAlphai  r`   r   Nr   r   r+   r)   r   r     r   r+   r   )$r   
__future__r   r   r   r   #apitools.base.protorpclite.messagesr   apitools.base.pyr   googlecloudsdk.api_lib.batchr   googlecloudsdk.callioper	   r
    googlecloudsdk.command_lib.batchr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr   r*   r\   ReleaseTracksr|   GACommandr^   BETAr   ALPHAr   r   r+   r)   <module>r      s    / &  '  ; % - / ( : : * # $ *tnbJ D%%(()qT\\ q *qh D%%**+* * ,*Z D%%++,** * -*r+   