
    P                        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j*                  j,                  fdZ G d d      Zd Zd Zd Zd Zd Zej*                  j,                  fdZej*                  j,                  fdZej*                  j@                  fdZ!ej*                  j@                  fdZ"ej*                  j@                  fdZ#ej*                  j@                  fdZ$ej*                  j@                  fdZ%ej*                  j@                  fdZ&ej*                  j@                  fdZ'ej*                  j,                  fdZ(ej*                  j,                  fd Z)d!ej*                  j,                  fd"Z*ej*                  j,                  fd#Z+d$ Z,d% Z-d& Z.d' Z/y!)(z4Utilities for calling the Composer Environments API.    )absolute_import)division)unicode_literals)
exceptions)util)base)CONNECTION_TYPE_FLAG_ALPHA)CONNECTION_TYPE_FLAG_BETA)CONNECTION_TYPE_FLAG_GA)ENVIRONMENT_SIZE_ALPHA)ENVIRONMENT_SIZE_BETA)ENVIRONMENT_SIZE_GAc                 @    t        j                  |       j                  S N)api_utilGetClientInstanceprojects_locations_environmentsrelease_tracks    8lib/googlecloudsdk/api_lib/composer/environments_util.py
GetServicer   !   s    		#	#
445    c            O           e Zd ZdZdddddddddddddddddddddddddddddddddddddddddddddddddddddddej
                  j                  dddddddddddddddddddddddfOdZy)CreateEnvironmentFlagsaH#  Container holding environment creation flag values.

  Attributes:
    node_count: int or None, the number of VMs to create for the environment
    environment_size: str or None, one of small, medium and large.
    labels: dict(str->str), a dict of user-provided resource labels to apply to
      the environment and its downstream resources
    location: str or None, the Compute Engine zone in which to create the
      environment specified as relative resource name.
    machine_type: str or None, the Compute Engine machine type of the VMs to
      create specified as relative resource name.
    network: str or None, the Compute Engine network to which to connect the
      environment specified as relative resource name.
    subnetwork: str or None, the Compute Engine subnetwork to which to connect
      the environment specified as relative resource name.
    network_attachment: str or None, the Compute Engine network attachment that
      is used as PSC Network entry point.
    env_variables: dict(str->str), a dict of user-provided environment variables
      to provide to the Airflow scheduler, worker, and webserver processes.
    airflow_config_overrides: dict(str->str), a dict of user-provided Airflow
      configuration overrides.
    service_account: str or None, the user-provided service account
    oauth_scopes: [str], the user-provided OAuth scopes
    tags: [str], the user-provided networking tags
    disk_size_gb: int, the disk size of node VMs, in GB
    python_version: str or None, major python version to use within created
      environment.
    image_version: str or None, the desired image for created environment in the
      format of 'composer-(version)-airflow-(version)'
    airflow_executor_type: str or None, the airflow executor type to run task
      instances.
    use_ip_aliases: bool or None, create env cluster nodes using alias IPs.
    cluster_secondary_range_name: str or None, the name of secondary range to
      allocate IP addresses to pods in GKE cluster.
    services_secondary_range_name: str or None, the name of the secondary range
      to allocate IP addresses to services in GKE cluster.
    cluster_ipv4_cidr_block: str or None, the IP address range to allocate IP
      adresses to pods in GKE cluster.
    services_ipv4_cidr_block: str or None, the IP address range to allocate IP
      addresses to services in GKE cluster.
    max_pods_per_node: int or None, the maximum number of pods that can be
      assigned to a GKE cluster node.
    enable_ip_masq_agent: bool or None, when enabled, the GKE IP Masq Agent is
      deployed to the cluster.
    private_environment: bool or None, create env cluster nodes with no public
      IP addresses.
    private_endpoint: bool or None, managed env cluster using the private IP
      address of the master API endpoint.
    master_ipv4_cidr: IPv4 CIDR range to use for the cluster master network.
    privately_used_public_ips: bool or None, when enabled, GKE pod and services
      can use IPs from public (non-RFC1918) ranges.
    web_server_ipv4_cidr: IPv4 CIDR range to use for Web Server network.
    cloud_sql_ipv4_cidr: IPv4 CIDR range to use for Cloud SQL network.
    composer_network_ipv4_cidr: IPv4 CIDR range to use for Composer network.
    connection_subnetwork: str or None, the Compute Engine subnetwork from which
      to reserve the IP address for internal connections, specified as relative
      resource name.
    connection_type: str or None, mode of internal connectivity within the Cloud
      Composer environment. Can be VPC_PEERING or PRIVATE_SERVICE_CONNECT.
    web_server_access_control: [{string: string}], List of IP ranges with
      descriptions to allow access to the web server.
    cloud_sql_machine_type: str or None, Cloud SQL machine type used by the
      Airflow database.
    cloud_sql_preferred_zone: str or None, Cloud SQL db preferred zone. Can be
      specified only in Composer 2.0.0.
    web_server_machine_type: str or None, machine type used by the Airflow web
      server
    kms_key: str or None, the user-provided customer-managed encryption key
      resource name
    scheduler_cpu: float or None, CPU allocated to Airflow scheduler. Can be
      specified only in Composer 2.0.0.
    worker_cpu: float or None, CPU allocated to each Airflow worker. Can be
      specified only in Composer 2.0.0.
    web_server_cpu: float or None, CPU allocated to Airflow web server. Can be
      specified only in Composer 2.0.0.
    scheduler_memory_gb: float or None, memory allocated to Airflow scheduler.
      Can be specified only in Composer 2.0.0.
    worker_memory_gb: float or None, memory allocated to each Airflow worker.
      Can be specified only in Composer 2.0.0.
    web_server_memory_gb: float or None, memory allocated to Airflow web server.
      Can be specified only in Composer 2.0.0.
    scheduler_storage_gb: float or None, storage allocated to Airflow scheduler.
      Can be specified only in Composer 2.0.0.
    worker_storage_gb: float or None, storage allocated to each Airflow worker.
      Can be specified only in Composer 2.0.0.
    web_server_storage_gb: float or None, storage allocated to Airflow web
      server. Can be specified only in Composer 2.0.0.
    min_workers: int or None, minimum number of workers in the Environment. Can
      be specified only in Composer 2.0.0.
    max_workers: int or None, maximum number of workers in the Environment. Can
      be specified only in Composer 2.0.0.
    scheduler_count: int or None, number of schedulers in the Environment.
    maintenance_window_start: Datetime or None, the starting time of the
      maintenance window
    maintenance_window_end: Datetime or None, the ending time of the maintenance
      window
    maintenance_window_recurrence: str or None, the recurrence of the
      maintenance window
    enable_master_authorized_networks: bool or None, whether master authorized
      networks should be enabled
    master_authorized_networks: list(str), master authorized networks
    airflow_database_retention_days: Optional[int], the number of retention days
      for airflow database data retention mechanism. Infinite retention will be
      applied in case `0` or no integer is provided.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.
    enable_triggerer: bool or None, enable triggerer in the Environment. Can be
      specified only in Airflow 2.2.x and greater
    triggerer_cpu: float or None, CPU allocated to Airflow triggerer. Can be
      specified only in Airflow 2.2.x and greater
    triggerer_count: int or None, number of Airflow triggerers. Can be specified
      only in Airflow 2.2.x and greater
    triggerer_memory_gb: float or None, memory allocated to Airflow triggerer.
      Can be specified only in Airflow 2.2.x and greater
    enable_scheduled_snapshot_creation: bool or None, whether the automatic
      snapshot creation should be enabled
    snapshot_creation_schedule: str or None, cron expression that specifies when
      snapshots will be created
    snapshot_location: str or None, a Cloud Storage location used to store
      automatically created snapshots
    snapshot_schedule_timezone: str or None, time zone that sets the context to
      interpret snapshot_creation_schedule
    enable_cloud_data_lineage_integration: bool or None, whether Cloud Data
      Lineage integration should be enabled
    disable_cloud_data_lineage_integration: bool or None, whether Cloud Data
      Lineage integration should be disabled
    enable_high_resilience: bool or None, whether high resilience should be
      enabled
    enable_logs_in_cloud_logging_only: bool or None, whether logs in cloud
      logging only should be enabled
    disable_logs_in_cloud_logging_only: bool or None, whether logs in cloud
      logging only should be disabled
    support_web_server_plugins: bool or None, whether to enable/disable the
      support for web server plugins
    dag_processor_cpu: float or None, CPU allocated to Airflow dag processor.
      Can be specified only in Composer 3.
    dag_processor_count: int or None, number of Airflow dag processors. Can be
      specified only in Composer 3.
    dag_processor_memory_gb: float or None, memory allocated to Airflow dag
      processor. Can be specified only in Composer 3.
    dag_processor_storage_gb: float or None, storage allocated to Airflow dag
      processor. Can be specified only in Composer 3.
    composer_internal_ipv4_cidr_block: str or None. The IP range in CIDR
      notation to use internally by Cloud Composer. Can be specified only in
      Composer 3.
    enable_private_builds_only: bool or None, whether to enable the support for
      private only builds.
    disable_private_builds_only: bool or None, whether to disable the support
      for private only builds.
    storage_bucket: str or None. An existing Cloud Storage bucket to be used by
      the environment.
  NcP                 V   || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        | | _        |!| _         |"| _!        |#| _"        |$| _#        |%| _$        |&| _%        |'| _&        |(| _'        |)| _(        |*| _)        |+| _*        |,| _+        |-| _,        |.| _-        |/| _.        |0| _/        |1| _0        |9| _1        |:| _2        |;| _3        |<| _4        |2| _5        |3| _6        |4| _7        |5| _8        |6| _9        |7| _:        |8| _;        |=| _<        |>| _=        |?| _>        @| _?        A| _@        B| _A        C| _B        D| _C        E| _D        F| _E        G| _F        H| _G        K| _H        J| _I        I| _J        L| _K        M| _L        N| _M        O| _N        y r   )O
