diff --git a/pve-ct-python/.gitignore b/pct/.gitignore similarity index 100% rename from pve-ct-python/.gitignore rename to pct/.gitignore diff --git a/pve-ct-python/Pulumi.yaml b/pct/Pulumi.yaml similarity index 55% rename from pve-ct-python/Pulumi.yaml rename to pct/Pulumi.yaml index e38fa0f..1bf509d 100644 --- a/pve-ct-python/Pulumi.yaml +++ b/pct/Pulumi.yaml @@ -3,4 +3,4 @@ name: ${PROJECT} description: ${DESCRIPTION} runtime: python template: - description: A ProxmoxVE VM template with Python + description: Template for an LXC container over ProxmoxVE diff --git a/pve-ct-python/README.md b/pct/README.md similarity index 100% rename from pve-ct-python/README.md rename to pct/README.md diff --git a/pct/__main__.py b/pct/__main__.py new file mode 100644 index 0000000..628ede2 --- /dev/null +++ b/pct/__main__.py @@ -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])) diff --git a/pve-ct-python/input.yaml b/pct/input.yaml similarity index 77% rename from pve-ct-python/input.yaml rename to pct/input.yaml index 904d2f1..713193c 100644 --- a/pve-ct-python/input.yaml +++ b/pct/input.yaml @@ -4,16 +4,17 @@ pve: insecure: true username: root@pam nodename: pve - storage: local # Basic VM configuration ct: - name: virtual-machine - clone: 802 - sockets: 1 + name: container + storage: local-lvm + template: debian-12-standard_12.2-1_amd64.tar.zst + template_type: debian cores: 1 - ram: 2048 - disksize: 20 + ram: 512 + swap: 512 + disksize: 8 password: cicciopasticcio sshkeys: - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso" diff --git a/pve-ct-python/requirements.txt b/pct/requirements.txt similarity index 100% rename from pve-ct-python/requirements.txt rename to pct/requirements.txt diff --git a/pve-ct-python/__main__.py b/pve-ct-python/__main__.py deleted file mode 100644 index 2be7560..0000000 --- a/pve-ct-python/__main__.py +++ /dev/null @@ -1,70 +0,0 @@ -"""A ProxmoxVE VM 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", - virtual_environment = { - "endpoint": conf.pve.url, - "insecure": conf.pve.insecure, - "username": conf.pve.username, - "password": config.require_secret("password") - } -) - -ct = proxmox.ct.Container(conf.ct.name, - clone = proxmox.ct.ContainerCloneArgs( - vm_id = conf.ct.clone, - full = True - ), - console = proxmox.ct.ConsoleArgs( - type = "serial", - tty_count = 1, - enabled = True - ), - cpu = proxmox.ct.ContainerCpuArgs(cores = conf.ct.cores), - disk = proxmox.ct.ContainerDiskArgs(datastore_id = conf.pve.storage), - 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("mynic", - bridge = "vmbr0", - enabled = True - ) - ], - node_name = conf.pve.nodename, - operating_system = proxmox.ct.ContainerOperatingSystemArgs( - template_file_id = "debian-11-standard_11.3-1_amd64.tar.zst" - ), - started = True, - opts = pulumi.ResourceOptions( - provider = provider - ) -) - -# Getting local IP -# First item of the ipv4_addresses is of the loopback interface (so the usual 127.0.0.1). Let's get the second and grab only the text. -lanip = ct.initialization["ip_configs"]["ipv4"]["address"][0] - -pulumi.export("ip", lanip)