
                             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 Z
d	 Zd
 Zd Zd Zd Zd Z	 ddZy)z('notebooks environments create' command.    )absolute_import)division)unicode_literals)util)log)	resourcesc                    fd}fd}| j                  d      r	 ||       }n ||       }j                  | j                  | j                  | j                  | j
                        }| j                  d      r	|_        |S |_        |S )zCreates the Environment message for the create request.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the Environment message.
  c                 V    j                  | j                  | j                        }|S )N)
repositorytag)ContainerImagecontainer_repositorycontainer_tag)argscontainer_imagemessagess     4lib/googlecloudsdk/api_lib/notebooks/environments.pyCreateContainerImageFromArgsz7CreateEnvironment.<locals>.CreateContainerImageFromArgs%   s0    --,,$2D2D . FO    c                     j                  | j                        }| j                  d      r| j                  |_        |S | j
                  |_        |S )N)projectvm_image_family)VmImagevm_image_projectIsSpecifiedr   imageFamilyvm_image_name	imageName)r   vm_imager   s     r   CreateVmImageFromArgsz0CreateEnvironment.<locals>.CreateVmImageFromArgs*   sZ    %%   'H)*!11h O  --hOr   r   )namedescriptiondisplayNamepostStartupScript)r   Environmentenvironmentr"   display_namepost_startup_scriptvmImagecontainerImage)r   r   r   r    r   r   r&   s    `     r   CreateEnvironmentr+      s    
 
()$T*H248O$$""##00	 % 2+
 
()"K 
 "1K	r   c                     t        j                  |       }t        | |      }|j                  ||| j                        S )N)parentr&   environmentId)r   GetParentForEnvironmentr+   3NotebooksProjectsLocationsEnvironmentsCreateRequestr&   )r   r   r-   r&   s       r   CreateEnvironmentCreateRequestr1   D   sF    ''-&!$1+		E	ED<L<L 
F 
N Nr   c                 P    t        j                  |       }|j                  |      S )N)r-   )r   GetParentFromArgs1NotebooksProjectsLocationsEnvironmentsListRequest)r   r   r-   s      r   CreateEnvironmentListRequestr5   K   s.    !!$'&		C	C 
D 
 r   c                 X    t        |       j                         }|j                  |      S N)r!   )GetEnvironmentResourceRelativeName3NotebooksProjectsLocationsEnvironmentsDeleteRequestr   r   r&   s      r   CreateEnvironmentDeleteRequestr<   Q   s1    &t,99;+		E	E 
F 
 r   c                 X    t        |       j                         }|j                  |      S r7   )r8   r9   0NotebooksProjectsLocationsEnvironmentsGetRequestr;   s      r    CreateEnvironmentDescribeRequestr?   W   s1    &t,99;+		B	B 
C 
 r   c                 J    | j                   j                  j                         S )N)CONCEPTSr&   Parse)r   s    r   r8   r8   ]   s    		"	"	(	(	**r   c                 x    t         j                  j                  | j                  d      }|j	                         S )Nz)notebooks.projects.locations.environments)
collection)r   REGISTRYParseRelativeNamer!   SelfLink)resourcer&   s     r   GetEnvironmentURIrI   a   s7    ""44mm K 5 M+				r   c                    |rt         j                  nt         j                  }|j                  rD |t	        j
                  | j                  |      dj                  |j                        d       | S t	        j                  | dj                  |j                  |rdnd| j                        |||      } |t	        j
                  | j                  |      dj                  |j                        d       |S )	z8Handles Long Running Operations for both cases of async.znotebooks environment {0}T)kindis_asyncz/Waiting for Environment [{}] to be {} with [{}]deletedcreated)servicerelease_track	is_deleteF)
r   DeletedResourceCreatedResourceasync_r   GetOperationResourcer!   formatr&   WaitForOperation)	operationr   environment_servicerP   rQ   logging_methodresponses          r   	HandleLROr\   g   s     +43&&9L9L.	[[!!)..-@(//0@0@A $$9@@9i)NN	 $#H !!)..-@(//0@0@A Or   N)F)__doc__
__future__r   r   r    googlecloudsdk.api_lib.notebooksr   googlecloudsdk.corer   r   r+   r1   r5   r<   r?   r8   rI   r\    r   r   <module>rb      sK    / &  ' 1 # )'TN+  	r   