node_countenvironment_sizelabelslocationmachine_typenetwork
subnetworknetwork_attachmentenv_variablesairflow_config_overridesservice_accountoauth_scopestagsdisk_size_gbpython_versionimage_versionairflow_executor_typeuse_ip_aliasescluster_secondary_range_nameservices_secondary_range_namecluster_ipv4_cidr_blockservices_ipv4_cidr_blockmax_pods_per_nodeenable_ip_masq_agentprivate_environmentprivate_endpointmaster_ipv4_cidrprivately_used_public_ipsweb_server_ipv4_cidrcloud_sql_ipv4_cidrcomposer_network_ipv4_cidrconnection_subnetworkconnection_typeweb_server_access_controlcloud_sql_machine_typeweb_server_machine_typekms_keyscheduler_cpu
worker_cpuweb_server_cpuscheduler_memory_gbworker_memory_gbweb_server_memory_gbscheduler_storage_gbworker_storage_gbweb_server_storage_gbmin_workersmax_workersscheduler_countenable_triggerertriggerer_cputriggerer_counttriggerer_memory_gbmaintenance_window_startmaintenance_window_endmaintenance_window_recurrence!enable_master_authorized_networksmaster_authorized_networksairflow_database_retention_daysr   "enable_scheduled_snapshot_creationsnapshot_creation_schedulesnapshot_locationsnapshot_schedule_timezone%enable_cloud_data_lineage_integration&disable_cloud_data_lineage_integrationenable_high_resilience!enable_logs_in_cloud_logging_only"disable_logs_in_cloud_logging_onlycloud_sql_preferred_zonesupport_web_server_pluginsdag_processor_cpudag_processor_storage_gbdag_processor_memory_gbdag_processor_count!composer_internal_ipv4_cidr_blockenable_private_builds_onlydisable_private_builds_onlystorage_bucket)Pselfr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rQ   rR   rS   rT   rU   rV   r   rM   rN   rO   rP   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   re   rd   rc   rf   rg   rh   ri   sP                                                                                   r   __init__zCreateEnvironmentFlags.__init__   s   d !DO,DDKDM$DDL DO0D&D$<D!*D$DDI$D(D&D!6D(D(DD%)FD&#:D $<D!.D 4D2D,D,D%>D" 4D2D&@D#!6D*D%>D""8D#:D DL&D DO(D2D,D 4D 4D.D!6D"D"D*D,D&D*D2D$<D!"8D)FD&-ND*&@D#+JD(&D.PD+&@D#.D&@D#- 	. 	/ 	/ #9D-ND*.PD+$<D!&@D#.D$<D!#:D 2D-ND*&@D#'BD$(Dr   )__name__
__module____qualname____doc__r   ReleaseTrackGArk    r   r   r   r   &   s   W@ # #'$("# $!%  $!" #!$((,!%&*%%(()-!%!%,0-1!(,)-#!%"#(,!%"&ad)r   r   c                 D   |j                   s|j                  s|j                  s|j                  s|j                  s|j
                  sy|j                  sm|j                  sa|j                  sU|j                  sI|j                  s=|j                  s1|j                  s%|j                  s|j                  s|j                  sy| j!                  |j                   |j                  |j                  |j                  |j                  |j                        }|j                  r|j                  |_        |j                  r|j                  |_        |j
                  r6t'        |j
                  D cg c]  }|j)                          c}      |_        |j                  r6t'        |j                  D cg c]  }|j)                          c}      |_        |j                  s0|j                  s$|j                  s|j                  s|j                  rj| j-                  |j                  |j                  |j                  |j                  |j                        |_        |j0                  r|j0                  |_        |j                  r|j                  |_        |S c c}w c c}w )zECreates node config from parameters, returns None if config is empty.N)r   machineTyper!   r"   serviceAccount
