Conclusa prima implementazione container su PVE.

This commit is contained in:
Emiliano Vavassori 2023-12-31 20:54:30 +01:00
parent fbf68c67b9
commit 2ed3e17ecd
7 changed files with 69 additions and 77 deletions

2
pct/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.pyc
venv/

6
pct/Pulumi.yaml Normal file
View file

@ -0,0 +1,6 @@
---
name: ${PROJECT}
description: ${DESCRIPTION}
runtime: python
template:
description: Template for an LXC container over ProxmoxVE

7
pct/README.md Normal file
View file

@ -0,0 +1,7 @@
# Quick configuration #
Check out the file `input.yml` for a quick setup for a new machine.
Also, don't forget to setup the password for your account on your ProxmoxVE
server configuring `pulumi`:
$ pulumi config set password --secret yourpvepassword

61
pct/__main__.py Normal file
View file

@ -0,0 +1,61 @@
"""A ProxmoxVE Container template with Python"""
import yaml
from dotmap import DotMap
import pulumi
import pulumi_proxmoxve as proxmox
conf=DotMap(yaml.safe_load(open("input.yaml").read()))
config = pulumi.Config()
provider=proxmox.Provider("proxmoxve",
endpoint=conf.pve.url,
insecure=conf.pve.insecure,
username=conf.pve.username,
password=config.require_secret("password")
)
ct=proxmox.ct.Container(conf.ct.name,
console=proxmox.ct.ContainerConsoleArgs(enabled=True),
cpu=proxmox.ct.ContainerCpuArgs(cores=conf.ct.cores),
disk=proxmox.ct.ContainerDiskArgs(
datastore_id=conf.ct.storage,
size=conf.ct.disksize
),
initialization=proxmox.ct.ContainerInitializationArgs(
hostname=conf.ct.name,
ip_configs=[
proxmox.ct.ContainerInitializationIpConfigArgs(
ipv4=proxmox.ct.ContainerInitializationIpConfigIpv4Args(
address="dhcp"
)
)
],
user_account=proxmox.ct.ContainerInitializationUserAccountArgs(
password=conf.ct.password,
keys=conf.ct.sshkeys
),
),
memory=proxmox.ct.ContainerMemoryArgs(
dedicated=conf.ct.ram,
swap=conf.ct.ram
),
network_interfaces=[
proxmox.ct.ContainerNetworkInterfaceArgs(
name="eth0",
bridge="vmbr0",
enabled=True
)
],
node_name=conf.pve.nodename,
operating_system=proxmox.ct.ContainerOperatingSystemArgs(
template_file_id=f"local:vztmpl/{conf.ct.template}",
type=conf.ct.template_type
),
started=True,
opts=pulumi.ResourceOptions(
provider=provider
)
)
pulumi.export("id", pulumi.Output.all(ct.id).apply(lambda x: x[0]))

22
pct/input.yaml Normal file
View file

@ -0,0 +1,22 @@
---
pve:
url: "https://pve.vavassori.lcl:8006"
insecure: true
username: root@pam
nodename: pve
# Basic VM configuration
ct:
name: container
storage: local-lvm
template: debian-12-standard_12.2-1_amd64.tar.zst
template_type: debian
cores: 1
ram: 512
swap: 512
disksize: 8
password: cicciopasticcio
sshkeys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso"
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps"
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo"

5
pct/requirements.txt Normal file
View file

@ -0,0 +1,5 @@
pyyaml>=6.0
protobuf==3.20.1
pulumi>=3.0.0,<4.0.0
pulumi-proxmoxve>=2.0.0
dotmap>=1.3.30