
    -                     .   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 dd
lmZ ddlmZ ddlZej&                  fdZej*                   ej,                  ej.                  j0                         G d dej2                                      Zej*                   ej,                  ej.                  j6                         G d de                    Z ej,                  ej.                  j:                         G d de             Zy)zCreates a Filestore instance.    )absolute_import)division)unicode_literals)filestore_client)base)
exceptions)flags)labels_util)log)
propertiesNc                 0    t        j                  | |       y N)instances_flagsAddInstanceCreateArgs)parserapi_versions     )lib/surface/filestore/instances/create.py_CommonArgsr       s    ''<    c                   H    e Zd ZdZej
                  ZdddZed        Z	d Z
y)CreateCreate a Filestore instance.a6      The following command creates a Filestore instance named NAME with a single volume.

      $ {command} NAME --description=DESCRIPTION --tier=TIER --protocol=PROTOCOL --file-share=name=VOLUME_NAME,capacity=CAPACITY --network=name=NETWORK_NAME,reserved-ip-range=RESERVED_IP_RANGE,connect-mode=CONNECT_MODE,psc-endpoint-project=PSC_ENDPOINT_PROJECT --zone=ZONE --performance=max-iops-per-tb=MAX-IOPS-PER-TB --kms-key=KMS-KEY --kms-keyring=KMS_KEYRING --kms-location=KMS_LOCATION --kms-project=KMS_PROJECT --flags-file=FLAGS_FILE --source-instance=SOURCE_INSTANCE

    Example json configuration file:
  {
  "--file-share":
  {
    "capacity": "61440",
    "name": "my_vol",
    "nfs-export-options": [
      {
        "access-mode": "READ_WRITE",
        "ip-ranges": [
          "10.0.0.0/8",
        ],
        "squash-mode": "NO_ROOT_SQUASH",
      },
       {
        "access-mode": "READ_ONLY",
        "ip-ranges": [
          "192.168.0.0/24"
        ],
        "squash-mode": "ROOT_SQUASH",
        "anon_uid": 1003,
        "anon_gid": 1003
      }
    ]
  }
  }

    DESCRIPTIONEXAMPLESc                 8    t        | t        j                         y r   )r   r   _API_VERSIONr   s    r   ArgszCreate.ArgsP   s    ++,r   c                    |j                   j                  j                         }t        j                  | j
                        }t        j                  |j                        j                  |j                        }d}|j                  8t        j                  |j                        j                  |j                        }|j                  xs d}t        j                  ||j                  j                   j"                        }t        j$                  ||j                  j                   j&                        }	 |j)                  |j                  |j*                  j-                  dg             }	|j9                  |||j:                  |j*                  |j<                  |j>                  |||j@                  |	t        jB                  |      ||jD                  |jF                  |jH                        }|jK                  ||jL                  |      }|jL                  rtN        jP                  jR                  jT                  jW                         jY                  d      }|rd|d<   tZ        j\                  j_                  d	ja                  d
jc                  |                   |S # t.        $ r.}
t1        j2                  dt5        j6                  |
            d}
~
ww xY w)3Create a Filestore instance in the current project.Nnfs-export-optionsmessagesnfs_export_options--file-share)tierprotocoldescription
file_sharenetworkperformancelabelstagszoner%   kms_key_nameldapsource_instancedeletion_protection_enableddeletion_protection_reason.listFCheck the status of the new instance by listing all instances:
  $ {}  )2CONCEPTSinstanceParser   FilestoreClientr   r   
GetTierArgr$   GetEnumForChoicer'   r(   GetProtocolArgr1   r
   ParseCreateArgsInstanceLabelsValueGetTagsFromArgs	TagsValueMakeNFSExportOptionsMsgr*   getKeyErrorr   InvalidArgumentExceptionsix	text_typeParseFilestoreConfigr)   r+   r,   locationsIdGetAndValidateKmsKeyNamer2   deletion_protectionr4   CreateInstanceasync_r   VALUESmetricscommand_nameGetsplitr   statusPrintformatjoin)selfargsinstance_refclientr'   r(   r1   r-   r.   r%   errr;   resultcommands                 r   Runz
