Skip to content

Accessing TMC via API and CLI

+++ author = "Shubham Sharma" title = "Accessing TMC via API and CLI" menuTitle = "How to access TMC using API and tmc cli" date = "2022-08-17" description = "How to access TMC using API and tmc cli" series = ["TMC"] codeMaxLines = 15 +++

Accessing TMC via API

Get CSP token

  • Log in to the VMware Cloud Services, select your user profile in the top-right corner, and click My Account.
  • In the My Account page, click API Tokens, and then click Generate Token.
  • Select the required organization roles and the service roles. Depending on your requirement, you can specifically select either the organization roles or the service roles.
  • Click Generate.
  • Copy or save the generated token.

image

Get Access token

Use the Access token to call the TMC API

export TMC_ORG_FQDN='<org-name>.tmc.cloud.vmware.com'

# List management clusters
curl -s -X  GET https://$TMC_ORG_FQDN/v1alpha1/managementclusters --header "Authorization: Bearer $ACCESS_TOKEN" | jq .managementClusters[].fullName.name

Helpful API commands

API Documentation

List all management clusters

curl -s -X  GET https://$TMC_ORG_FQDN/v1alpha1/managementclusters --header "Authorization: Bearer $ACCESS_TOKEN" | jq .managementClusters[].fullName.name

Get Management cluster status

curl -s -X  GET https://$TMC_ORG_FQDN/v1alpha1/managementclusters/mgmt-slot35rp02 --header "Authorization: Bearer $ACCESS_TOKEN" | jq .managementCluster.status.conditions

Get Management cluster health Details

curl -s -X  GET https://$TMC_ORG_FQDN/v1alpha1/managementclusters/mgmt-slot35rp02 --header "Authorization: Bearer $ACCESS_TOKEN" | jq .managementCluster.status.healthDetails

Accessing TMC via CLI

Installing CLI

Install the Tanzu Mission Control CLI (tmc)

  • In the left navigation pane of the Tanzu Mission Control console, click Automation center.
  • On the Automation Center page, click Download CLI, and then choose the environment where you want to use the CLI.
chmod +x tmc
sudo mv tmc /usr/local/bin/tmc
tmc version

Get the CSP token

You can export the CSP token using the steps described in the previous section

export TMC_API_TOKEN=<CSP token>
export TMC_CONTEXT_NAME="tmc-ctx"

tmc login --no-configure --name "${TMC_CONTEXT_NAME}"

# To confirm your context is added
tmc system context list

Some helpful TMC CLI commands

# List all management clusters under your org
tmc managementcluster list

# List all workload clusters
tmc cluster list