This script allows you to manage Equinix Metal VMs by fetching their details, displaying their current states, and optionally deleting them. You can specify a project, skip certain VMs based on tags, and view the total cost incurred by each VM.
- Fetch and display all VMs in a specified Equinix project.
- Display VM details such as name, ID, state, owner, tags, and total cost.
- Optionally delete VMs, with the ability to skip VMs tagged as
DO_NOT_DELETE
. - Print VM details in a formatted table for easy viewing.
- Python 3.x
- The
requests
library (can be installed viapip install requests
) - An Equinix Metal API token
--token
: (Required) The API token for Equinix Metal.--project
: (Required) The name of the project to manage VMs.--delete
: (Optional) Flag to trigger deletion of VMs.--skip-do-not-delete-tags
: (Optional) Flag to skip deletion of VMs with the tagDO_NOT_DELETE
.
To fetch and display all VMs in the Zededa Test
project:
python3 equinixManageVM.py --token your_api_token --project "Zededa Test"
To fetch VMs and delete them (excluding those tagged as DO_NOT_DELETE
):
python3 equinixManageVM.py --token your_api_token --project "Zededa Test" --delete --skip-do-not-delete-tags
To force delete all VMs in the project:
python3 equinixManageVM.py --token your_api_token --project "Zededa Test" --delete
You can use this script in a Jenkins job and schedule it to run automatically (e.g., every Friday at 10 PM IST) by using the following cron expression in Jenkins:
0 16 * * 5
-
Clone the repository and navigate to the directory:
git clone https://github.com/vivek-zededa/equinix-manage.git cd equinix-manage
-
Install the required dependencies:
pip3 install -r requirements.txt
-
Execute the script using the appropriate arguments (see Usage).
The project names and their corresponding IDs are stored in a dictionary inside the script. You can modify the following mapping to add your own projects:
PROJECTS_INFO_DICT = {
'Zededa Test': 'e6df9343-8781-4f27-b942-8f9675d5e0e7',
'Zededa Development': 'ce48ed95-821d-4f9e-89d5-330f7ee52ba4'
}
-
Fetching VMs: The script makes an API call to Equinix Metal using the provided project ID and retrieves all devices (VMs) in that project.
-
Displaying VMs: It prints a formatted table with VM details, including the name, state, owner, tags, and cost.
-
VM Deletion (Optional): If the
--delete
flag is set, the script attempts to delete VMs. If the--skip-do-not-delete-tags
flag is also set, it skips any VM tagged withDO_NOT_DELETE
.
- Ensure your API token has the necessary permissions to perform delete operations if you use the
--delete
flag. - Handle your API token securely (avoid hardcoding it into scripts or committing it to version control). Use environment variables or Jenkins credentials management for security.
This project is licensed under the MIT License - see the LICENSE file for details.