Reformat code with Black code formatter
Unify the code style along PEP and Black principles using the tool.
This commit is contained in:
@ -64,29 +64,35 @@ def install(**kwargs):
|
||||
# The provisioner has already mounted the disks on kwargs['temporary_directory'].
|
||||
# by this point, so we can get right to running the debootstrap after setting
|
||||
# some nicer variable names; you don't necessarily have to do this.
|
||||
vm_name = kwargs['vm_name']
|
||||
temporary_directory = kwargs['temporary_directory']
|
||||
disks = kwargs['disks']
|
||||
networks = kwargs['networks']
|
||||
vm_name = kwargs["vm_name"]
|
||||
temporary_directory = kwargs["temporary_directory"]
|
||||
disks = kwargs["disks"]
|
||||
networks = kwargs["networks"]
|
||||
# Our own required arguments. We should, though are not required to, handle
|
||||
# failures of these gracefully, should administrators forget to specify them.
|
||||
try:
|
||||
deb_release = kwargs['deb_release']
|
||||
deb_release = kwargs["deb_release"]
|
||||
except Exception:
|
||||
deb_release = "stable"
|
||||
try:
|
||||
deb_mirror = kwargs['deb_mirror']
|
||||
deb_mirror = kwargs["deb_mirror"]
|
||||
except Exception:
|
||||
deb_mirror = "http://ftp.debian.org/debian"
|
||||
try:
|
||||
deb_packages = kwargs['deb_packages'].split(',')
|
||||
deb_packages = kwargs["deb_packages"].split(",")
|
||||
except Exception:
|
||||
deb_packages = ["linux-image-amd64", "grub-pc", "cloud-init", "python3-cffi-backend", "wget"]
|
||||
deb_packages = [
|
||||
"linux-image-amd64",
|
||||
"grub-pc",
|
||||
"cloud-init",
|
||||
"python3-cffi-backend",
|
||||
"wget",
|
||||
]
|
||||
|
||||
# We need to know our root disk
|
||||
root_disk = None
|
||||
for disk in disks:
|
||||
if disk['mountpoint'] == '/':
|
||||
if disk["mountpoint"] == "/":
|
||||
root_disk = disk
|
||||
if not root_disk:
|
||||
return
|
||||
@ -95,9 +101,7 @@ def install(**kwargs):
|
||||
# good idea to include if you plan to use anything that is not part of the
|
||||
# base Debian host system, just in case the provisioner host is not properly
|
||||
# configured already.
|
||||
os.system(
|
||||
"apt-get install -y debootstrap"
|
||||
)
|
||||
os.system("apt-get install -y debootstrap")
|
||||
|
||||
# Perform a deboostrap installation
|
||||
os.system(
|
||||
@ -105,16 +109,12 @@ def install(**kwargs):
|
||||
suite=deb_release,
|
||||
target=temporary_directory,
|
||||
mirror=deb_mirror,
|
||||
pkgs=','.join(deb_packages)
|
||||
pkgs=",".join(deb_packages),
|
||||
)
|
||||
)
|
||||
|
||||
# Bind mount the devfs
|
||||
os.system(
|
||||
"mount --bind /dev {}/dev".format(
|
||||
temporary_directory
|
||||
)
|
||||
)
|
||||
os.system("mount --bind /dev {}/dev".format(temporary_directory))
|
||||
|
||||
# Create an fstab entry for each disk
|
||||
fstab_file = "{}/etc/fstab".format(temporary_directory)
|
||||
@ -130,11 +130,11 @@ def install(**kwargs):
|
||||
options = "defaults,discard,noatime,nodiratime"
|
||||
|
||||
# The root, var, and log volumes have specific values
|
||||
if disk['mountpoint'] == "/":
|
||||
root_disk['scsi_id'] = disk_id
|
||||
if disk["mountpoint"] == "/":
|
||||
root_disk["scsi_id"] = disk_id
|
||||
dump = 0
|
||||
cpass = 1
|
||||
elif disk['mountpoint'] == '/var' or disk['mountpoint'] == '/var/log':
|
||||
elif disk["mountpoint"] == "/var" or disk["mountpoint"] == "/var/log":
|
||||
dump = 0
|
||||
cpass = 2
|
||||
else:
|
||||
@ -142,14 +142,14 @@ def install(**kwargs):
|
||||
cpass = 0
|
||||
|
||||
# Append the fstab line
|
||||
with open(fstab_file, 'a') as fh:
|
||||
with open(fstab_file, "a") as fh:
|
||||
data = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-{disk} {mountpoint} {filesystem} {options} {dump} {cpass}\n".format(
|
||||
disk=disk_id,
|
||||
mountpoint=disk['mountpoint'],
|
||||
filesystem=disk['filesystem'],
|
||||
mountpoint=disk["mountpoint"],
|
||||
filesystem=disk["filesystem"],
|
||||
options=options,
|
||||
dump=dump,
|
||||
cpass=cpass
|
||||
cpass=cpass,
|
||||
)
|
||||
fh.write(data)
|
||||
|
||||
@ -158,12 +158,14 @@ def install(**kwargs):
|
||||
|
||||
# Write the hostname
|
||||
hostname_file = "{}/etc/hostname".format(temporary_directory)
|
||||
with open(hostname_file, 'w') as fh:
|
||||
with open(hostname_file, "w") as fh:
|
||||
fh.write("{}".format(vm_name))
|
||||
|
||||
# Fix the cloud-init.target since it's broken
|
||||
cloudinit_target_file = "{}/etc/systemd/system/cloud-init.target".format(temporary_directory)
|
||||
with open(cloudinit_target_file, 'w') as fh:
|
||||
cloudinit_target_file = "{}/etc/systemd/system/cloud-init.target".format(
|
||||
temporary_directory
|
||||
)
|
||||
with open(cloudinit_target_file, "w") as fh:
|
||||
data = """[Install]
|
||||
WantedBy=multi-user.target
|
||||
[Unit]
|
||||
@ -176,7 +178,7 @@ After=multi-user.target
|
||||
# will always be on PCI bus ID 2, hence the name "ens2".
|
||||
# Write a DHCP stanza for ens2
|
||||
ens2_network_file = "{}/etc/network/interfaces.d/ens2".format(temporary_directory)
|
||||
with open(ens2_network_file, 'w') as fh:
|
||||
with open(ens2_network_file, "w") as fh:
|
||||
data = """auto ens2
|
||||
iface ens2 inet dhcp
|
||||
"""
|
||||
@ -184,25 +186,31 @@ iface ens2 inet dhcp
|
||||
|
||||
# Write the DHCP config for ens2
|
||||
dhclient_file = "{}/etc/dhcp/dhclient.conf".format(temporary_directory)
|
||||
with open(dhclient_file, 'w') as fh:
|
||||
data = """# DHCP client configuration
|
||||
with open(dhclient_file, "w") as fh:
|
||||
data = (
|
||||
"""# DHCP client configuration
|
||||
# Written by the PVC provisioner
|
||||
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
|
||||
interface "ens2" {
|
||||
""" + """ send fqdn.fqdn = "{hostname}";
|
||||
"""
|
||||
+ """ send fqdn.fqdn = "{hostname}";
|
||||
send host-name = "{hostname}";
|
||||
""".format(hostname=vm_name) + """ request subnet-mask, broadcast-address, time-offset, routers,
|
||||
""".format(
|
||||
hostname=vm_name
|
||||
)
|
||||
+ """ request subnet-mask, broadcast-address, time-offset, routers,
|
||||
domain-name, domain-name-servers, domain-search, host-name,
|
||||
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
|
||||
netbios-name-servers, netbios-scope, interface-mtu,
|
||||
rfc3442-classless-static-routes, ntp-servers;
|
||||
}
|
||||
"""
|
||||
)
|
||||
fh.write(data)
|
||||
|
||||
# Write the GRUB configuration
|
||||
grubcfg_file = "{}/etc/default/grub".format(temporary_directory)
|
||||
with open(grubcfg_file, 'w') as fh:
|
||||
with open(grubcfg_file, "w") as fh:
|
||||
data = """# Written by the PVC provisioner
|
||||
GRUB_DEFAULT=0
|
||||
GRUB_TIMEOUT=1
|
||||
@ -212,35 +220,29 @@ GRUB_CMDLINE_LINUX=""
|
||||
GRUB_TERMINAL=console
|
||||
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
|
||||
GRUB_DISABLE_LINUX_UUID=false
|
||||
""".format(root_disk=root_disk['scsi_id'])
|
||||
""".format(
|
||||
root_disk=root_disk["scsi_id"]
|
||||
)
|
||||
fh.write(data)
|
||||
|
||||
# Chroot, do some in-root tasks, then exit the chroot
|
||||
with chroot_target(temporary_directory):
|
||||
# Install and update GRUB
|
||||
os.system(
|
||||
"grub-install --force /dev/rbd/{}/{}_{}".format(root_disk['pool'], vm_name, root_disk['disk_id'])
|
||||
)
|
||||
os.system(
|
||||
"update-grub"
|
||||
"grub-install --force /dev/rbd/{}/{}_{}".format(
|
||||
root_disk["pool"], vm_name, root_disk["disk_id"]
|
||||
)
|
||||
)
|
||||
os.system("update-grub")
|
||||
# Set a really dumb root password [TEMPORARY]
|
||||
os.system(
|
||||
"echo root:test123 | chpasswd"
|
||||
)
|
||||
os.system("echo root:test123 | chpasswd")
|
||||
# Enable cloud-init target on (first) boot
|
||||
# NOTE: Your user-data should handle this and disable it once done, or things get messy.
|
||||
# That cloud-init won't run without this hack seems like a bug... but even the official
|
||||
# Debian cloud images are affected, so who knows.
|
||||
os.system(
|
||||
"systemctl enable cloud-init.target"
|
||||
)
|
||||
os.system("systemctl enable cloud-init.target")
|
||||
|
||||
# Unmount the bound devfs
|
||||
os.system(
|
||||
"umount {}/dev".format(
|
||||
temporary_directory
|
||||
)
|
||||
)
|
||||
os.system("umount {}/dev".format(temporary_directory))
|
||||
|
||||
# Everything else is done via cloud-init user-data
|
||||
|
@ -35,9 +35,9 @@ def install(**kwargs):
|
||||
# The provisioner has already mounted the disks on kwargs['temporary_directory'].
|
||||
# by this point, so we can get right to running the debootstrap after setting
|
||||
# some nicer variable names; you don't necessarily have to do this.
|
||||
vm_name = kwargs['vm_name']
|
||||
temporary_directory = kwargs['temporary_directory']
|
||||
disks = kwargs['disks']
|
||||
networks = kwargs['networks']
|
||||
vm_name = kwargs["vm_name"]
|
||||
temporary_directory = kwargs["temporary_directory"]
|
||||
disks = kwargs["disks"]
|
||||
networks = kwargs["networks"]
|
||||
# No operation - this script just returns
|
||||
pass
|
||||
|
Reference in New Issue
Block a user