def cluster_unshare(ctx, name, users, vdc, org, k8_runtime, cluster_id): """Remove access from current shared cluster users. Either the cluster name or cluster id is required. By default, this command searches for the cluster in the currently logged in user's org. \b Examples: vcd cse cluster unshare --name mycluster user1 user2 Unshare cluster 'mycluster' with FullControl access with 'user1' and 'user2' \b vcd cse cluster unshare --id urn:vcloud:entity:vmware:tkgcluster:1.0.0:71fa7b01-84dc-4a58-ae54-a1098219b057 user1 Unshare TKG-S cluster with cluster ID 'urn:vcloud:entity:vmware:tkgcluster:1.0.0:71fa7b01-84dc-4a58-ae54-a1098219b057' with 'user1' """ # noqa: E501 try: if not (cluster_id or name): raise Exception("Please specify cluster name or cluster id.") client_utils.cse_restore_session(ctx) if client_utils.is_cli_for_tkg_s_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 tkg raise CseServerNotRunningError() k8_runtime = shared_constants.ClusterEntityKind.TKG_S.value client = ctx.obj['client'] # Users should be explicit in their intent about the org on which the # command needs to be executed. is_system_user = client.is_sysadmin() if not is_system_user and org is None: org = ctx.obj['profiles'].get('org_in_use') elif is_system_user and org is None: raise Exception("Need to specify cluster org since logged in user is in system org") # noqa: E501 # If cluster kind is not specified, let the server handle this check if k8_runtime: def_utils.raise_error_if_tkgm_cluster_operation(cluster_kind=k8_runtime) # noqa: E501 users_list = list(users) cluster = Cluster(client, k8_runtime) cluster.unshare_cluster(cluster_id, name, users_list, org, vdc) stdout(f'Cluster {cluster_id or name} successfully unshared with: {users_list}') # noqa: E501 except Exception as e: stderr(e, ctx) CLIENT_LOGGER.error(str(e), exc_info=True)
def cluster_unshare(ctx, name, users, vdc, org, k8_runtime, cluster_id): """Remove access from current shared cluster users. Either the cluster name or cluster id is required. By default, this command searches for the cluster in the currently logged in user's org. \b Examples: vcd cse cluster unshare --name mycluster user1 user2 Unshare cluster 'mycluster' with FullControl access with 'user1' and 'user2' \b vcd cse cluster unshare --id urn:vcloud:entity:vmware:tkgcluster:1.0.0:71fa7b01-84dc-4a58-ae54-a1098219b057 user1 Unshare TKG cluster with cluster ID 'urn:vcloud:entity:vmware:tkgcluster:1.0.0:71fa7b01-84dc-4a58-ae54-a1098219b057' with 'user1' """ # noqa: E501 try: if not (cluster_id or name): raise Exception("Please specify cluster name or cluster id.") 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 tkg raise CseServerNotRunningError() k8_runtime = shared_constants.ClusterEntityKind.TKG.value client = ctx.obj['client'] if not org: ctx_profiles = ctx.obj['profiles'] org = ctx_profiles.get('org') users_list = list(users) cluster = Cluster(client, k8_runtime) cluster.unshare_cluster(cluster_id, name, users_list, org, vdc) stdout( f'Cluster {cluster_id or name} successfully unshared with: {users_list}' ) # noqa: E501 except Exception as e: stderr(e, ctx) CLIENT_LOGGER.error(str(e))