From 91d8af9280a9f8a559342bfb460c7ab61c33cd65 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Sun, 21 Aug 2022 01:12:55 +0200 Subject: [PATCH] Changed inputs from yaml file. --- pve-vm-python/Pulumi.yaml | 3 ++- pve-vm-python/README.md | 7 ++++++ pve-vm-python/__main__.py | 45 ++++++++++++++++------------------ pve-vm-python/input.yaml | 22 +++++++++++++++++ pve-vm-python/requirements.txt | 3 +++ 5 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 pve-vm-python/README.md create mode 100644 pve-vm-python/input.yaml diff --git a/pve-vm-python/Pulumi.yaml b/pve-vm-python/Pulumi.yaml index 2289d87..e38fa0f 100644 --- a/pve-vm-python/Pulumi.yaml +++ b/pve-vm-python/Pulumi.yaml @@ -1,5 +1,6 @@ +--- name: ${PROJECT} description: ${DESCRIPTION} runtime: python template: - description: A minimal Python Pulumi program + description: A ProxmoxVE VM template with Python diff --git a/pve-vm-python/README.md b/pve-vm-python/README.md new file mode 100644 index 0000000..a8c6fed --- /dev/null +++ b/pve-vm-python/README.md @@ -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 diff --git a/pve-vm-python/__main__.py b/pve-vm-python/__main__.py index 3c57fb5..f9d044e 100644 --- a/pve-vm-python/__main__.py +++ b/pve-vm-python/__main__.py @@ -1,23 +1,24 @@ -"""A Pulumi-based infrastructure with Proxmox VE and Python""" +"""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() -data = config.require_object("pve") provider = proxmox.Provider("proxmoxve", virtual_environment = { - "endpoint": data.get("endpoint"), - "insecure": True, - "username": "root@pam", - "password": data.get("password") + "endpoint": conf.pve.url, + "insecure": conf.pve.insecure, + "username": conf.pve.username, + "password": config.require_secure("password") } ) -vm = proxmox.vm.VirtualMachine("vm", - name = "virtual-machine", - node_name = data.get("node_name"), +vm = proxmox.vm.VirtualMachine(conf.vm.name, + node_name = conf.pve.nodename, agent = proxmox.vm.VirtualMachineAgentArgs( enabled = True, trim = True, @@ -25,22 +26,22 @@ vm = proxmox.vm.VirtualMachine("vm", ), bios = "seabios", cpu = proxmox.vm.VirtualMachineCpuArgs( - cores = 1, - sockets = 1 + cores = conf.vm.cores, + sockets = conf.vm.sockets ), memory = proxmox.vm.VirtualMachineMemoryArgs( - dedicated = 2048 + dedicated = conf.vm.ram ), clone = proxmox.vm.VirtualMachineCloneArgs( - node_name = data.get("node_name"), - vm_id = config.require("clonevm"), + node_name = conf.pve.nodename, + vm_id = conf.vm.clone, full = True ), disks = [ proxmox.vm.VirtualMachineDiskArgs( interface = "virtio0", - datastore_id = "local-lvm", - size = 20, + datastore_id = conf.pve.storage, + size = conf.vm.disksize, file_format = "qcow2" ) ], @@ -56,15 +57,11 @@ vm = proxmox.vm.VirtualMachine("vm", ), initialization = proxmox.vm.VirtualMachineInitializationArgs( type = "nocloud", - datastore_id = "local-lvm", + datastore_id = conf.pve.storage, user_account = proxmox.vm.VirtualMachineInitializationUserAccountArgs( - username = "syntaxerrormmm", - password = "cicciopasticcio", - keys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso", - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps", - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo" - ] + username = conf.vm.username, + password = conf.vm.password, + keys = conf.vm.sshkeys ) ), opts = pulumi.ResourceOptions( diff --git a/pve-vm-python/input.yaml b/pve-vm-python/input.yaml new file mode 100644 index 0000000..de8f3fa --- /dev/null +++ b/pve-vm-python/input.yaml @@ -0,0 +1,22 @@ +--- +pve: + url: "https://pve.vavassori.lcl:8006" + insecure: true + username: root@pam + nodename: pve + storage: local-lvm + +# Basic VM configuration +vm: + name: virtual-machine + clone: 802 + sockets: 1 + cores: 1 + ram: 2048 + disksize: 20 + username: syntaxerrormmm + password: cicciopasticcio + sshkeys: + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso" + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps" + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo" diff --git a/pve-vm-python/requirements.txt b/pve-vm-python/requirements.txt index 3d56c46..94544cf 100644 --- a/pve-vm-python/requirements.txt +++ b/pve-vm-python/requirements.txt @@ -1,2 +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