diskSizeGb)useIpAliasesclusterSecondaryRangeNameservicesSecondaryRangeNameclusterIpv4CidrBlockservicesIpv4CidrBlock)r   r    r!   r"   r&   r'   r(   r)   r-   r.   r#   r/   r0   r1   r3   rf   
NodeConfigcomposerNetworkAttachmentcomposerInternalIpv4CidrBlocksortedstripoauthScopesIPAllocationPolicyipAllocationPolicyr2   maxPodsPerNodeenableIpMasqAgent)messagesflagsconfigsts        r   _CreateNodeConfigr   l  s   
..E..%--


e33u7I7I
****e.B.B

,
,0H0H

-
-1N1N++u/I/I

1
1~~$$mm!!**##  %& ','?'?F$
,,// ( E4F4F G4Fq4F GHF
ZZUZZ8Z!'')Z89FKe@@))U-J-J$$ ( ; ;))"'"D"D#(#F#F"::#<< !< !F #55f
$99F	-' !H8s   .J0Jc                    t        | |      }|s|j                  s|j                  s|j                  s|j                  s|j
                  s|j                  s~|j                  sq|j                  sd|j                  sW|j                  sJ|j                  s=|j                  s0|j                  s#|j                  s|j                  s	|j                   s|j"                  s|j$                  s|j&                  s|j(                  s|j*                  s|j,                  s|j.                  s|j0                  s|j2                  s|j4                  s|j6                  sy|j8                  sm|j:                  sa|j<                  sU|j>                  sI|j@                  s=|jB                  s1|jD                  s%|jF                  s|jH                  s|jJ                  sy| jM                         }|j                  r|j                  |_'        |r||_(        |j                  r!| jS                  |j                        |_*        |j0                  r|jV                  tX        jZ                  j\                  k(  r%t_        j`                  |j0                        |_1        n|jV                  tX        jZ                  jd                  k(  r%tg        j`                  |j0                        |_1        nK|jV                  tX        jZ                  jh                  k(  r$tk        j`                  |j0                        |_1        |j                  sW|j                  sK|j
                  s?|j                  s3|j                  s'|j6                  r|s|jH                  s|jJ                  r-| jm                         |_7        |j                  r|j                  |jn                  _8        |j                  rCts        jt                  |j                  | jl                  jv                        |jn                  _<        |j
                  rCts        jt                  |j
                  | jl                  jz                        |jn                  _>        |j                  r|j                  |jn                  _?        |j                  r9t        | jl                  j                  |j                        |jn                  _B        |j                  k|j                  r0| jl                  j                  j                  |jn                  _F        n/| jl                  j                  j                  |jn                  _F        |j6                  r|r|j6                  |jn                  _H        |jH                  s|jJ                  r/| j                  |jH                  rdnd      |jn                  _J        |j                  ry|j                  sJ d       |j                  sJ d       | j                  |j                  j                         |j                  j                         |j                        |_M        |j8                  |j8                  d	k(  rF| j                  | j                  | j                  j                  j                  
            |_R        nP| j                  | j                  |j8                  | j                  j                  j                              |_R        |j@                  rR| j                  | j                  |j@                  |jB                  |jD                  |jF                              |_V        |j                  s|j                  s|j                  rd}d}|j                  s|j                  r'| j                  |j                  |j                        }|j                  r|jV                  tX        jZ                  j\                  k(  r t        j`                  |j                        }n|jV                  tX        jZ                  jd                  k(  r t        j`                  |j                        }nF|jV                  tX        jZ                  jh                  k(  rt        j`                  |j                        }| j                        }|j                  ||d}|j                  |j                  |d<   |j                  |j                  |d<   |j                  |j                  |d<   |j                  |j                  |d<   |j                  |j                  |d<   |j                  s|j                  r|j                  rdnd|d<    | j                  di ||_g        |j                  %t        |j                  |jV                        |_i        |j                  r%| jL                  j                  j                  |_m        |j                  rG| j                  | j                  j                  j                        }	| j                  |	      |_R        |j                  rG| j                  | j                  j                  j                        }	| j                  |	      |_R        |j                  r!| j                  |j                        |_u        |j                  r!| j                  |j                        |_u        |j                  r!| j                  |j                        |_x        |j                  rP|j                  r|j                  ng }
