Skip to content

NeckBeardPrince/hostname-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hostname Generator API

Overview

This project provides a fully containerized hostname generator API that allows you to generate random server hostnames based on predefined themes. It includes a FastAPI backend, a Vue.js Web UI, MongoDB for storage, and MQTT for auto-assigning hostnames to Raspberry Pi devices.

Features

  • βœ… Random hostname generation based on different themes
  • βœ… MongoDB-backed persistence for themes and names
  • βœ… Web UI for managing themes and names
  • βœ… Auto-assign hostnames to Raspberry Pi devices via MQTT
  • βœ… Podman/Docker Compose for easy deployment
  • βœ… Swagger API documentation

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/your-username/hostname-generator.git
cd hostname-generator

2. Setup Environment Variables

Create a .env file inside webui/:

echo "VITE_API_BASE_URL=http://backend:8000" > webui/.env

3. Build and Run the Services

podman-compose up -d --build

4. Access the Web UI

Once everything is running, open your browser and go to:

http://localhost:8080

5. Verify Running Containers

To check if all containers are running properly:

podman ps

πŸ“Œ API Endpoints

Swagger Docs

You can access the Swagger API Documentation at:

http://localhost:8000/docs

This provides an interactive way to test API calls.

Sample API Requests

Get a Random Hostname from a Theme

curl http://localhost:8000/dc

Response:

{ "batman" }

List All Themes

curl http://localhost:8000/themes

Response:

["dc", "marvel", "dinosaurs"]

View Names in a Theme

curl http://localhost:8000/theme/dc

Response:

["batman", "superman", "joker"]

Add a New Theme

curl -X POST "http://localhost:8000/add_theme/starwars" -H "Content-Type: application/json" -d '["yoda", "vader", "skywalker"]'

Add Names to an Existing Theme

curl -X POST "http://localhost:8000/add_names/starwars" -H "Content-Type: application/json" -d '["chewbacca", "han-solo"]'

Delete a Theme

curl -X DELETE "http://localhost:8000/remove_theme/starwars"

Remove a Specific Name from a Theme

curl -X DELETE "http://localhost:8000/remove_name/dc/joker"

Update a Name within a Theme

curl -X PUT "http://localhost:8000/update_name/dc?old_name=superman&new_name=man-of-steel"

πŸ› οΈ Automating Hostname Assignment on Raspberry Pi

This project supports automatic hostname assignment using MQTT. When a Raspberry Pi boots up, it can request a hostname from a specific theme and automatically set it.

1. Install Mosquitto MQTT Client

sudo apt install mosquitto mosquitto-clients

2. Create the Auto-Hostname Script

Save this as /home/pi/get_hostname.sh:

#!/bin/bash
THEME="dc"
MQTT_BROKER="mqtt"

# Request hostname
mosquitto_pub -h $MQTT_BROKER -t "hostname/request" -m "$THEME"

# Listen for response
mosquitto_sub -h $MQTT_BROKER -t "hostname/response/$THEME" -C 1 | xargs sudo hostnamectl set-hostname

3. Run the Script on Boot

Edit /etc/rc.local and add:

bash /home/pi/get_hostname.sh &

Reboot the Raspberry Pi, and it will automatically request a hostname from the API! πŸŽ‰


🐳 Managing Containers

View Running Containers

podman ps

Stop Everything

podman-compose down

Rebuild Everything

podman-compose up -d --build

View Logs

podman logs backend
podman logs webui

🎯 Future Enhancements

  • βœ… DNS Integration – Auto-map hostnames to IP addresses
  • βœ… Webhook Support – Notify when a hostname is assigned
  • βœ… More Themes – Star Trek, Harry Potter, LOTR, Cyberpunk, etc.

πŸ“œ License

This project is open-source under the MIT License.


πŸŽ‰ Credits

Created with ❀️ by Adam Stracener πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •