
    x                         S 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\
R                  5      rS r " S S\5      rg)z)Utilities for dealing with ML models API.    )absolute_import)division)unicode_literals)
list_pager)apis)
exceptions)
properties)	resourcesc                       \ rS rSrSrSrg)NoFieldsSpecifiedError   zEError indicating that no updates were requested in a Patch operation. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       .lib/googlecloudsdk/api_lib/ml_engine/models.pyr   r      s    Mr   r   c                     [         R                  R                  U S[        R                  R
                  R                  R                  0SS9$ )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                   X    \ rS rSrSrSS jr  SS jrS rS rS r	S	 r
S
 rSS jrSrg)ModelsClient'   z,High-level client for the ML models surface.Nc                     U=(       d    [         R                  " SS5      U l        U=(       d    U R                  R                  U l        g )Nmlv1)r   GetClientInstanceclientMESSAGES_MODULEmessages)selfr*   r,   s      r   __init__ModelsClient.__init__*   s1    >D224>DK; ; ;DMr   c                 l   [        U5      nU=(       d    / n[        R                  R                  UR                  SS9n	U R
                  R                  U	R                  5       U R
                  R                  UR                  5       UUUUUS9S9n
U R                  R                  R                  U
5      $ )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_namer2   enable_loggingenable_console_loggingr6   r5   	model_refregions_listproject_refreqs              r   r>   ModelsClient.Create.   s     J'I=bL$$**9+?+?6C + EK
--
5
5'')!]]??! $2+A# @  6 C ;;&&--c22r   c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ )N)resource)r*   r=   GetIamPolicyr,   #MlProjectsModelsGetIamPolicyRequestr:   )r-   rB   s     r   rI   ModelsClient.GetIamPolicy@   sB    ;;&&3399++- 	: 	/0 0r   c                     U R                   R                  UUS9nU R                  R                  R	                  U R                   R                  UUR                  5       S95      $ )N)policy
updateMask)googleIamV1SetIamPolicyRequestrH   )r,   GoogleIamV1SetIamPolicyRequestr*   r=   SetIamPolicy#MlProjectsModelsSetIamPolicyRequestr:   )r-   rB   rM   update_maskrequests        r   rQ   ModelsClient.SetIamPolicyE   sf    mm:: ;  G ;;&&3399+2++- 	: 	/0 0r   c                     [        U5      nU R                  R                  UR                  5       S9nU R                  R
                  R                  U5      $ )zDelete an existing model.r1   )r"   r,   MlProjectsModelsDeleteRequestr:   r*   r=   Deleter-   modelrB   rE   s       r   rY   ModelsClient.DeleteN   sL    E"I
--
5
5##% 6 'C;;&&--c22r   c                     [        U5      nU R                  R                  UR                  5       S9nU R                  R
                  R                  U5      $ )zGet details about a model.rW   )r"   r,   MlProjectsModelsGetRequestr:   r*   r=   GetrZ   s       r   r_   ModelsClient.GetU   sL    E"I
--
2
2##% 3 'C;;&&**3//r   c                     U R                   R                  UR                  5       S9n[        R                  " U R
                  R                  USSS9$ )zList models in the project.)r7   modelspageSize)fieldbatch_size_attribute)r,   MlProjectsModelsListRequestr:   r   YieldFromListr*   r=   )r-   rD   rE   s      r   ListModelsClient.List\   sP    
--
3
3'') 4 +C####'	) )r   c                    U R                   R                  5       n/ nUR                  (       a"  UR                  Ul        UR	                  S5        U(       a  X4l        UR	                  S5        U(       d  [        S5      eU R                   R                  UR                  5       USR                  U5      S9nU R                  R                  R                  U5      $ )zUpdate a model.r6   r5   zNo updates requested.,)r1   r8   rN   )r,   r;   needs_updater6   appendr5   r   MlProjectsModelsPatchRequestr:   joinr*   r=   Patch)r-   rB   labels_updater5   r[   rS   rE   s          r   rp   ModelsClient.Patchf   s    MM..0EK!!"))el"%'"#:;;
--
4
4##%"88K( 5 *C ;;&&,,S11r   )r*   r,   )NN)FFNN)N)r   r   r   r   r   r.   r>   rI   rQ   rY   r_   rh   rp   r   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>ry      sI    0 &  ' ' , * * )NZ-- N'R26 R2r   