| j                  d|
D cg c]  }| j                  |       c}      |_}        |j                  |j                   |j"                  |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  |j2                  |j4                  |j                  |j:                  |j>                  |j                  |j                   |j                  |j                  |j                  g}t	        d |D              }|s|j6                  r|st        | |      |_        |S c c}w ) zLCreates environment config from parameters, returns None if config is empty.N)
kmsKeyNameTF)enabledz!maintenance_window_end is missingz(maintenance_window_recurrence is missing)	startTimeendTime
recurrencer   )retentionMode)airflowMetadataRetentionConfig)retentionDaysr   )r   snapshotCreationSchedulesnapshotLocationtimeZone)scheduledSnapshotsConfig)enablePrivateEndpointmasterIpv4CidrBlock)connectionType)enablePrivateEnvironmentprivateClusterConfignetworkingConfigwebServerIpv4CidrBlockcloudSqlIpv4CidrBlock!cloudComposerNetworkIpv4CidrBlockenablePrivatelyUsedPublicIps!cloudComposerConnectionSubnetworkenablePrivateBuildsOnly)storageMode)taskLogsRetentionConfig)rt   )zone)	cidrBlock)r   
cidrBlocksc              3   $   K   | ]  }|d u 
 y wr   rr   ).0flags     r   	<genexpr>z _CreateConfig.<locals>.<genexpr>  s     M;L4d$.;Ls   rr   )r   r   r@   r+   r$   r%   r*   r,   rQ   rR   rS   r4   r=   r>   r?   rA   rB   rC   rD   rE   rF   rG   rH   rI   r   rJ   rK   rL   rV   rN   triggerer_memoryrM   rW   rX   rY   rZ   r[   r\   EnvironmentConfig	nodeCount
nodeConfigEncryptionConfigencryptionConfigr   r   rp   rq   r   GetEnumForChoiceenvironmentSizeBETAr   ALPHAr   SoftwareConfigsoftwareConfigimageVersionr   DictToMessageEnvVariablesValueenvVariablesAirflowConfigOverridesValueairflowConfigOverridespythonVersionConvertToTypeEnum"AirflowExecutorTypeValueValuesEnumairflowExecutorTypera   #WebServerPluginsModeValueValuesEnumPLUGINS_ENABLEDwebServerPluginsModePLUGINS_DISABLEDschedulerCountCloudDataLineageIntegrationcloudDataLineageIntegrationMaintenanceWindow	isoformatmaintenanceWindowDataRetentionConfig$AirflowMetadataRetentionPolicyConfigRetentionModeValueValuesEnumRETENTION_MODE_DISABLEDdataRetentionConfigRETENTION_MODE_ENABLEDRecoveryConfigScheduledSnapshotsConfigrecoveryConfigrg   rh   r5   r6   PrivateClusterConfigr<   r   r
   r	   NetworkingConfigr8   r9   r:   r7   r;   PrivateEnvironmentConfigprivateEnvironmentConfig"BuildWebServerNetworkAccessControlwebServerNetworkAccessControlr]   ResilienceModeValueValuesEnumHIGH_RESILIENCEresilienceModer^   TaskLogsRetentionConfigStorageModeValueValuesEnumCLOUD_LOGGING_ONLYr_   CLOUD_LOGGING_AND_CLOUD_STORAGEDatabaseConfigdatabaseConfigr`   WebServerConfigwebServerConfigrT   rU   MasterAuthorizedNetworksConfig	CidrBlockmasterAuthorizedNetworksConfigrP   rO   rb   re   rd   rc   any_CreateWorkloadConfigworkloadsConfig)r   r   is_composer_v1node_configr   private_cluster_confignetworking_configr<   private_env_config_argstask_logs_retention_confignetworksr!   composer_v2_flagscomposer_v2_flag_useds                 r   _CreateConfigr     s
   !(E2+
))U]]


