Renaming projects for quick retrieval.
This commit is contained in:
parent
9b8c772615
commit
fbf68c67b9
43 changed files with 112 additions and 1 deletions
2
vm/.gitignore
vendored
Normal file
2
vm/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.pyc
|
||||
venv/
|
6
vm/Pulumi.yaml
Normal file
6
vm/Pulumi.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
name: ${PROJECT}
|
||||
description: ${DESCRIPTION}
|
||||
runtime: python
|
||||
template:
|
||||
description: A Pulumi deployment with libvirt and Python
|
9
vm/README.md
Normal file
9
vm/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Quick configuration #
|
||||
|
||||
To quickly set up your pulumi deployment, configure the following settings:
|
||||
|
||||
$ pulumi config set libvirt:uri --plaintext "qemu:///system"
|
||||
$ pulumi config set image_url --plaintext "https://cdimage.debian.org/images/cloud/bullseye-backports/20220711-1073/debian-11-backports-generic-amd64-20220711-1073.qcow2"
|
||||
$ pulumi config set disksize --plaintext 20
|
||||
$ pulumi config set memory --plaintext 2048
|
||||
|
57
vm/__main__.py
Normal file
57
vm/__main__.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
"""A Pulumi deployment with libvirt and Python"""
|
||||
# vim:sts=4:sw=4
|
||||
|
||||
import yaml
|
||||
from dotmap import DotMap
|
||||
import pulumi
|
||||
import pulumi_libvirt as lv
|
||||
from passlib.hash import sha512_crypt
|
||||
from jinja2 import Template
|
||||
|
||||
conf = DotMap(yaml.safe_load(open("input.yaml").read()))
|
||||
cloudimages = DotMap(yaml.safe_load(open("cloud-images.yaml").read()))
|
||||
conf.password = sha512_crypt.hash(conf.password, rounds=4096)
|
||||
config = pulumi.Config()
|
||||
|
||||
pool = lv.Pool("mypool", type="dir", path=conf.poolpath)
|
||||
baseimg = lv.Volume("myimage", pool=pool.name, source=cloudimages[conf.image])
|
||||
|
||||
volume = lv.Volume("mydisk",
|
||||
base_volume_id=baseimg.id,
|
||||
pool=pool.name,
|
||||
size=int(conf.disksize) * 1024 ** 3
|
||||
)
|
||||
|
||||
# Stream configuration files
|
||||
userdata = Template(open("./cloud-init/user-data.jinja").read()).render(conf)
|
||||
metadata = Template(open("./cloud-init/meta-data.jinja").read()).render(conf)
|
||||
networkconfig = open("./cloud-init/network-config").read()
|
||||
|
||||
cloudinit = lv.CloudInitDisk("cloud-init",
|
||||
meta_data=metadata,
|
||||
user_data=userdata,
|
||||
network_config=networkconfig
|
||||
)
|
||||
|
||||
vm = lv.Domain(conf.name,
|
||||
boot_devices=[lv.DomainBootDeviceArgs(devs=["hd", "cdrom"])],
|
||||
cloudinit=cloudinit.id,
|
||||
vcpu=conf.vcpu,
|
||||
disks=[lv.DomainDiskArgs(volume_id=volume.id)],
|
||||
memory=int(conf.ram),
|
||||
network_interfaces=[lv.DomainNetworkInterfaceArgs(
|
||||
network_name="default",
|
||||
wait_for_lease=True
|
||||
)
|
||||
],
|
||||
consoles=[lv.DomainConsoleArgs(
|
||||
type="pty",
|
||||
target_port='0',
|
||||
target_type="serial"
|
||||
)],
|
||||
opts=pulumi.ResourceOptions(
|
||||
custom_timeouts=pulumi.CustomTimeouts(create="3m")
|
||||
)
|
||||
)
|
||||
|
||||
pulumi.export("ip", vm.network_interfaces[0]['addresses'][0])
|
3
vm/cloud-images.yaml
Normal file
3
vm/cloud-images.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
buster: https://cloud.debian.org/images/cloud/buster-backports/latest/debian-10-backports-generic-amd64.qcow2
|
||||
bullseye: https://cloud.debian.org/images/cloud/bullseye-backports/latest/debian-11-backports-generic-amd64.qcow2
|
||||
bookworm: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
|
2
vm/cloud-init/meta-data.jinja
Normal file
2
vm/cloud-init/meta-data.jinja
Normal file
|
@ -0,0 +1,2 @@
|
|||
instance-id: {{ name }}
|
||||
local-hostname: {{ name }}
|
5
vm/cloud-init/network-config
Normal file
5
vm/cloud-init/network-config
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
version: 2
|
||||
ethernets:
|
||||
ens3:
|
||||
dhcp4: true
|
24
vm/cloud-init/user-data.jinja
Normal file
24
vm/cloud-init/user-data.jinja
Normal file
|
@ -0,0 +1,24 @@
|
|||
#cloud-config
|
||||
resize_rootfs: true
|
||||
users:
|
||||
- name: {{ username }}
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
groups: users, admin
|
||||
shell: /bin/bash
|
||||
ssh_authorized_keys:
|
||||
{% for key in sshkeys %}
|
||||
- "{{ key }}"
|
||||
{% endfor %}
|
||||
hashed_passwd: {{ password }}
|
||||
ssh_pwauth: true
|
||||
disable_root: false
|
||||
chpasswd:
|
||||
expire: false
|
||||
list: |
|
||||
root:{{ password }}
|
||||
syntaxerrormmm:{{ password }}
|
||||
#packages:
|
||||
# - qemu-guest-agent
|
||||
#power_state:
|
||||
# delay: now
|
||||
# mode: reboot
|
15
vm/input.yaml
Normal file
15
vm/input.yaml
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
# Basic VM configuration
|
||||
name: virtual-machine
|
||||
vcpu: 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"
|
||||
|
||||
image: bookworm
|
||||
poolpath: /var/tmp/libvirt/pulumi
|
7
vm/requirements.txt
Normal file
7
vm/requirements.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
pyyaml>=6.0
|
||||
dotmap>=1.3.30
|
||||
protobuf==3.20.1
|
||||
pulumi>=3.0.0,<4.0.0
|
||||
pulumi_libvirt>=0.3.0
|
||||
Jinja2>=3.1.2
|
||||
passlib>=1.7.4
|
Loading…
Add table
Add a link
Reference in a new issue