
                            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 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dZ  ejB                  ejD                  jF                  ejD                  jH                        ejJ                   G d dejL                                      Z'y)z&Command to import an Attached cluster.    )absolute_import)division)unicode_literals)attached)	locations)base)cluster_util)flags)resource_args)	kube_util)command_util)	constants)endpoint_util)pretty_print)
exceptions)
console_io)retryNa8  
To import the fleet membership of an attached cluster in fleet ``FLEET_MEMBERSHIP'' managed in location ``us-west1'', run:

$ {command} --location=us-west1 --platform-version=PLATFORM_VERSION --fleet-membership=FLEET_MEMBERSHIP --distribution=DISTRIBUTION --context=CLUSTER_CONTEXT --kubeconfig=KUBECONFIG_PATH
c                   @    e Zd ZdZdeiZed        Zd Zd Z	d Z
d Zy)	Importz0Import fleet membership for an Attached cluster.EXAMPLESc                    t        j                  | d       t        j                  |        t        j                  |        t        j
                  | d       t        j                  |        t        j                  |        t        j                  |        t        j                  | d       t        j                  j                  |        y)z!Registers flags for this command.zto import attached cluster.T)requiredzcluster to importN)r   AddLocationResourceArgAddFleetMembershipResourceArgattached_flagsAddPlatformVersionAddDistribution
AddKubectlAddProxyConfigAddSkipClusterAdminCheckr
   AddValidateOnlyr   
ASYNC_FLAGAddToParser)parsers    1lib/surface/container/attached/clusters/import.pyArgszImport.Args4   s     ((1NO//7%%f-""6D9f%!!&)++F3	&"56OO'    c           
         |j                   j                  j                         }|j                   j                  j                         }t	        j
                  |j                        5  | j                  |||j                        }d}t        j                  t        j                  |      t        j                  |      d      5 }t        j                  |      s|j                          	 t!        j"                  |      s{t%        j&                  d       |j)                  |       t+        j,                  t.        j0                        }|j3                  t4        j6                  |ft.        j8                         | j;                  |||      }| j?                  |||       d	d	d	       |cd	d	d	       S # t*        j<                  $ r^}| j?                  |||       |j@                  d   r6tC        jD                  |j@                  d   d   |j@                  d   d           d	}~wtF        jH                  $ r d
jK                  tM        jN                  | jQ                               jS                         |j                  t        jT                  |      |j                        }	t%        j&                  |	         | j?                  |||        xY w# 1 sw Y   /xY w# 1 sw Y   y	xY w)zRuns the import command. T)
kubeconfigcontextenable_workload_identityz!Creating in-cluster install agent)max_retrials)argssleep_ms      NzTo manually clean up the in-cluster install agent, run:

$ gcloud {} container attached clusters generate-install-manifest --location={} --platform-version={} --format="value(manifest)"  {}  | kubectl delete -f -

AFTER the attach operation completes.
)+CONCEPTSlocationParsefleet_membershipr   GkemulticloudEndpointOverridelocationsId_get_manifestmembershipsIdr   KubernetesClientr   GetKubeconfig
GetContextGetSkipClusterAdminCheckCheckClusterAdminPermissionsr
   GetValidateOnlyr   InfoApplyr   Retryerr   %ATTACHED_INSTALL_AGENT_VERIFY_RETRIESRetryOnExceptionr	   verify_install_agent_deployed%ATTACHED_INSTALL_AGENT_VERIFY_WAIT_MS_import_attached_clusterRetryException_remove_manifestlast_resultr   reraiser   OperationCancelledErrorformatsix	text_typeReleaseTracklowerGetPlatformVersion)
selfr.   location_reffleet_membership_refmanifestimport_respkube_clientretryeremsgs
             r%   Runz
Import.RunD   sv   ==))//1L==99??A		4	4\5M5M	N##
2@@h k%%#11$7 ++D1#' 66t<

2
2
4)	&&t,ABh'mm&LLG $$::!^"HH %  55L"6+< 	dK:gj w 
O	N< ## 	


k8
<
 ]]1q}}Q/2AMM!4DQ4GH
11 	
 FmmD--/0668&&//5"00	  

C
 
	


k8
<
c  
O	NsL   (AK&K-B#F6K#	K6K	AH""B+KKK	KK&c                 j    t        j                         }|j                  |||      }|j                  S )N)r.   )loc_utilLocationsClient GenerateInstallManifestForImportrV   )rS   r.   rT   memberships_idlocation_clientresps         r%   r8   zImport._get_manifest   s8    ..0O;;n4 < D ==r'   c                 |    t        j                  |      s't        j                  d       |j	                  |       y y )Nz!Deleting in-cluster install agent)r
   r?   r   r@   Delete)rS   r.   rX   rV   s       r%   rI   zImport._remove_manifest   s2      &;<" 'r'   c                     t        j                         }t        j                  |j	                         dt
        j                        }t        j                  |||||t
        j                        S )N	Importing)actionkind)rT   resource_clientrU   r.   messageri   )	api_utilClustersClientr   ClusterMessageRelativeNamer   ATTACHEDr   ATTACHED_CLUSTER_KIND)rS   r.   rT   rU   cluster_clientrk   s         r%   rG   zImport._import_attached_cluster   se    ,,.N))))+G
 !&1,, r'   N)__name__
__module____qualname____doc__	_EXAMPLESdetailed_helpstaticmethodr&   r\   r8   rI   rG    r'   r%   r   r   -   s9     9y)-( (@D#
r'   r   )(rv   
__future__r   r   r   .googlecloudsdk.api_lib.container.gkemulticloudr   rl   r   r^   googlecloudsdk.callioper   -googlecloudsdk.command_lib.container.attachedr	   r
   r   r   *googlecloudsdk.command_lib.container.fleetr   2googlecloudsdk.command_lib.container.gkemulticloudr   r   r   googlecloudsdk.command_lib.runr   googlecloudsdk.corer   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   rN   rw   ReleaseTracksrP   ALPHAGADefaultUniverseOnlyCommandr   rz   r'   r%   <module>r      s    - &  ' O P ( F Q G @ K H L D 7 * 2 * 
	 D%%++T->->-A-ABqT\\ q  Cqr'   