
                             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 ej(                   G d dej*                               Zy)z7Command to create a specified Batch resource allowance.    )absolute_import)division)unicode_literals)DecodeError)encoding)resource_allowances)arg_parsers)base)resource_args)
exceptions)log)yamlc                   6    e Zd ZdZed        Zed        Zd Zy)Submitah  Create a Batch resource allowance.

  This command creates a Batch resource allowance.

  ## EXAMPLES

  The following command submit a resource allowance with config.json sample
  config file
  `projects/foo/locations/us-central1/resousrceAllowances/bar`:

    $ {command} projects/foo/locations/us-central1/resousrceAllowances/bar
    --config config.json
  c                 |    t        j                  |        | j                  dt        j                         dd       y )Nz--configTz(The config file of a resource allowance.)typerequiredhelp)r   &AddCreateResourceAllowanceResourceArgsadd_argumentr	   FileContents)parsers    /lib/surface/batch/resource_allowances/create.pyArgszSubmit.Args/   s8    88@
%%';	      c                 p   	 t        j                  |j                  t        j                  |            }|S # t
        t        t        j                  f$ r` 	 t        j                  |j                  |      }Y |S # t
        t        f$ r)}t        j                  dj                  |            d}~ww xY ww xY w)a  Parse into ResourceAllowance 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 resource allowance message.
    zUnable to parse config file: {}N)r   PyValueToMessageResourceAllowancer   load
ValueErrorAttributeErrorYAMLParseErrorJsonToMessager   r   Errorformat)cls
batch_msgsconfigresultes        r   _CreateResourceAllowanceMessagez&Submit._CreateResourceAllowanceMessage:   s    L((

&
&		&(9f M (;(;< LL''
(D(DfM M +& L@GGJKKLLs'   37 B5 A99B1$B,,B11B5c                 F   |j                   j                  j                         }|j                         }|j	                         j                  d      d   }|t        j                  k(  rd }| j                         }t        j                  |      }|j                  }|j                         }|j                  r| j                  ||j                        }|j                  |||      }	t         j"                  j%                  dj'                  |	j(                               |	S )N/zCResourceAllowance {resourceAllowanceName} was successfully created.)resourceAllowanceName)CONCEPTSresource_allowanceParseParentRelativeNamesplitr   	INVALIDIDReleaseTrackr   ResourceAllowancesClientmessagesr   r(   r+   Creater   statusPrintr%   uid)
selfargsresource_allowance_reflocation_refresource_allowance_idrelease_trackbatch_clientr'   resource_allowance_msgresps
             r   Runz
Submit.RunQ   s    !]]==CCE)002L2??AGGLRP  7 77"%%'M&??NL&&J'99;{{#CC
dkk  |-CD JJM	dhh	/ Kr   N)	__name__
__module____qualname____doc__staticmethodr   classmethodr+   rG    r   r   r   r      s4        ,r   r   N)rK   
__future__r   r   r   #apitools.base.protorpclite.messagesr   apitools.base.pyr   googlecloudsdk.api_lib.batchr   googlecloudsdk.callioper	   r
    googlecloudsdk.command_lib.batchr   googlecloudsdk.corer   r   r   DefaultUniverseOnlyCommandr   rN   r   r   <module>rX      sV    > &  ' ; % < / ( : * # $ MT\\ M Mr   