Query Equinix Metal
Query Equinix Metal infrastructure with cnquery
Rely on cnquery to query and inventory your Equinix Metal infrastructure. Explore devices, projects, SSH keys, and more within your Equinix Metal organization.
Requirements
To analyze your Equinix Metal environment with cnquery, you must have:
- cnquery installed on your workstation.
- An Equinix Metal account.
- An Equinix Metal API token.
Configure access to Equinix Metal
To create an API token:
- Log in to the Equinix Metal console.
- Navigate to your user settings.
- Generate an API token.
Connect to Equinix Metal
Query an organization
To query resources within an organization:
cnquery shell equinix org ORG_ID --token YOUR_API_TOKEN| For... | Substitute... |
|---|---|
| ORG_ID | Your Equinix Metal organization ID |
Query a project
To query resources within a specific project:
cnquery shell equinix project PROJECT_ID --token YOUR_API_TOKEN| For... | Substitute... |
|---|---|
| PROJECT_ID | Your Equinix Metal project ID |
You can also set the PACKET_AUTH_TOKEN environment variable to omit the --token flag.
Example queries
This query retrieves organization information:
cnquery> equinix.metal.organization
equinix.metal.organization: {
name: "My Organization"
...
}This query retrieves all projects:
cnquery> equinix.metal.projects
equinix.metal.projects: [
0: equinix.metal.project name="Production"
1: equinix.metal.project name="Development"
...
]This query retrieves all devices:
cnquery> equinix.metal.devices
equinix.metal.devices: [
0: equinix.metal.device hostname="server-1"
...
]This query retrieves SSH keys:
cnquery> equinix.metal.sshKeys
equinix.metal.sshKeys: [
0: equinix.metal.sshKey label="my-key"
...
]This query lists devices with their details:
cnquery> equinix.metal.devices { hostname state facility plan }Exit the cnquery shell
To exit the cnquery shell, either press Ctrl + D or type exit.
Learn more
-
To learn more about how the MQL query language works, read Write Effective MQL.
-
For a list of all the Equinix resources and fields you can query, read the Equinix Resource Pack Reference.