
                            d Z ddlmZ ddlmZ ddlmZ ddl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d Ze	j*                   e	j,                  e	j.                  j0                  e	j.                  j2                  e	j.                  j4                         G d de	j6                                      Zy)z6gcloud service-extensions wasm-plugins create command.    )absolute_import)division)unicode_literalsN)wasm_plugin_api)base)
exceptions)flags)util)labels_util)logc                 b    | j                   yt        j                  | j                   d   |      S )aS  Converts the dict representation of the log_config to proto.

  Args:
    args: args with log_level parsed ordered dict. If log-level flag is set,
      enable option should also be set.
    api_version: API version (e.g. v1apha1)

  Returns:
    a value of messages.WasmPluginLogConfig or None,
    if log-level flag were not provided.
  Nr   )
log_configr
   GetLogConfig)argsapi_versions     5lib/surface/service_extensions/wasm_plugins/create.py_GetLogConfigr       s-     
__			4??1-{	;;    c                 6    | j                   xs | j                  S )N)plugin_configplugin_config_file)r   s    r   GetPluginConfigDatar   2   s    				6t666r   c                   p    e Zd ZdZ ej
                  d       ej
                  d      dZed        Zd Z	y)CreatezCreate a `WasmPlugin` resource.z4          Create a new `WasmPlugin` resource.
      a	            To create a `WasmPlugin` called `my-plugin`, together with a new
          version called `v1`, and set it as main, run:

          $ {command} my-plugin --main-version=v1
          --image=...-docker.pkg.dev/my-project/repository/container:tag
          )DESCRIPTIONEXAMPLESc                 f   t        j                  | j                               }t        j                  ||d       t
        j                  j                  |       t        j                  |       t        j                  |       t        j                  ||       t        j                  |d       y )Nz.The ID of the `WasmPlugin` resource to create.)parserr   messagezID of the `WasmPluginVersion` resource that will be created for that `WasmPlugin` and that will be set as the current main version.)r   version_message)r
   GetApiVersionReleaseTrackr	   AddWasmPluginResourcer   
ASYNC_FLAGAddToParserr   AddCreateLabelsFlagsAddDescriptionFlagAddLogConfigFlagAddWasmPluginVersionArgs)clsr   r   s      r   ArgszCreate.ArgsJ   s    $$S%5%5%78K	@ 	OO'$$V,	V$	6;/	""r   c           	      2   t        j                  | j                               }|j                  t	        j
                  dd      |j                  st	        j
                  dd      |j                  t	        j
                  dd      t        j                  | j                               }|j                  j                  j                         }t        j                  ||j                  j                  j                         }t#        ||      }|j%                  |j                  |j                  t'        |      |j(                        }|j+                  |j-                         j/                         |j1                         |j2                  |||j                  |      }t4        j6                  j9                  dj;                  |j1                                      |j<                  r:t4        j6                  j9                  dj;                  |j>                               |S |jA                  |d	j;                  |j>                        
      }	t4        j6                  j9                  dj;                  |j1                         |j                               |	S )Nz--main-versionz!Flag --main-version is mandatory.z$Flag --main-version cannot be empty.z--imagezFlag --image is mandatory.)parentnamedescriptionlabelsr   main_versionversionszCreate request issued for: [{}]z Check operation [{}] for status.z&Waiting for operation [{}] to complete)operation_refr   z4Created WasmPlugin [{}] with WasmPluginVersion [{}].)!r
   r!   r"   r1   calliope_exceptionsRequiredArgumentExceptionimager   ClientCONCEPTSwasm_pluginParser   ParseCreateArgsmessages
WasmPluginLabelsValuer   %PrepareVersionDetailsForSingleVersionr   plugin_config_uriCreateWasmPluginParentRelativeNameNamer/   r   statusPrintformatasync_r.   WaitForOperation)
selfr   r   	wp_clientwasm_plugin_refr0   r   r2   op_refresults
             r   Runz
Create.Runa   s7   $$T%6%6%89K 99
?  99
B  zz99
1   &&t'8'8':;Imm//557O((i  ++77F t[1J>>

D!	H ''%%'446!!#$$&& ( F JJ)001E1E1GH {{	jj9@@MNm''8??L ( F
 JJ>EE  "D$5$5	
 Mr   N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpclassmethodr+   rO    r   r   r   r   6   sQ    
 ( %X__ &
  "(// # 	-  ,:r   r   )rS   
__future__r   r   r   rT   )googlecloudsdk.api_lib.service_extensionsr   googlecloudsdk.callioper   r   r4   -googlecloudsdk.command_lib.service_extensionsr	   r
   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   DefaultUniverseOnlyReleaseTracksr"   ALPHABETAGACreateCommandr   rX   r   r   <module>re      s    = &  '  E ( E ? > < #<$7 T..33T5F5F5I5IaT a ar   