
    59                        d 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 ej                  fd
Zej"                   ej$                  ej&                  j(                         G d dej*                                      Z ej$                  ej&                  j.                         G d de             Z ej$                  ej&                  j2                         G d de             Zy)Update a Filestore instance.    N)filestore_client)base)
exceptions)dp_util)flags)labels_util)logc                 0    t        j                  | |       y N)instances_flagsAddInstanceUpdateArgs)parserapi_versions     )lib/surface/filestore/instances/update.py_CommonArgsr      s    ''<    c                   h    e Zd ZdZej
                  Zd ej                  d      dZ	e
d        Zd Zy)Updater   Y      The following command updates the Filestore instance NAME to change the
    description to "A new description."

      $ {command} NAME --description="A new description."

    The following command updates a Filestore instance named NAME to add the label
    "key1=value1" and remove any metadata with the label "key2".

      $ {command} NAME --update-labels=key1=value1 --remove-labels=key2

      $ {command} NAME --zone=ZONE --flags-file=FILE_PATH

    Example json configuration file:
      {
      "--file-share":
      {
        "capacity": "102400",
        "name": "my_vol",
        "nfs-export-options": [
          {
            "access-mode": "READ_WRITE",
            "ip-ranges": [
              "10.0.0.0/29",
              "10.2.0.0/29"
            ],
            "squash-mode": "ROOT_SQUASH",
            "anon_uid": 1003,
            "anon_gid": 1003
          }
        ]
      }
      }


    The following command updates a Filestore instance named NAME to change the
    capacity to CAPACITY.

      $ {command} NAME --project=PROJECT_ID --zone=ZONE        --file-share=name=VOLUME_NAME,capacity=CAPACITY

    The following command updates a Filestore instance named NAME to configure the
    max-iops-per-tb to MAX-IOPS-PER-TB.

      $ {command} NAME --project=PROJECT_ID --zone=ZONE        --performance=max-iops-per-tb=MAX-IOPS-PER-TB
    DESCRIPTIONEXAMPLESc                 8    t        | t        j                         y r   )r   r   _API_VERSIONr   s    r   ArgszUpdate.Args\   s    ++,r   c                    |j                   j                  j                         }t        j                  | j
                        }t        j                  j                  |      }t        j                  |       |j                  |      }	 |j                  r7|j                  |j                  |j                  j                  dg              |j)                         rI|j+                  |j                  j,                  j.                  |j0                        j3                         }nd}	 |j5                  ||j6                  ||j                  |j8                  |j:                  |j<                  |j>                  |j@                  |jB                  
      }g }
|jK                  d      r|
jM                  d       |jK                  d	      s"|jK                  d
      s|jK                  d      r|
jM                  d       |jK                  d      r|
jM                  d       |jK                  d      r|
jM                  d       |
t        jN                  |      z  }
|jK                  d      s|jK                  d      r|
jM                  d       djQ                  |
      }|jS                  ||||jT                        }|jT                  r8tV        jX                  j[                  dj]                  |j^                               |S # t         $ r$}t#        j$                  dt'        |            d}~ww xY w# t        jD                  $ r$}	t#        j$                  dt'        |	            d}	~	wt        jF                  $ r$}	t#        j$                  dt'        |	            d}	~	wt        jH                  $ r$}	t#        j$                  dt'        |	            d}	~	ww xY w)Runs command line arguments.

    Args:
      args: Command line arguments.

    Returns:
       The client instance.

    Raises:
       InvalidArgumentException: For invalid JSON formatted --file-args.
    nfs-export-optionsmessagesnfs_export_options--file-shareN)	descriptionlabels
file_shareperformanceldapdisconnect_ldapclear_nfs_export_optionsdeletion_protection_enableddeletion_protection_reason--disconnect-ldap--disconnect-managed-adr%   update_labelsremove_labelsclear_labelsr&   r'   
fileSharesr(   performanceConfigr)   r*   directoryServices,zSTo check the status of the operation, run `gcloud filestore operations describe {}`)0CONCEPTSinstanceParser   FilestoreClientr   r	   DiffFromUpdateArgsr   $ValidateDeletionProtectionUpdateArgsGetInstancer'   MakeNFSExportOptionsMsgr"   getKeyErrorr   InvalidArgumentExceptionstrMayHaveUpdatesApplyInstanceLabelsValuer&   	GetOrNoneParseUpdatedInstanceConfigr%   r(   r)   r*   r+   deletion_protectionr-   InvalidDisconnectLdapErrorInvalidDisconnectManagedADErrorErrorIsSpecifiedappendGetDeletionProtectionUpdateMaskjoinUpdateInstanceasync_r
   statusPrintformatnameselfargsinstance_refclientlabels_difforig_instanceerrr&   r8   eupdated_fieldsupdate_maskresults                r   Runz