!4!4

(
(E,@,@

%
%)G)G

&
&%*M*M

#
#u'F'F

&
&%*G*G


!1!1U5I5I

#
#u'='=

$
$(B(B

!
!U%@%@

 
 E$5$59J9J


5#H#H


!7!7

 
 E$L$L

*
*e.E.E

*
*

5
5

6
6%%'&
''F#F
]]&77== 8 "F
d//2222CC

 
  "f			 1 1 6 6	64EE

 
  "f			 1 1 7 7	75FF

 
  "f 					'	'					$	$


N		4	4		5	5$335F+0+>+>f(+3+A+A


x66HH,Jf(%%5=5K5K

(
(

!
!
=
=6?f2 ,1,@,@f)""2C

!
!
D
D

%
%3f/ ''3		)	)##GGWW 	2
 ##GGXX 	2 -2-B-Bf*3377 
.
.EE$5 /  7 ##''L)LL'.. 424.'9900::<,,66866  :  8F **6,,1#+#?#?)1)V)V$IIff~~ *W * $@ $f  $,#?#?)1)V)V!AA$IIff}} *W * $@ $f  --$33!)!B!B<<%*%E%E"4455	 "C "7 4 8F 		)	)		*	* "!7!7'<< % 6 6#44  =  6 			 1 1 4 4	41BB!!#$"3"3"8"883DD!!#$"3"3"9"994EE!!#"33( 4 * %*$=$= 6- !!-&+&@&@ 
"$  ,%*%>%> 
!#''3161Q1Q 
-/&&2,1,K,K 
(*"".161L1L 
-/''5+L+L22$ 78 'Hh&G&G '#
!'#F# $$0+M'')<)<,>F( !!""@@PP  ,,!)!A!A44OObb "B " "*!=!= : "> "F --!)!A!A44OOoo "B " "*!=!= : "> "F !!$3300 4 2F
##$33++ 4 F ""%5511 6 3F ,,383S3Su//Y[H,4,S,SAI
AIgH1
 -T -F)     !!##$$'* M;LMMu44^28UCF	-9
s   
q>
c                    t        | j                  |j                  |j                  |j                  |j
                        | j                  |j                  |j                  |j                        | j                  |j                  |j                  |j                  |j                  |j                              }|j                   s$|j"                  s|j$                  s|j&                  S|j                   rdnd}|j&                  |j&                  }| j)                  |j"                  |j$                  |      |d<   |j*                  s$|j,                  |j.                  s|j0                  r@| j3                  |j*                  |j.                  |j0                  |j,                        |d	<    | j4                  d
i |S )z(Creates workload config from parameters.)cpumemoryGb	storageGbcount)r   r   r   )r   r   r   minCountmaxCount)	scheduler	webServerworker   r   )r   r   r   	triggererdagProcessorrr   )dictSchedulerResourcerA   rD   rG   rL   WebServerResourcerC   rF   rI   WorkerResourcerB   rE   rH   rJ   rK   rM   rN   rP   rO   TriggererResourcerb   re   rd   rc   DagProcessorResourceWorkloadsConfig)r   r   workload_resourcesrO   s       r   r   r     s   **!!,,..%%	 + '
 **""--// + 1 $$))++$$$$ % &'" 					"	"				* 11aqO(--o&.&@&@** 'A '{# 		"	"	.		&	&		'	')1)F)F##..00''	 *G *~& 
