
                         >   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mZ ddlmZ ddlmZ ej0                   ej2                  ej4                  j6                         G d dej8                                      Zy)z#Command to create an HA Controller.    )absolute_import)division)unicode_literals)base_classes)utils)poller)arg_parsers)base)	arg_utils)
exceptions)log)compute_alpha_messagesc                   &    e Zd ZdZed        Zd Zy)CreatezCreate an HA Controller.

  Create an High Availability (HA) Controller, which helps
  ensure that a virtual machine (VM) instance remains operational by
  automatically managing failover across two zones.
  c                     t         j                  j                  |        t        j                  | t         j
                  j                  j                  j                                | j                  dd       | j                  dd       | j                  ddd d	t        j                  t        j                  j                         
       | j                  ddd dt        j                  t        j                  j                         
       | j                  ddt        j                   t        j                   d dt        j                  t        j"                  j$                               t        j                   t&        d      t        j                   d dt        j                  t        j(                  j*                               t        j                   t&        d      d      t        j,                         d       y )Nz--descriptionzZAn optional, user-provided description for the HA Controller to help identify its purpose.)helpz--instance-namezThe name of the existing VM that the HA Controller manages. This VM must already exist in one of the zones specified in --zone-configuration.z--failover-initiationTc                 ^    t        j                  | t        j                  j                        S N)r   ChoiceToEnumr   HaController!FailoverInitiationValueValuesEnumxs    ,lib/surface/compute/ha_controllers/create.py<lambda>zCreate.Args.<locals>.<lambda>D   s!    y--"//QQ
    zuSpecifies how a failover is triggered. Set to MANUAL_ONLY if you want to trigger failovers yourself. Must be one of: )requiredtyper   z--secondary-zone-capacityc                 ^    t        j                  | t        j                  j                        S r   )r   r   r   r   $SecondaryZoneCapacityValueValuesEnumr   s    r   r   zCreate.Args.<locals>.<lambda>Q   s!    y--"//TT
r   zDetermines the capacity guarantee in the secondary zone. Use BEST_EFFORT to create a VM based on capacity availability at the time of failover, suitable for workloads that can tolerate longer recovery times. Must be one of: z--zone-configurationc                 ^    t        j                  | t        j                  j                        S r   )r   r   r   )HaControllerZoneConfigurationNodeAffinityOperatorValueValuesEnumr   s    r   r   zCreate.Args.<locals>.<lambda>c   s!    )?)?.XXpp*r   z3Specifies the node-affinity value. Must be one of: )
value_type	help_textz[Specifies the reservation name. The reservation must exist within the HA Controller region.c                 ^    t        j                  | t        j                  j                        S r   )r   r   r   0HaControllerZoneConfigurationReservationAffinity%ConsumeReservationTypeValueValuesEnumr   s    r   r   zCreate.Args.<locals>.<lambda>u   s'    )?)?.__  F  F*r   z:Specifies the reservation-affinity value. Must be one of: zESpecifies the zone. The zone must be within the HA Controller region.)znode-affinityreservationzreservation-affinityzone)speczConfigures the two zones for the HA Controller and specifies how VM capacity is reserved in each zone. You must provide two zone configurations. You can also specify an existing reservation or node-group to guarantee capacity.)r   r   actionr   )r
   
ASYNC_FLAGAddToParserr   AddHaControllerNameArgToParserReleaseTrackALPHAnameloweradd_argumentEnumTypeToChoicesr   r   r   r    r	   	ArgObjectr"   r#   strr'   r(   FlattenAction)parsers    r   ArgszCreate.Args,   s   OO'	((!!'',,224 *   %   

''(>(K(K(m(mnoq   #

 ''(>(K(K(p(pqr	t   ""!,!6!6 
!334J4t4t  5M  5M  N  OP
"  +44"B  )4(=(= 
!334J4{4{  5b  5b  c  de
) $--".=%'
P ((*1[  2r   c                    t        j                  | j                               }|j                  }|j                  j
                  j                         }|j                  j                  |j                         |j                  |j                  |j                  |j                  |j                  t        j                   |j"                              }|j$                  st'        j(                  |||      S g }t'        j*                  ||||      }t-        |dd       }|r.|j/                  t1        j2                  |j4                               |rt7        j8                  |      |j:                  j                  |j<                        }	t>        j@                  jC                  djE                  |jF                  |	jI                                      t>        j@                  jC                  d       |S )N)r2   regiondescriptioninstanceNamefailoverInitiationsecondaryZoneCapacityzoneConfigurationserrorz/HA Controller creation in progress for [{}]: {}zZUse [gcloud compute operations describe URI] command to check the status of the operation.)%r   ComputeApiHolderr0   clientCONCEPTSha_controllerParsemessagesr   Namer<   r=   instance_namefailover_initiationsecondary_zone_capacityr   MakeZoneConfigurationzone_configurationasync_	api_utilsInsertInsertAsyncgetattrappendr   OperationErrorserrorscore_exceptions
MultiError	resourcesselfLinkr   statusPrintformatr2   SelfLink)
selfargsholderrD   ha_controller_refrF   errors_to_collectresponseerroperation_refs
             r   Runz
Create.Run   s   **4+<+<+>?F]]F3399;OO00##% ''$$''33":: 66t7N7NO 1 M ;;m->GG$$02CH (GT
*C
v55cjjAB&&'899$$**8+<+<=MJJ9@@ 6 6 8	

 JJ	0
 Or   N)__name__
__module____qualname____doc__staticmethodr:   rg    r   r   r   r   "   s#     b bH&r   r   N)rk   
__future__r   r   r   googlecloudsdk.api_lib.computer   -googlecloudsdk.api_lib.compute.ha_controllersr   rP   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.callioper	   r
   1googlecloudsdk.command_lib.compute.ha_controllers$googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   rW   r   3googlecloudsdk.generated_clients.apis.compute.alphar   DefaultUniverseOnlyReleaseTracksr0   r1   CreateCommandr   rm   r   r   <module>rz      s|     * &  ' 7 L < / ( C : = # V D%%++,ST S - Sr   