
    x                         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  G d
 de
j                        Zd Z G d de      Zy)z)Utilities for dealing with ML models API.    )absolute_import)division)unicode_literals)
list_pager)apis)
exceptions)
properties)	resourcesc                       e Zd ZdZy)NoFieldsSpecifiedErrorzEError indicating that no updates were requested in a Patch operation.N)__name__
__module____qualname____doc__     .lib/googlecloudsdk/api_lib/ml_engine/models.pyr   r      s    Mr   r   c                     t         j                  j                  | dt        j                  j
                  j                  j                  id      S )N
projectsIdzml.projects.models)params
collection)r
   REGISTRYParser	   VALUEScoreproject	GetOrFail)model_ids    r   _ParseModelr       sF    				!	!J--22::DDE% 
" 
' 'r   c                   J    e Zd ZdZddZ	 	 ddZd Zd Zd Zd Z	d	 Z
dd
Zy)ModelsClientz,High-level client for the ML models surface.Nc                     |xs t        j                  dd      | _        |xs | j                  j                  | _        y )Nmlv1)r   GetClientInstanceclientMESSAGES_MODULEmessages)selfr&   r(   s      r   __init__zModelsClient.__init__*   s1    >D224>DK; ; ;DMr   c                 t   t        |      }|xs g }t        j                  j                  |j                  d      }	| j
                  j                  |	j                         | j
                  j                  |j                         |||||            }
| j                  j                  j                  |
      S )zCreate a new model.zml.projects)r   )nameregionsonlinePredictionLoggingonlinePredictionConsoleLoggingdescriptionlabels)parentgoogleCloudMlV1Model)r   r
   r   r   r   r(   MlProjectsModelsCreateRequestRelativeNameGoogleCloudMlV1ModelNamer&   projects_modelsCreate)r)   
model_namer-   enable_loggingenable_console_loggingr1   r0   	model_refregions_listproject_refreqs              r   r9   zModelsClient.Create.   s     J'I=bL$$**9+?+?6C + EK
--
5
5'')!]]??! $2+A# @  6 C ;;&&--c22r   c                     | j                   j                  j                  | j                  j	                  |j                                     S )N)resource)r&   r8   GetIamPolicyr(   #MlProjectsModelsGetIamPolicyRequestr5   )r)   r=   s     r   rC   zModelsClient.GetIamPolicy@   sB    ;;&&3399++- 	: 	/0 0r   c                     | j                   j                  ||      }| j                  j                  j	                  | j                   j                  ||j                                     S )N)policy
updateMask)googleIamV1SetIamPolicyRequestrB   )r(   GoogleIamV1SetIamPolicyRequestr&   r8   SetIamPolicy#MlProjectsModelsSetIamPolicyRequestr5   )r)   r=   rF   update_maskrequests        r   rJ   zModelsClient.SetIamPolicyE   sf    mm:: ;  G ;;&&3399+2++- 	: 	/0 0r   c                     t        |      }| j                  j                  |j                               }| j                  j
                  j                  |      S )zDelete an existing model.r,   )r   r(   MlProjectsModelsDeleteRequestr5   r&   r8   Deleter)   modelr=   r@   s       r   rQ   zModelsClient.DeleteN   sL    E"I
--
5
5##% 6 'C;;&&--c22r   c                     t        |      }| j                  j                  |j                               }| j                  j
                  j                  |      S )zGet details about a model.rO   )r   r(   MlProjectsModelsGetRequestr5   r&   r8   GetrR   s       r   rV   zModelsClient.GetU   sL    E"I
--
2
2##% 3 'C;;&&**3//r   c                     | j                   j                  |j                               }t        j                  | j
                  j                  |dd      S )zList models in the project.)r2   modelspageSize)fieldbatch_size_attribute)r(   MlProjectsModelsListRequestr5   r   YieldFromListr&   r8   )r)   r?   r@   s      r   ListzModelsClient.List\   sP    
--
3
3'') 4 +C####'	) )r   c                    | j                   j                         }g }|j                  r"|j                  |_        |j	                  d       |r||_        |j	                  d       |st        d      | j                   j                  |j                         |dj                  |            }| j                  j                  j                  |      S )zUpdate a model.r1   r0   zNo updates requested.,)r,   r3   rG   )r(   r6   needs_updater1   appendr0   r   MlProjectsModelsPatchRequestr5   joinr&   r8   Patch)r)   r=   labels_updater0   rS   rL   r@   s          r   re   zModelsClient.Patchf   s    MM..0EK!!"))el"%e'"#:;;
--
4
4##%"88K( 5 *C ;;&&,,S11r   )NN)FFNN)N)r   r   r   r   r*   r9   rC   rJ   rQ   rV   r^   re   r   r   r   r!   r!   '   s5    4< 8=DH3$0
030)2r   r!   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r	   r
   Errorr   r   objectr!   r   r   r   <module>rm      sI    0 &  ' ' , * * )NZ-- N'R26 R2r   