This project is a Python Flask project to showcase Vagon Computer APIs and their functionalities for the teams looking for a custom dashboard implementation.
- Computer Management: List and view all machines
- Computer Control: Start, stop, reset, and create access links for machines
- Machine Configuration: Change machine type and view available machine types
- File Management: Browse, upload, and download files (organization-wide and machine-specific)
- User Action Logs: View activity logs for machines and users
- Software Management: List available softwares and golden images
- Machine Creation: Create new machines with software pre-installation
- Clean API Client: Well-documented Python client for the Vagon API
vagon-computer-api-example/
├── vagon_api.py # Vagon API client
├── app.py # Flask application with API routes
├── templates/
│ ├── base.html # Base template with Tailwind CSS
│ ├── index.html # Computers list page
│ ├── machine_detail.html # Machine details and files
│ └── files.html # Shared files directory
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
└── README.md
-
Clone and navigate to the project:
cd vagon-management-example -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
cp .env.example .env
Edit
.envand add your Vagon API credentials:VAGON_API_KEY=your_api_key VAGON_API_SECRET=your_api_secret VAGON_BASE_URL=https://api.vagon.io -
Run the application:
python app.py
-
Open in browser:
http://localhost:5050
The vagon_api.py module can be used independently:
from vagon_api import VagonAPI
# Initialize client
client = VagonAPI(
api_key="your_api_key",
api_secret="your_api_secret"
)
# List machines
machines = client.list_machines(page=1, per_page=20)
for machine in machines['machines']:
print(f"{machine['name']}: {machine['status']}")
# Start a machine
client.start_machine(machine_id=123)
# Stop a machine
client.stop_machine(machine_id=123)
# Reset a stopped machine (deletes images, terminates instance, resets to silver image)
client.reset_machine(machine_id=123)
# Change machine type
client.set_machine_type(machine_id=123, machine_type_id=5)
# Get available machine types for a machine
machine_types = client.get_machine_available_machine_types(machine_id=456)
# Create access link (expires_in in seconds)
access = client.create_machine_access(machine_id=123, expires_in=3600)
print(f"Access link: {access['connection_link']}")
# List organization files
files = client.list_files(parent_id=0)
for f in files['files']:
print(f"{f['name']} ({f['object_type']})")
# Get storage capacity
capacity = client.get_capacity()
print(f"Used: {capacity['in_use']} / {capacity['total']} bytes")
# View user action logs
from datetime import datetime, timedelta
start_date = (datetime.now() - timedelta(days=7)).iso8601()
end_date = datetime.now().iso8601()
logs = client.list_user_action_logs(
start_date=start_date,
end_date=end_date,
organization_machine_id=123
)
# List available softwares
result = client.list_softwares()
for software in result['software']:
print(f"{software['name']}: {software['size']} GB")
# Create a new machine
result = client.create_machine(
seat_plan_id=1,
quantity=2,
software_ids=[1, 2, 3]
)
print(f"Created {result['count']} machines")GET /- List all machinesGET /machines/<id>- Machine details with filesGET /files- Browse organization-wide shared filesGET /logs- View user action logs with filters
GET /api/machines/<id>- Get machine detailsPOST /api/machines/<id>/start- Start computer- Optional body:
{"machine_type_id": 5, "region": "dublin"}
- Optional body:
POST /api/machines/<id>/stop- Stop computerPOST /api/machines/<id>/reset- Reset stopped computer- Deletes all machine images, terminates instance, resets to silver image if assigned
POST /api/machines/<id>/access- Create access link to running computer- Body:
{"expires_in": 3600}(expires_in in seconds)
- Body:
POST /api/machines/<id>/machine-type- Change machine type- Body:
{"machine_type_id": 5}
- Body:
GET /api/machines/<id>/available-machine-types- Get available machine types for machinePOST /api/machines/create- Create new machines- Body:
{"seat_plan_id": 1, "quantity": 2, "software_ids": [1,2,3]}
- Body:
GET /api/machines/<id>/files- Get machine-specific files
GET /api/files/capacity- Get storage capacity- Optional query:
?machine_id=123for machine-specific capacity
- Optional query:
POST /api/files- Create file or directoryPOST /api/files/upload- Upload file (multipart)GET /api/files/<id>/download- Get download URLPOST /api/files/<id>/complete- Complete multipart uploadDELETE /api/files/<id>- Delete file or directory
GET /api/user-action-logs- Get recent logs (last 30 days)- Query params:
start_date,end_date,action_type,user_email,organization_machine_id
- Query params:
GET /api/user-action-logs/archived-download-urls- Get archived logs (older than 30 days)- Query params:
start_date,end_date,expires_in
- Query params:
GET /api/software- List available softwares and golden images