feat: add automatic template resolution for debian-13 alias
This commit is contained in:
parent
0dfaadab20
commit
42767fd8bc
2 changed files with 17 additions and 3 deletions
|
|
@ -49,8 +49,8 @@ infra samba add-to-group "xmpp-users" "jdoe"
|
||||||
# List containers on a specific node
|
# List containers on a specific node
|
||||||
infra proxmox list-lxcs --node la-vmh-12
|
infra proxmox list-lxcs --node la-vmh-12
|
||||||
|
|
||||||
# Create a new container
|
# Create a new container (CLI resolves "debian-13" automatically)
|
||||||
infra proxmox create-lxc 12150 local:vztmpl/debian-13-standard_13.1-2_amd64.tar.zst "new-app" "10.32.70.100/16" "10.32.0.1" --node la-vmh-12
|
infra proxmox create-lxc 12150 debian-13 "new-app" "10.32.70.100/16" "10.32.0.1" --node la-vmh-12
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Database (PostgreSQL)
|
### 3. Database (PostgreSQL)
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,26 @@ class ProxmoxManager:
|
||||||
res = self.client.run(f"pct status {vmid}")
|
res = self.client.run(f"pct status {vmid}")
|
||||||
return res.stdout
|
return res.stdout
|
||||||
|
|
||||||
|
def resolve_template(self, alias):
|
||||||
|
"""Resolves a template alias (e.g. 'debian-13') to the latest full path on the node"""
|
||||||
|
if alias == "debian-13":
|
||||||
|
# Search for debian-13 templates in all storages
|
||||||
|
res = self.client.run("pvesm list --content vztmpl | grep 'debian-13-standard' | sort -V | tail -n 1")
|
||||||
|
if res.returncode == 0 and res.stdout.strip():
|
||||||
|
# Extract first column (Volid)
|
||||||
|
return res.stdout.split()[0]
|
||||||
|
return alias # Fallback to original if no resolution
|
||||||
|
|
||||||
def create_lxc(self, vmid, template, hostname, ip, gateway, bridge="vmbr0", storage="local-zfs", password=None):
|
def create_lxc(self, vmid, template, hostname, ip, gateway, bridge="vmbr0", storage="local-zfs", password=None):
|
||||||
|
# Resolve template if it's an alias
|
||||||
|
full_template = self.resolve_template(template)
|
||||||
|
|
||||||
# Professional creation command with sane defaults
|
# Professional creation command with sane defaults
|
||||||
cmd = f"pct create {vmid} {template} --hostname {hostname} " \
|
cmd = f"pct create {vmid} {full_template} --hostname {hostname} " \
|
||||||
f"--net0 name=eth0,bridge={bridge},ip={ip},gw={gateway} " \
|
f"--net0 name=eth0,bridge={bridge},ip={ip},gw={gateway} " \
|
||||||
f"--storage {storage} --onboot 1"
|
f"--storage {storage} --onboot 1"
|
||||||
|
|
||||||
|
|
||||||
if password:
|
if password:
|
||||||
cmd += f" --password {password}"
|
cmd += f" --password {password}"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue