
    ['                        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 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(                  e	j*                  j,                  e	j*                  j.                         G d
 dej0                  ej2                               Z e	j(                  e	j*                  j6                         G d de             Zy)z2The command to view the Config Management Feature.    N)
transforms)util)
exceptions)base)	resources)utils)logc                   @    e Zd ZdZej
                  Zej
                  Zy)Describe'Describe the Config Management feature.N)__name__
__module____qualname____doc__r   CONFIG_MANAGEMENT_FEATURE_NAMEfeature_namemf_name     9lib/surface/container/fleet/config_management/describe.pyr   r      s     055,00'r   r   c                   t    e Zd ZdZddiZed        Zed        Z e	j                  d      d        Zd Zd	 Zy
)DescribeAlphar   EXAMPLESa  
To describe the entire Config Management feature, run:

  $ {command}

To describe select membership configurations, run:

  $ {command} --memberships=example-membership-1,example-membership-2

To list the membership configurations, run:

  $ {command} --view=list

MEMBERSHIP           | LOCATION    | STATUS | INSTALL_STATE             | STOP_STATE  | SYNC_STATE    | VERSION | SYNCED_TO_FLEET_DEFAULT
-------------------- | ----------- | ------ | ------------------------- | ----------- | ------------- | ------- | ----------------------------
example-membership-1 | asia-east1  | OK     | CONFIG_SYNC_NOT_INSTALLED |             | NOT_INSTALLED |         | FLEET_DEFAULT_NOT_CONFIGURED
example-membership-2 | us-central1 | OK     | CONFIG_SYNC_INSTALLED     | NOT_STOPPED | SYNCED        | 1.22.0  | FLEET_DEFAULT_NOT_CONFIGURED
example-membership-3 | us-central1 | ERROR  | CONFIG_SYNC_INSTALLED     | NOT_STOPPED | ERROR         | 1.21.3  | FLEET_DEFAULT_NOT_CONFIGURED
      c                 |   || _         |j                         }|j                  ddddddd       |j                  t        j                  d	
      }t        j                  t        j                        }|j                  d   j                         dz   |j                  d<   |j                  |       t        j                  t        j                        }|j                  d   j                         dz   |j                  d<   |j                  |       |j                  d      }t        j                  |d       y )Nz--viewzView of the feature.z(Default view. Prints the entire feature.a  
List of membership configurations. Default format is a table summary.

The `SYNCED_TO_FLEET_DEFAULT` column may display `UNKNOWN` for any membership
whose configuration has not been updated since the
[fleet-default membership configuration](https://cloud.google.com/kubernetes-engine/fleet-management/docs/manage-features)
enablement.

To view the underlying configurations instead of the table summary for select
memberships, run:

  $ {command} --view=list --format=yaml --memberships=example-membership-1,example-membership-2
            )fulllistr   T)helpchoicesdefaultrequiredz\List command flags. Only specify when `--view=list`. Does not include support for `--limit`.)categoryr   r   a>  

To filter for memberships with an overall status of `ERROR`, use the
``COLUMN~VALUE'' pattern and run:

  $ {command} --view=list --filter=STATUS~ERROR

To filter for memberships that are synced to the
fleet-default membership configuration, run:

  $ {command} --view=list --filter="spec.origin.type.synced_to_fleet_default()~YES"

`SYNCED_TO_FLEET_DEFAULT` is the only column that requires filtering on the
underlying configuration field instead of the column name. An alternative is to
`--sort-by=SYNCED_TO_FLEET_DEFAULT` and filter by eye.

To filter on a configuration field not in the table summary, in this case the
Config Sync repo, run:

  $ {command} --view=list --format=yaml --filter="spec.configmanagement.configSync.git.syncRepo~https://github.com/GoogleCloudPlatform/anthos-config-management-samples.git"
        a  

The default table summary sorts by `LOCATION` then `MEMBERSHIP`.

To sort the table by `VERSION` instead, run:

  $ {command} --view=list --sort-by=VERSION

To sort by a configuration field not in the table summary, in this case the
Config Sync repo, and print its values in a table, run:

  $ {command} --view=list --sort-by="spec.configmanagement.configSync.git.syncRepo" --format="table(MEMBERSHIP,LOCATION,spec.configmanagement.configSync.git.syncRepo:label=REPO)"
        zyMemberships to print configurations for. Errors if a specified membership does not have a configuration for this feature.)r   )plural)parser	add_groupadd_argumentr   LIST_COMMAND_FLAGScopydeepcopyFILTER_FLAGkwargsrstripAddToParserSORT_BY_FLAGr   AddMembershipResourceArg)clsr#   