"	!	!	7$6	77r   c                    t        j                  |j                        }|j                  | j	                               }t        |||      |_        |j                  r9t        j                  |j                  |j                  j                        |_        |j                  r!|j                  |j                        |_        	 t        |j                        j                  t        j                  |j                        j                  || j!                         j	                                     S # t"        j$                  $ r}t'        j(                  |d      d}~ww xY w)a  Calls the Composer Environments.Create method.

  Args:
    environment_ref: Resource, the Composer environment resource to create.
    flags: CreateEnvironmentFlags, the flags provided for environment creation.
    is_composer_v1: boolean representing if creation request is for Composer
      1.*.* image versions.

  Returns:
    Operation: the operation corresponding to the creation of the environment
  r   name)bucket)environmentparentzCreation operation failed because of lack of proper permissions. Please, refer to https://cloud.google.com/composer/docs/how-to/managing/creating and Composer Creation Troubleshooting pages to resolve this issue.error_formatN)r   GetMessagesModuler   EnvironmentRelativeNamer   r   r   r   LabelsValueri   StorageConfigstorageConfigr   Create2ComposerProjectsLocationsEnvironmentsCreateRequestParentapitools_exceptionsHttpForbiddenErrorr   HttpException)environment_refr   r   r   r  es         r   r  r    s5    ''e6I6IJ($$/*F*F*H$I+$XunE+
\\!//h**668K  ( 6 6## !7 !KE$7$78??""1D1DE	;	;#"))+88: 
< 
<= =
 
	/	/ 

"
"	Q s   A/D6 6E%	E  E%c                      | |      S )a  Converts airflow executor type string to enum.

  Args:
    type_enum: AirflowExecutorTypeValueValuesEnum, executor type enum value.
    airflow_executor_type: string, executor type string value.

  Returns:
    AirflowExecutorTypeValueValuesEnum: the executor type enum value.
  rr   )	type_enumr,   s     r   r   r     s     
(	))r   c                     t        |      j                  t        j                  |      j	                  | j                                     S )ac  Calls the Composer Environments.Delete method.

  Args:
    environment_ref: Resource, the Composer environment resource to delete.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    Operation: the operation corresponding to the deletion of the environment
  r   r  )r   Deleter   r  2ComposerProjectsLocationsEnvironmentsDeleteRequestr  r!  r   s     r   r&  r&    sF     
-	0	7	7  }=99++- : /
0 0r   c                     t        j                  |      }|j                  | j                               }t	        |      j                  |      S )a  Calls the Composer Environments.RestartWebServer method.

  Args:
    environment_ref: Resource, the Composer environment resource to restart the
      web server for.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    Operation: the operation corresponding to the restart of the web server
  r   r  )r   r  <ComposerProjectsLocationsEnvironmentsRestartWebServerRequestr  r   RestartWebServerr!  r   message_modulerequest_messages       r   r+  r+  
  sR     --MJ."__'') ` +/	!
##3#3O#DEr   c                     t        j                  |      }|j                  | j                         |j	                  |            }t        |      j                  |      S )a  Calls the Composer Environments.SaveSnapshot method.

  Args:
    environment_ref: Resource, the Composer environment resource to save the
      snapshot for.
    snapshot_location: location to save the snapshot of the environment.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    Operation: the operation corresponding to saving the snapshot.
  r   )r   )r  saveSnapshotRequest)r   r  8ComposerProjectsLocationsEnvironmentsSaveSnapshotRequestr  SaveSnapshotRequestr   SaveSnapshot)r!  rY   r   r-  r.  s        r   r3  r3    sd     --MJ."[[!..0(<<, = . \ // 
-	0	=	=o	NNr   c           
          t        j                  |      }|j                  | j                         |j	                  |||||            }t        |      j                  |      S )a+  Calls the Composer Environments.LoadSnapshot method.

  Args:
    environment_ref: Resource, the Composer environment resource to Load the
      snapshot for.
    skip_pypi_packages_installation: skip installing the pypi packages during
      the operation.
    skip_environment_variables_setting: skip setting environment variables
      during the operation.
    skip_airflow_overrides_setting: skip setting Airflow overrides during the
      operation.
    skip_gcs_data_copying: skip copying GCS data during the operation.
    snapshot_path: path of the specific snapshot to load the snapshot.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    Operation: the operation corresponding to loading the snapshot.
  r   )skipPypiPackagesInstallationskipEnvironmentVariablesSettingskipAirflowOverridesSettingskipGcsDataCopyingsnapshotPath)r  loadSnapshotRequest)r   r  8ComposerProjectsLocationsEnvironmentsLoadSnapshotRequestr  LoadSnapshotRequestr   LoadSnapshot)	r!  skip_pypi_packages_installation"skip_environment_variables_settingskip_airflow_overrides_settingskip_gcs_data_copyingsnapshot_pathr   r-  r.  s	            r   r=  r=  4  sp    4 --MJ."[[!..0(<<'F*L&D2$ = & \ '/ 
-	0	=	=o	NNr   c                     t        j                  |      }|j                  |j                         |j	                  | ||            }t        |      j                  |      S )a  Starts execution of an Airflow CLI command through Composer API.

  Args:
    command: string, the command to execute.
    subcommand: string, the subcommand to execute.
    parameters: string[], optional, additinal parameters for the command.
    environment_ref: Resource, the Composer environment to execute the command.
    release_track: base.ReleaseTrack, the release track of command. Determines
      which Composer client library is used.

  Returns:
    ExecuteAirflowCommandResponse: information about the execution.
  r   )command
