
                         >   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
  ej                  d       ej                  d      d	Zej                   ej                  ej                  j                          G d
 dej"                                      Zee_        y)z6Command to create a cluster-director cluster resource.    N)utils)base)flags)logaC  
        *{command}* facilitates the creation of a cluster resource.

        There are following ways to create a cluster:
        - [Preferred] Use granular flags to define cluster specs.
        - Use --config flag with cluster specs in JSON format.

        Please refer to the examples below for more details.
        a"  
        To create a cluster `my-cluster` in location `us-central1-a` with granular flags, run the following example:

        $ {command} my-cluster --location us-central1-a         --description "My cluster description"         --labels env=prod,client=gcloud-cli         --create-network name=network0         --create-filestores name=locations/us-central1-a/instances/filestore0,tier=BASIC_HDD,capacityGb={filestoreSize},fileshare={fileshare}         --filestores locations/us-central1-a/instances/filestore1         --create-buckets name=bucket0         --buckets bucket1         --create-lustres name=locations/us-central1-a/instances/lustre0,capacityGb={lustreSize},filesystem={filesystem}         --lustres locations/us-central1-a/instances/lustre1         --reserved-instances id=compute0,machineType={machineType},reservation=zones/us-central1-a/reservations/{reservation}         --slurm-login-node machineType={machineType},zone=us-central1-a         --slurm-node-sets id=nodeset0,computeId=compute0         --slurm-partitions id=partition0,nodesetIds=[nodeset0]         --slurm-default-partition partition0         --format json

        To create a cluster `my-cluster` in location `us-central1-a` with config in JSON string format run the following example:

        $ {command} my-cluster --location=us-central1-a --config='{"key": "value"}'

        Or create a JSON file `my-cluster-config.json` with the cluster specs and run the following file example:

        $ {command} my-cluster --location=us-central1-a --config=my-cluster-config.json
        )DESCRIPTIONEXAMPLESc                   &    e Zd ZdZed        Zd Zy)Createz$Creates a Cluster Director resource.c                    t         j                  j                  |       t        j                  | j                               }t        j                  ||       |j                  ddd      }t        j                  ||       |j                  d      }t        j                  ||       t        j                  ||       |j                  ddd      }t        j                  ||       |j                  d	      }t        j                  ||d
       t        j                  ||d
       t        j                   ||       t        j"                  ||       t        j$                  ||       t        j&                  ||       t        j(                  ||       t        j*                  ||       t        j,                  ||       t        j.                  ||       t        j0                  ||       t        j2                  ||       t        j4                  ||d
       t        j6                  ||d
       t        j8                  ||d
       t        j:                  ||       y)znSpecifies command flags.

    Args:
      parser: argparse.Parser: Parser object for command line inputs.
    )parserapi_versionz'Cluster configuration for provisioning.T)helpmutexrequiredz+Flag Configurations to define cluster spec.)r   z&Network configuration for the cluster.)r   r   r   z/Use an existing network source for the cluster.)r   r   r   N)r   
ASYNC_FLAGAddToParser	api_utilsGetApiVersionReleaseTrackr   AddClusterNameArgToParser	add_groupr   	AddConfigAddDescription	AddLabelsAddCreateNetworkAddNetworkSourceAddSubnetSourceAddCreateFilestoresAddFilestoresAddCreateGcsBucketsAddGcsBucketsAddCreateLustres
AddLustresAddOnDemandInstancesAddSpotInstancesAddReservedInstancesAddDwsFlexInstancesAddSlurmLoginNodeAddSlurmNodeSetsAddSlurmPartitionsAddSlurmDefaultPartition)clsr   r   group
flag_groupnetwork_groupnetwork_source_groups          /lib/surface/cluster_director/clusters/create.pyArgszCreate.ArgsI   s    	OO'))#*:*:*<=K	##6{K6  E
 
OO5k:: ! J 

D	OO:;?((5 ) M
 
-[I(22> 3  
#t 
#t 
Z[I	z{C	Z[I	z{C	*+F	JK@	jkJ	*+F	jkJ	Z[I	{T 
{T 
{T 
""*+N    c                 B   | j                         }t        j                  |      }t        j                  |      }t	        j
                  ||      }|j                  }|j                  d      r|j                         }n|j                         }|j                  j                  |j                  |j                         j                         |j                         |            }t         j"                  j%                  dj'                  |j                                      |j(                  r|S t        j*                  ||dj'                  |j,                        d      }	t         j"                  j%                  dj'                  |j                                      |	S )	zConstructs and sends request.

    Args:
      args: argparse.Namespace, An object that contains the values for the
        arguments specified in the .Args() method.

    Returns:
      ProcessHttpResponse of the request made.
    )argsmessage_moduleconfig)parent	clusterIdclusterz Create request issued for: [{0}]z'Waiting for operation [{0}] to completei   )client	operationmessagemax_wait_seczCreated cluster [{0}].)r   r   GetClientInstanceGetMessagesModuler   ClusterUtilcluster_refIsSpecifiedMakeClusterFromConfigMakeClusterprojects_locations_clustersr
   9HypercomputeclusterProjectsLocationsClustersCreateRequestParentRelativeNameNamer   statusPrintformatasync_WaitForOperationname)
selfr5   release_trackr;   messagescluster_utilrB   r:   r<   responses
             r1   Runz
Create.Run   s_    %%'M((7F**=9H$$$xHL**K!224g((*g2299JJ%%'446!&&( 	K 	
I JJ*11+2B2B2DE {{))9@@NN
 H JJ-44[5E5E5GHIOr3   N)__name__
__module____qualname____doc__classmethodr2   rV    r3   r1   r
   r
   D   s!     -6O 6Op+r3   r
   )rZ   textwrap*googlecloudsdk.api_lib.hypercomputeclusterr   r   googlecloudsdk.callioper   4googlecloudsdk.command_lib.cluster_director.clustersr   googlecloudsdk.corer   dedentDETAILED_HELPDefaultUniverseOnlyReleaseTracksr   ALPHACreateCommandr
   detailed_helpr\   r3   r1   <module>ri      s     =  I ( F F # #8?? $    ! &R D%%++,gT g - gT % r3   