Create.RunT   sa   ==))//1L--d.?.?@F%%foo6GG		D H}}  //
//'  99D(()/)A)A)M)MOF**4+1??+C+C+M+MODD!99??!__001ErJ : L **$$??$$%%-$==dC,,$($<$<#'#B#B + DH  ""<hGF{{!!))66::<BB3Gg		jj&'*+- M9  D//03c0BD DDs   ;7J% %	K.)KKN)__name__
__module____qualname____doc__r   V1_API_VERSIONr   detailed_helpstaticmethodr   rb    r   r   r   r   $   s=     %!00, 4 #-J - -1r   r   c                   H    e Zd ZdZej
                  ZdddZed        Z	d Z
y)
CreateBetar   a      The following command creates a Filestore instance named NAME with a single volume.

      $ {command} NAME --description=DESCRIPTION --tier=TIER --protocol=PROTOCOL --file-share=name=VOLUME_NAME,capacity=CAPACITY --network=name=NETWORK_NAME,reserved-ip-range=RESERVED_IP_RANGE,connect-mode=CONNECT_MODE,psc-endpoint-project=PSC_ENDPOINT_PROJECT --zone=ZONE --performance=max-iops-per-tb=MAX-IOPS-PER-TB --kms-key=KMS-KEY --kms-keyring=KMS_KEYRING --kms-location=KMS_LOCATION --kms-project=KMS_PROJECT --managed-ad=domain=DOMAIN,computer=COMPUTER --flags-file=FLAGS_FILE --source-instance=SOURCE_INSTANCE

    Example json configuration file:
  {
  "--file-share":
  {
    "capacity": "61440",
    "name": "my_vol",
    "nfs-export-options": [
      {
        "access-mode": "READ_WRITE",
        "ip-ranges": [
          "10.0.0.0/8",
        ],
        "squash-mode": "NO_ROOT_SQUASH",
        "security-flavors": [
            "AUTH_SYS",
            "KRB5P",
        ],
      },
       {
        "access-mode": "READ_ONLY",
        "ip-ranges": [
          "192.168.0.0/24"
        ],
        "squash-mode": "ROOT_SQUASH"
        "anon_uid": 1003,
        "anon_gid": 1003
      }
    ],
  }
  }

    r   c                 8    t        | t        j                         y r   )r   rl   r   r   s    r   r   zCreateBeta.Args   s    
//0r   c                 z   |j                   j                  j                         }t        j                  | j
                        }t        j                  |j                        j                  |j                        }d}|j                  8t        j                  |j                        j                  |j                        }d}|j                  8t        j                  |j                        j                  |j                        }|j                  xs d}|j                   xs d}|j"                  xs d}	t%        j&                  ||j                  j(                  j*                        }
t        j,                  ||j                  j(                  j.                        }	 |j1                  |j                  |j2                  j5                  dg             }|jA                  |||jB                  |j2                  |jD                  |jF                  |
||jH                  |t        jJ                  |      |||	|jL                  |jN                  |      }|jQ                  ||jR                  |      }|jR                  rtT        jV                  jX                  jZ                  j]                         j_                  d      }|rd|d<   t`        jb                  je                  d	jg                  d
ji                  |                   |S # t6        $ r.}t9        j:                  dt=        j>                  |            d}~ww xY w)zCreates a Filestore instance in the current project.

    Note: This is a copied code from Run() of base.ReleaseTrack.GA.
    Args:
      args: A list of fields.
    Returns:
      A filestore instance.
    Nr"   r#   r&   )r'   r(   r)   r*   r+   r,   r-   r.   r/   r%   r0   
managed_adr1   r2   r3   r4   backend_typer5   r6   r7   r8   r9   )5r:   r;   r<   r   r=   r   r   r>   r$   r?   r'   r(   r@   rp   GetBackendTypeArgro   r1   r2   r
   rA   rB   rC   rD   rE   MakeNFSExportOptionsMsgBetar*   rG   rH   r   rI   rJ   rK   rL   r)   r+   r,   rM   rN   rO   r4   rP   rQ   r   rR   rS   rT   rU   rV   r   rW   rX   rY   rZ   )r[   r\   r]   r^   r'   r(   rp   ro   r1   r2   r-   r.   r%   r_   r;   r`   ra   s                    r   rb   zCreateBeta.Run   s    ==))//1L--d.?.?@F%%foo6GG		D H}}  //