subcommand
parameters)r  executeAirflowCommandRequest)r   r  AComposerProjectsLocationsEnvironmentsExecuteAirflowCommandRequestr  ExecuteAirflowCommandRequestr   ExecuteAirflowCommand)rD  rE  rF  r!  r   r-  r.  s          r   rJ  rJ  Z  sp    ( --MJ."dd!..0#1#N#N $O $ e / 
-	0	F	F
 r   c           	          t        j                  |      }|j                  |j                         |j	                  | |||            }t        |      j                  |      S )a  Stops the execution of an Airflow CLI command.

  Args:
    execution_id: string, the unique ID of execution.
    pod_name: string, the pod the execution is running on.
    pod_namespace: string, the pod's namespace.
    force: boolean, If true, the execution is terminated forcefully (SIGKILL).
      If false, the  execution is stopped gracefully, giving it time for
      cleanup.
    environment_ref: Resource, the Composer environment to stop the command.
    release_track: base.ReleaseTrack, the release track of command. Determines
      which Composer client library is used.

  Returns:
    StopAirflowCommandResponse: information whether stopping the execution was
    successful.
  r   )executionIdpodpodNamespaceforce)r  stopAirflowCommandRequest)r   r  >ComposerProjectsLocationsEnvironmentsStopAirflowCommandRequestr  StopAirflowCommandRequestr   StopAirflowCommand)execution_idpod_namepod_namespacerO  r!  r   r-  r.  s           r   rS  rS  |  ss    2 --MJ."aa!..0 . H H"$	 !I ! b / 
-	0	C	C
 r   c           	          t        j                  |      }|j                  |j                         |j	                  | |||            }t        |      j                  |      S )a  Polls the execution of an Airflow CLI command through Composer API.

  Args:
    execution_id: string, the unique ID of execution.
    pod_name: string, the pod the execution is running on.
    pod_namespace: string, the pod's namespace.
    next_line_number: int, line of the output which should be fetched.
    environment_ref: Resource, the Composer environment to poll the command.
    release_track: base.ReleaseTrack, the release track of command. Determines
      which Composer client library is used.

  Returns:
    PollAirflowCommandResponse: the next output lines from the execution and
    information whether the execution is still running.
  r   )rL  rM  rN  nextLineNumber)r  pollAirflowCommandRequest)r   r  >ComposerProjectsLocationsEnvironmentsPollAirflowCommandRequestr  PollAirflowCommandRequestr   PollAirflowCommand)rT  rU  rV  next_line_numberr!  r   r-  r.  s           r   r\  r\    ss    . --MJ."aa!..0 . H H"$)	 !I ! b / 
-	0	C	C
 r   c                     t        j                  |      }|j                  | j                         |j	                               }t        |      j                  |      S )a  Triggers the database failover (only for highly resilient environments).

  Args:
    environment_ref: Resource, the Composer environment resource to trigger the
      database failover for.
    release_track: base.ReleaseTrack, the release track of command. Determines
      which Composer client library is used.

  Returns:
    Operation: the operation corresponding to triggering a database failover.
  r   )r  databaseFailoverRequest)r   r  <ComposerProjectsLocationsEnvironmentsDatabaseFailoverRequestr  DatabaseFailoverRequestr   DatabaseFailoverr,  s       r   rb  rb    s`     --MJ."__!..0,DDF ` H/ 
