233 lines
5.8 KiB
Markdown
233 lines
5.8 KiB
Markdown
# Proxmox Cloud Image Tool
|
|
|
|
Tool untuk membuat **template** di Proxmox menggunakan cloud image (Ubuntu, Debian, CentOS, dll) dengan Golang.
|
|
|
|
## Features
|
|
|
|
- Download cloud image dari URL
|
|
- Customize image (resize disk, inject SSH key)
|
|
- Otomatis create template di Proxmox
|
|
- Support konfigurasi via CLI flags atau YAML file
|
|
- Progress bar untuk download
|
|
- **QEMU Guest Agent support** (auto-enable)
|
|
- **Firewall configuration** (enable/disable)
|
|
|
|
## Requirements
|
|
|
|
- Go 1.19+
|
|
- SSH access ke Proxmox host
|
|
- `qemu-img` dan `virt-customize` (libguestfs-tools)
|
|
|
|
Install dependencies di Ubuntu/Debian:
|
|
```bash
|
|
sudo apt install qemu-utils libguestfs-tools
|
|
```
|
|
|
|
## Installation
|
|
|
|
### Build from source:
|
|
|
|
```bash
|
|
git clone <repo-url>
|
|
cd cloud-image
|
|
go build -o proxmox-cloud-image
|
|
```
|
|
|
|
### Install globally (Linux):
|
|
|
|
```bash
|
|
sudo cp proxmox-cloud-image /usr/local/bin/
|
|
sudo chmod +x /usr/local/bin/proxmox-cloud-image
|
|
```
|
|
|
|
Setelah install, bisa langsung dipanggil dari mana aja:
|
|
```bash
|
|
proxmox-cloud-image -h
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Menggunakan CLI flags:
|
|
|
|
```bash
|
|
proxmox-cloud-image \
|
|
-image-url "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" \
|
|
-vm-name "ubuntu-template" \
|
|
-vm-id 9000 \
|
|
-proxmox-host "192.168.1.100" \
|
|
-proxmox-user "root@pam" \
|
|
-storage "local-lvm" \
|
|
-memory 2048 \
|
|
-cores 2 \
|
|
-disk-size "20G" \
|
|
-bridge "vmbr0" \
|
|
-ssh-key "/root/.ssh/id_rsa.pub" \
|
|
-guest-agent \
|
|
-firewall
|
|
```
|
|
|
|
### Auto-find VM ID (mulai dari 10000):
|
|
|
|
```bash
|
|
proxmox-cloud-image \
|
|
-image-url "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" \
|
|
-vm-name "ubuntu-template" \
|
|
-proxmox-host "192.168.1.100" \
|
|
-guest-agent
|
|
```
|
|
|
|
### Dengan VLAN:
|
|
|
|
```bash
|
|
proxmox-cloud-image \
|
|
-image-url "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" \
|
|
-vm-name "ubuntu-template" \
|
|
-vm-id 9000 \
|
|
-proxmox-host "192.168.1.100" \
|
|
-bridge "vmbr0" \
|
|
-vlan-tag 100 \
|
|
-guest-agent \
|
|
-firewall
|
|
```
|
|
|
|
### Menggunakan config file:
|
|
|
|
```bash
|
|
proxmox-cloud-image -config config.yaml
|
|
```
|
|
|
|
Contoh `config.yaml`:
|
|
```yaml
|
|
image_url: "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
|
|
vm_name: "ubuntu-template"
|
|
vm_id: 0
|
|
storage: "local-lvm"
|
|
memory: 2048
|
|
cores: 2
|
|
disk_size: "20G"
|
|
bridge: "vmbr0"
|
|
vlan_tag: 100
|
|
ssh_key: "/root/.ssh/id_rsa.pub"
|
|
proxmox_host: "192.168.1.100"
|
|
proxmox_user: "root@pam"
|
|
proxmox_pass: ""
|
|
guest_agent: true
|
|
firewall: true
|
|
```
|
|
|
|
### Batch mode (multiple templates):
|
|
|
|
Buat file batch (contoh: `batch.txt`) dengan list config files:
|
|
```
|
|
# Ubuntu templates
|
|
configs/ubuntu-22.04.yaml
|
|
configs/ubuntu-20.04.yaml
|
|
|
|
# Debian templates
|
|
configs/debian-12.yaml
|
|
configs/debian-11.yaml
|
|
```
|
|
|
|
Jalankan batch:
|
|
```bash
|
|
proxmox-cloud-image -batch batch.txt
|
|
```
|
|
|
|
**Features:**
|
|
- Process multiple config files sekaligus
|
|
- Max 3 concurrent jobs (parallel)
|
|
- Auto-skip lines yang kosong atau comment (#)
|
|
- Summary report di akhir
|
|
|
|
## Cloud Image URLs
|
|
|
|
### Ubuntu
|
|
- Ubuntu 22.04 (Jammy): `https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img`
|
|
- Ubuntu 20.04 (Focal): `https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img`
|
|
|
|
### Debian
|
|
- Debian 12 (Bookworm): `https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2`
|
|
- Debian 11 (Bullseye): `https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2`
|
|
|
|
### CentOS Stream
|
|
- CentOS Stream 9: `https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2`
|
|
|
|
## Flags
|
|
|
|
| Flag | Default | Description |
|
|
|------|---------|-------------|
|
|
| `-config` | - | Path ke config file (YAML) |
|
|
| `-image-url` | - | URL cloud image (required) |
|
|
| `-vm-name` | cloud-vm | Nama template |
|
|
| `-vm-id` | 0 | Template ID (0 = auto-find dari 10000+) |
|
|
| `-storage` | auto-detect | Nama storage Proxmox (auto-detect jika kosong) |
|
|
| `-memory` | 2048 | Memory dalam MB |
|
|
| `-cores` | 2 | Jumlah CPU cores |
|
|
| `-disk-size` | 20G | Ukuran disk |
|
|
| `-bridge` | vmbr0 | Network bridge |
|
|
| `-vlan-tag` | 0 | VLAN tag (0 = no VLAN) |
|
|
| `-guest-agent` | false | Enable QEMU guest agent |
|
|
| `-firewall` | false | Enable firewall |
|
|
| `-ssh-key` | - | Path ke SSH public key |
|
|
| `-proxmox-host` | - | IP/hostname Proxmox (required) |
|
|
| `-proxmox-user` | root@pam | Proxmox user |
|
|
| `-proxmox-pass` | - | Proxmox password |
|
|
| `-list-storage` | - | List semua storage yang tersedia |
|
|
| `-ls` | - | Shorthand untuk `-list-storage` |
|
|
|
|
## How It Works
|
|
|
|
1. Download cloud image dari URL yang diberikan
|
|
2. Customize image (resize, inject SSH key jika ada)
|
|
3. Upload image ke Proxmox host via SCP
|
|
4. Create VM menggunakan `qm` commands
|
|
5. Import disk dan configure VM
|
|
6. Setup cloud-init
|
|
7. **Enable QEMU Guest Agent** (jika di-enable)
|
|
8. **Enable Proxmox firewall** (jika di-enable)
|
|
9. **Convert VM menjadi template** dengan `qm template`
|
|
|
|
## QEMU Guest Agent
|
|
|
|
QEMU Guest Agent adalah service yang berjalan di guest OS untuk:
|
|
- IP address discovery
|
|
- Graceful shutdown/reboot
|
|
- File system freeze/thaw
|
|
- Time synchronization
|
|
|
|
Enable dengan flag `-guest-agent` atau di config file:
|
|
```yaml
|
|
guest_agent: true
|
|
```
|
|
|
|
## Proxmox Firewall
|
|
|
|
Proxmox firewall bisa di-enable untuk template dengan flag `-firewall` atau di config file:
|
|
```yaml
|
|
firewall: true
|
|
```
|
|
|
|
Firewall akan di-enable di network interface VM.
|
|
|
|
## Clone Template
|
|
|
|
Setelah template dibuat, kamu bisa clone untuk membuat VM baru:
|
|
|
|
```bash
|
|
qm clone 9000 100 --name my-vm --full
|
|
qm set 100 --ipconfig0 ip=192.168.1.100/24,gw=192.168.1.1
|
|
qm set 100 --sshkeys /root/.ssh/id_rsa.pub
|
|
qm start 100
|
|
```
|
|
|
|
## Notes
|
|
|
|
- Tool ini menggunakan SSH untuk koneksi ke Proxmox
|
|
- Pastikan SSH key sudah di-setup untuk passwordless login
|
|
- Image akan di-download ke `/tmp` dan di-upload ke Proxmox
|
|
- Template tidak bisa di-start, harus di-clone dulu
|
|
- QEMU Guest Agent akan otomatis ter-install di guest OS yang support
|
|
|
|
## License
|
|
|
|
MIT |