Update.Run`   s?    ==))//1L--d.?.?@F""11$7K006&&|4M		&&__#223GL 	' 	
 !!#  
//
"
"
.
.0D0D	  f22
&&__&&yy..#'#@#@&*&>&>%)%D%D 3 h2 N&M*)O,N+H%%L)&/0g==dCCN4#3#34E#F/0((>*K""hT[[F {{	jj$$*F6;;$7 MA  //
#c( 2 66 //
s1v  ;; //
#SV  !! //
#a& sJ   
AL  )A+L0  	L-	L((L-0OM""O8NO-OON)__name__
__module____qualname____doc__r   V1_API_VERSIONr   textwrapdedentdetailed_helpstaticmethodr   rd    r   r   r   r       sL     %!00, )
(// . .		3-j - -Yr   r   c                   h    e Zd ZdZej
                  Zd ej                  d      dZ	e
d        Zd Zy)UpdateAlphar   ao      The following command updates the Filestore instance NAME to change the
    description to "A new description."

      $ {command} NAME --description="A new description."

    The following command updates a Filestore instance named NAME to add the label
    "key1=value1" and remove any metadata with the label "key2".

      $ {command} NAME --update-labels=key1=value1 --remove-labels=key2

      $ {command} NAME --zone=ZONE --flags-file=FILE_PATH

    Example json configuration file:
      {
      "--file-share":
      {
        "capacity": "102400",
        "name": "my_vol",
        "nfs-export-options": [
          {
            "access-mode": "READ_WRITE",
            "ip-ranges": [
              "10.0.0.0/29",
              "10.2.0.0/29"
            ],
            "squash-mode": "ROOT_SQUASH",
            "anon_uid": 1003,
            "anon_gid": 1003
          }
        ]
      }
      }


    The following command updates a Filestore instance named NAME to change the
    capacity to CAPACITY.

      $ {command} NAME --project=PROJECT_ID --zone=ZONE        --file-share=name=VOLUME_NAME,capacity=CAPACITY
    r   c                 8    t        | t        j                         y r   )r   rp   r   r   s    r   r   zUpdateAlpha.Args   s    001r   c                 b   |j                   j                  j                         }t        j                  | j
                        }t        j                  j                  |      }|j                  |      }	 |j                  r7|j                  |j                  |j                  j                  dg              |j%                         rI|j'                  |j                  j(                  j*                  |j,                        j/                         }nd}	 |j1                  ||j2                  ||j                  |j4                        }g }
|j9                  d      r|
j;                  d       |j9                  d      s"|j9                  d      s|j9                  d	      r|
j;                  d
       |j9                  d      r|
j;                  d       dj=                  |
      }|j?                  ||||j@                        }|j@                  r8tB        jD                  jG                  djI                  |jJ                               |S # t        $ r$}t        j                   dt#        |            d}~ww xY w# t        j6                  $ r$}	t        j                   dt#        |	            d}	~	ww xY w)r   r    r!   r$   N)r%   r&   r'   r+   r%   r0   r1   r2   r&   r'   r3   r6   zYTo check the status of the operation, run `gcloud alpha filestore operations describe {}`)&r7   r8   r9   r   r:   r   r	   r;   r<   r>   r'   r?   r"   r@   rA   r   rB   rC   rD   rE   rF   rG   r&   rH   rI   r%   r+   rM   rN   rO   rQ   rR   rS   r
   rT   rU   rV   rW   rX   s                r   rd   zUpdateAlpha.Run   sO    ==))//1L--d.?.?@F""11$7K&&|4M		&&__#223GL 	' 	
 !!#  
//
"
"
.
.0D0D	  f22
&&__#'#@#@ 3 h N&M*)O,N+H%%L)((>*K""hT[[F {{	jj$$*F6;;$7 M]  //
#c( ( !! //
#a& s1   5AI 4I7 	I4I//I47J.
J))J.N)re   rf   rg   rh   r   ALPHA_API_VERSIONr   rj   rk   rl   rm   r   rd   rn   r   r   rp   rp      sJ    $!33, )
(// ( (		--^ 2 2Fr   rp   c                   h    e Zd ZdZej
                  Zd ej                  d      dZ	e
d        Zd Zy)
UpdateBetar   r   r   c                 8    t        | t        j                         y r   )r   ru   r   r   s    r   r   zUpdateBeta.Argsx  s     
//0r   c                    |j                   j                  j                         }t        j                  | j
                        }t        j                  j                  |      }t        j                  |       |j                  |      }	 |j                  r7|j                  |j                  |j                  j                  dg              |j)                         rI|j+                  |j                  j,                  j.                  |j0                        j3                         }nd}	 |j5                  ||j6                  ||j                  |j8                  |j:                  |j<                  |j>                  |j@                  |jB                  |jD                  |jF                        }g }	|jO                  d      r|	jQ                  d       |jO                  d	      s"|jO                  d
      s|jO                  d      r|	jQ                  d       |jO                  d      r|	jQ                  d       |jO                  d      r|	jQ                  d       |jO                  d      s3|jO                  d      s"|jO                  d      s|jO                  d      r|	jQ                  d       |	t        jR                  |      z  }	djU                  |	      }
|jW                  |||
|jX                        }|jX                  r8tZ        j\                  j_                  dja                  |jb                               |S # t         $ r$}t#        j$                  dt'        |            d}~ww xY w# t        jH                  $ r$}t#        j$                  dt'        |            d}~wt        jJ                  $ r$}t#        j$                  dt'        |            d}~wt        jL                  $ r$}t#        j$                  dt'        |            d}~ww xY w)a  Runs a command line string arguments.

    Args:
      args: cmd line string arguments.

    Returns:
       client: A FilestoreClient instance.

    Raises:
       InvalidArgumentException: for invalid JSON formatted --file-args.
       KeyError: for key errors in JSON values.
    r    r!   r$   N)r%   r&   r'   r(   
managed_addisconnect_managed_adr)   r*   r+   r,   r-   r.   r/   r%   r0   r1   r2   r&   r'   r3   r(   r4   rx   ry   r)   r*   r5   r6   zXTo check the status of the operation, run `gcloud beta filestore operations describe {}`)2r7   r8   r9   r   r:   r   r	   r;   r<   r   r=   r>   r'   MakeNFSExportOptionsMsgBetar"   r@   rA   r   rB   rC   rD   rE   rF   rG   r&   rH   rI   r%   r(   rx   ry   r)   r*   r+   rJ   r-   rK   rL   rM   rN   rO   rP   rQ   rR   rS   r
   rT   rU   rV   rW   )rY   rZ   r[   r\   r]   r^   r`   r&   r8   ra   rb   rc   s               r   rd   zUpdateBeta.Run}  sm    ==))//1L--d.?.?@F""11$7K006&&|4M		**__#223GL 	+ 	
 !!#  
//
"
"
.
.0D0D	  f22
&&__&&__ $ : :yy..#'#@#@&*&>&>%)%D%D 3 h6 N&M*)O,N+H%%L)&/0%)9)9*			&	!T%5%56G%H/0g==dCCN((>*K""hT[[F {{	jj$$*F6;;$7 MI  //
#a& 4 66 //
s1v  ;; //
#SV  !! //
#a& sJ   
AL8 )BM( 8	M%M  M%(P	;NP	0OP	%PP	N)re   rf   rg   rh   r   BETA_API_VERSIONr   rj   rk   rl   rm   r   rd   rn   r   r   ru   ru   =  sJ    $!22, )
(// . .		3-j 1 1^r   ru   )rh   rj    googlecloudsdk.api_lib.filestorer   googlecloudsdk.callioper   r   .googlecloudsdk.command_lib.filestore.instancesr   r   r   $googlecloudsdk.command_lib.util.argsr	   googlecloudsdk.corer
   ri   r   UniverseCompatibleReleaseTracksReleaseTrackGACreateCommandr   ALPHArp   BETAru   rn   r   r   <module>r      s    #  = ( . B S < # %5$C$C = D%%(()WT W * Wt D%%++,}& } -}@ D%%**+] ] ,]r   