-	0	A	A
 r   c                     t        j                  |      }|j                  | j                               }t	        |      j                  |      S )a`  Fetch database properties.

  Args:
    environment_ref: Resource, the Composer environment resource to fetch the
      database properties for.
    release_track: base.ReleaseTrack, the release track of command. Determines
      which Composer client library is used.

  Returns:
    DatabaseProperties: database properties for a given environment.
  r   )r  )r   r  CComposerProjectsLocationsEnvironmentsFetchDatabasePropertiesRequestr  r   FetchDatabasePropertiesr,  s       r   re  re    sQ     --MJ."ff!..0 g 2/	-	0	H	H
 r   c                     t        j                  |      }|j                  | j                         |j	                  |            }t        |      j                  |      S )a  Calls the Composer Environments.CheckUpgrade method.

  Args:
    environment_ref: Resource, the Composer environment resource to check
      upgrade for.
    image_version: Image version to upgrade to.
    release_track: base.ReleaseTrack, the release track of command. Determines
      which Composer client library is used.

  Returns:
    Operation: the operation corresponding to the upgrade check
  r   )r   )r  checkUpgradeRequest)r   r  8ComposerProjectsLocationsEnvironmentsCheckUpgradeRequestr  CheckUpgradeRequestr   CheckUpgrade)r!  r+   r   r-  r.  s        r   rj  rj    sd     --MJ."[[!..0(<<$ = & \ '/ 
-	0	=	=o	NNr   c                     t        |      j                  t        j                  |      j	                  | j                                     S )a?  Calls the Composer Environments.Get method.

  Args:
    environment_ref: Resource, the Composer environment resource to retrieve.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    Environment: the requested environment
  r   r  )r   Getr   r  /ComposerProjectsLocationsEnvironmentsGetRequestr  r(  s     r   rl  rl    sF     
-	0	4	4  }=66++- 7 /
0 0r   Nc                     t        j                  t        j                  |      j                  t	        |      | d||      S )aJ  Lists Composer Environments across all locations.

  Uses a hardcoded list of locations, as there is no way to dynamically
  discover the list of supported locations. Support for new locations
  will be aligned with Cloud SDK releases.

  Args:
    location_refs: [core.resources.Resource], a list of resource reference to
      locations in which to list environments.
    page_size: An integer specifying the maximum number of resources to be
      returned in a single list call.
    limit: An integer specifying the maximum number of environments to list.
      None if all available environments should be returned.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    list: a generator over Environments in the locations in `location_refs`
  r   environments)limit)r   AggregateListResultsr  0ComposerProjectsLocationsEnvironmentsListRequestr   )location_refs	page_sizerp  r   s       r   Listru    s?    . 
	&	&  }=77}-
 r   c                    	 t        |      j                  t        j                  |      j	                  | j                         ||            S # t        j                  $ r}t        j                  |d      d}~ww xY w)a  Calls the Composer Environments.Update method.

  Args:
    environment_ref: Resource, the Composer environment resource to update.
    environment_patch: The Environment message specifying the patch associated
      with the update_mask.
    update_mask: A field mask defining the patch.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    Operation: the operation corresponding to the environment update
  r   )r  r  
updateMaskzUpdate operation failed because of lack of proper permissions. Please, refer to https://cloud.google.com/composer/docs/how-to/managing/updating and Composer Update Troubleshooting pages to resolve this issue.r  N)
r   Patchr   r  1ComposerProjectsLocationsEnvironmentsPatchRequestr  r  r  r   r   )r!  environment_patchupdate_maskr   r"  s        r   rx  rx  =  s    "QM288""?	:	: --/)" 
; 
$% % 
	/	/ Q

"
"	OQ QQs   AA B $A;;B c                     t        j                  |      }|j                  | D cg c]'  }|j                  |d   |j	                  d            ) c}      S c c}w )a&  Builds a WebServerNetworkAccessControl proto given an IP range list.

  If the list is empty, the returned policy is set to ALLOW by default.
  Otherwise, the default policy is DENY with a list of ALLOW rules for each
  of the IP ranges.

  Args:
    web_server_access_control: [{string: string}], list of IP ranges with
      descriptions.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Composer client library will be used.

  Returns:
    WebServerNetworkAccessControl: proto to be sent to the API.
  r   ip_rangedescription)valuer~  )allowedIpRanges)r   r  WebServerNetworkAccessControlAllowedIpRangeget)r=   r   r   r}  s       r   r   r   _  su    " ''mD(		/	/ 0A 0( $(,,}2M  O/A	/ 
  As   ,Ac                 &    |rg S |r
ddddddgS | S )a  Returns the list of IP ranges that will be sent to the API.

  The resulting IP range list is determined by the options specified in
  environment create or update flags.

  Args:
    allowed_ip_list: [{string: string}], list of IP ranges with descriptions.
    allow_all: bool, True if allow all flag was set.
    deny_all: bool, True if deny all flag was set.

  Returns:
    [{string: string}]: list of IP ranges that will be sent to the API, taking
        into account the values of allow all and deny all flags.
  z	0.0.0.0/0z5Allows access from all IPv4 addresses (default value))r}  r~  z::0/0z5Allows access from all IPv6 addresses (default value)rr   )allowed_ip_list	allow_alldeny_alls      r   BuildWebServerAllowedIpsr  x  s9     IN N  
r   c                     | r| dz	  S | S )zReturns a disk size value in GB.

  Args:
    disk_size: int, size in bytes, or None for default value

  Returns:
    int, size in GB
     rr   )	disk_sizes    r   DiskSizeBytesToGBr    s     &b494r   c                 :    | s| S t        | t        d      z  d      S )zReturns a memory size value in GB.

  Args:
    memory_size: int, size in bytes, or None for default value

  Returns:
    float, size in GB rounded to 3 decimal places
  i   @   )roundfloat)memory_sizes    r   MemorySizeBytesToGBr    s#     
	{U7^+Q	//r   )0ro   
__future__r   r   r   apitools.base.pyr   r  googlecloudsdk.api_lib.composerr   r   googlecloudsdk.api_lib.utilgooglecloudsdk.callioper   )googlecloudsdk.command_lib.composer.flagsr	   r
   r   r   r   r   rp   rq   r   r   r   r   r   r  r   r&  r+  r   r3  r=  rJ  rS  r\  rb  re  rj  rl  ru  rx  r   r  r  r  rr   r   r   <module>r     s   ; &  ' > < 2 ( P O M L K I "..11 5
C) C)L
,^sl-8`(V
* +/*;*;*>*> 0" 594E4E4H4H E*  $0066O:  $0066#OV ##))P ##))%\ ##))#L 594E4E4K4K , +/*;*;*A*A.  $0033O. (,'8'8';'; 0& ((++H )),,QD28	50r   