//'  L$$66
//**+  (DJ99D**2dO((foo&&224F**4+1??+C+C+M+MODD!==??!__001ErJ > L **$$??$$%%-$==dC'$($<$<#'#B#B!# + H( ""<hGF{{!!))66::<BB3Gg		jj&'*+- MA  D//03c0BD DDs   !7L 	L:)L55L:N)rc   rd   re   rf   r   BETA_API_VERSIONr   rh   ri   r   rb   rj   r   r   rl   rl      s>     %!22, 4$'-R 1 1Cr   rl   c                   H    e Zd ZdZej
                  ZdddZed        Z	d Z
y)CreateAlphar   ad      The following command creates a Filestore instance named NAME with a single volume.

      $ {command} NAME       --description=DESCRIPTION --tier=TIER       --file-share=name=VOLUME_NAME,capacity=CAPACITY       --network=name=NETWORK_NAME,reserved-ip-range=RESERVED_IP_RANGE,connect-mode=CONNECT_MODE       --zone=ZONE       --flags-file=FLAGS_FILE

    Example json configuration file:
  {
  "--file-share":
  {
    "capacity": "61440",
    "name": "my_vol",
    "nfs-export-options": [
      {
        "access-mode": "READ_WRITE",
        "ip-ranges": [
          "10.0.0.0/8",
        ],
        "squash-mode": "NO_ROOT_SQUASH",
      },
       {
        "access-mode": "READ_ONLY",
        "ip-ranges": [
          "192.168.0.0/24"
        ],
        "squash-mode": "ROOT_SQUASH"
        "anon_uid": 1003,
        "anon_gid": 1003
      }
    ],
  }
  }

    r   c                 8    t        | t        j                         y r   )r   ru   r   r   s    r   r   zCreateAlpha.Args4  s    001r   c           	      $   |j                   j                  j                         }t        j                  | j
                        }t        j                  |j                        j                  |j                        }t        j                  ||j                  j                  j                        }	 |j                  |j                  |j                   j#                  dg             }|j/                  ||j0                  |j                   |j2                  ||j4                  |      }|j7                  ||j8                  |      }	|j8                  rt:        j<                  j>                  j@                  jC                         jE                  d      }
|
rd|
d<   tF        jH                  jK                  d	jM                  d
jO                  |
                   |	S # t$        $ r.}t'        j(                  dt+        j,                  |            d}~ww xY w)r!   r"   r#   r&   N)r'   r)   r*   r+   r-   r/   r%   r5   r6   r7   r8   r9   )(r:   r;   r<   r   r=   r   r   r>   r$   r?   r'   r
   rA   rB   rC   rF   r*   rG   rH   r   rI   rJ   rK   rL   r)   r+   rM   rP   rQ   r   rR   rS   rT   rU   rV   r   rW   rX   rY   rZ   )r[   r\   r]   r^   r'   r-   r%   r_   r;   r`   ra   s              r   rb   zCreateAlpha.Run8  s   ==))//1L--d.?.?@F%%foo6GG		D (()/)A)A)M)MOFD!99??!__001ErJ : L **$$??%%- + /H ""<hGF{{!!))66::<BB3Gg		jj&'*+- M'  D//03c0BD DDs   17G 	H!)H

HN)rc   rd   re   rf   r   ALPHA_API_VERSIONr   rh   ri   r   rb   rj   r   r   ru   ru     s;    $!33, )%	*-X 2 2 r   ru   )rf   
__future__r   r   r    googlecloudsdk.api_lib.filestorer   googlecloudsdk.callioper   r   .googlecloudsdk.command_lib.filestore.instancesr	   r   $googlecloudsdk.command_lib.util.argsr
   googlecloudsdk.corer   r   rJ   rg   r   UniverseCompatibleReleaseTracksReleaseTrackGACreateCommandr   BETArl   ALPHAru   rj   r   r   <module>r      s   $ &  ' = ( . S < # * 
 %5$C$C = D%%(()_T _ * _D D%%**+u u , up D%%++,U& U -Ur   