view_group
list_groupfilter_with_examplessort_by_with_examplesmemberships_groups          r   ArgszDescribeAlpha.ArgsE   sF   CJ!!#J#>
  )  . %%((7 & J  ==)9)9:##F+224 8 	 '. $$Z0 MM$*;*;<$$V,335 9 	   ( %%j1((! )  &&'8Fr   c                 ~    | j                   s| j                  r%| j                  dk7  rt        j                  d      y y )Nr   z>--filter and --sort-by can only be specified when --view=list.)filtersort_byviewr   Error)argss    r   enforce_flag_combinationsz'DescribeAlpha.enforce_flag_combinations   s7    t||f)<
J  *=|r   z	{message}c                    || _         | j                  |       | j                         }|j                  r)t	        j
                  |d      }| j                  ||       |j                  dk(  r| j                  j                  j                  t        j                  | j                  |j                  d u             | j                  j                  j                  d       | j!                  |      S |S )NT)searchr   a5  table(
          name.segment(-3):label=MEMBERSHIP:sort=2,
          name.segment(-5):label=LOCATION:sort=1,
          state.state.code:label=STATUS,
          state.configmanagement.configSyncState.state:label=INSTALL_STATE,
          state.configmanagement.configSyncState.clusterLevelStopSyncingState:label=STOP_STATE,
          state.configmanagement.configSyncState.syncState.code:label=SYNC_STATE,
          state.configmanagement.membershipSpec.version:label=VERSION,
          spec.origin.type.synced_to_fleet_default():label=SYNCED_TO_FLEET_DEFAULT
      ))r;   r<   
GetFeaturemembershipsfeatures_baseParseMembershipsPluralfilter_feature_for_membershipsr9   r#   display_infoAddTransformsr   get_transforms	hubclientfleetDefaultMemberConfig	AddFormat"construct_membership_features_list)selfr;   featurer@   s       r   RunzDescribeAlpha.Run   s    DI""4(ooG "88dKk
))';?yyF
kk,,Z-F-F
..'::$F. 	 kk(( 	* 	 44W==Nr   c                    |j                   r t        j                  d|j                          |j                  sg S i }|j                  rK|j                  j
                  D ci c],  }t        j                  |j                        |j                  . }}| j                  d      }| j                  d      }|j                  j
                  D cg c]  }| j                  |j                  j                  d| dd| dd            |j                  dt        j                  |j                        |v r$d	|t        j                  |j                           ini  c}S c c}w c c}w )
NzJMembership configuration list may be incomplete. Unreachable locations: %sF)numberTz	projects//   )namespecstate)unreachabler	   warningmembershipSpecsmembershipStatesadditionalPropertiesr   MembershipPartialNamekeyvalueProjectMembershipFeatureResourceNamereplace)rK   rL   statesentry
project_idproject_numbers         r   rJ   z0DescribeAlpha.construct_membership_features_list   sn   	kk /070C0CE""iF //DDDe 
$
$UYY
/
<D   U+J\\\.N: ,,AA98 BE 66		!!/q1
|1- KK	
" --eii8FB &!;!;EII!FGH%	
* B9 s   !1E"BE'c                 |    |s:| j                   j                  dk(  r t        j                  j	                  d       y y y )Nr   zListed 0 items.)r;   r9   r	   statusPrint)rK   resources_were_displayeds     r   EpilogzDescribeAlpha.Epilog   s0    #		&(@	jj() )A#r   N)r   r   r   r   detailed_helpclassmethodr5   staticmethodr<   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionrM   rJ   rh   r   r   r   r   r   +   sq    /  
-, SG SGj   544[A B6+Z*r   r   )r   r'   &googlecloudsdk.api_lib.container.fleetr   r   googlecloudsdk.api_lib.utilr   rl   googlecloudsdk.callioper   *googlecloudsdk.command_lib.container.fleetr   <googlecloudsdk.command_lib.container.fleet.config_managementr   3googlecloudsdk.command_lib.container.fleet.featuresrA   =googlecloudsdk.command_lib.container.fleet.membershipfeaturesmembershipfeatures_basegooglecloudsdk.corer	   ReleaseTracksReleaseTrackBETAGAMembershipFeatureCommandDescribeCommandr   ALPHAr   r   r   r   <module>r~      s    9  = 7 F ( @ N U i * # D%%**D,=,=,@,@A1 44!!	1 B1 D%%++,B*H B* -B*r   