def cluster_config(ctx, name, vdc, org, k8_runtime=None, cluster_id=None): """Display cluster configuration. \b Examples: vcd cse cluster config my-cluster (Supported only for vcd api version < 35) \b vcd cse cluster config -k native my-cluster (Supported only for vcd api version >= 35) To write to a file: `vcd cse cluster config mycluster > ~/.kube/my_config` \b vcd cse cluster config --id urn:vcloud:entity:cse:nativeCluster:1.0.0:0632c7c7-a613-427c-b4fc-9f1247da5561 (--id option is supported only for vcd api version >= 35) """ # noqa: E501 CLIENT_LOGGER.debug(f'Executing command: {ctx.command_path}') try: if not (cluster_id or name): # --id is not required when working with api version 33 and 34 raise Exception( "Please specify cluster name (or) cluster Id. " "Note that '--id' flag is applicable for API versions >= 35 only." ) # noqa: E501 client_utils.cse_restore_session(ctx) if client_utils.is_cli_for_tkg_only(): if k8_runtime in [ shared_constants.ClusterEntityKind.NATIVE.value, shared_constants.ClusterEntityKind.TKG_PLUS.value ]: # noqa: E501 # Cannot run the command as cse cli is enabled only for native raise CseServerNotRunningError() k8_runtime = shared_constants.ClusterEntityKind.TKG.value client = ctx.obj['client'] cluster = Cluster(client, k8_runtime=k8_runtime) if not client.is_sysadmin() and org is None: org = ctx.obj['profiles'].get('org_in_use') cluster_config = \ cluster.get_cluster_config(name, cluster_id=cluster_id, vdc=vdc, org=org) \ .get(shared_constants.RESPONSE_MESSAGE_KEY) # noqa: E501 if os.name == 'nt': cluster_config = str.replace(cluster_config, '\n', '\r\n') click.secho(cluster_config) CLIENT_LOGGER.debug(cluster_config) except Exception as e: stderr(e, ctx) CLIENT_LOGGER.error(str(e))
def cluster_config(ctx, name, vdc, org): """Display cluster configuration. To write to a file: `vcd cse cluster config mycluster > ~/.kube/my_config` """ try: restore_session(ctx) client = ctx.obj['client'] cluster = Cluster(client) if not client.is_sysadmin() and org is None: org = ctx.obj['profiles'].get('org_in_use') cluster_config = cluster.get_cluster_config(name, vdc=vdc, org=org).get(RESPONSE_MESSAGE_KEY) # noqa: E501 if os.name == 'nt': cluster_config = str.replace(cluster_config, '\n', '\r\n') click.secho(cluster_config) except Exception as e: stderr(e, ctx)