linting cleanups

This commit is contained in:
Neill Cox 2023-09-22 17:35:29 +10:00
parent 3bf347f7a2
commit 4daf1b9c2f
5 changed files with 672 additions and 8 deletions

View file

@ -1,3 +1,7 @@
"""
Use virt-install to create a VM suitable for installing a RHOSP/tripleo AIO
"""
import argparse
import pathlib
import subprocess
@ -8,6 +12,7 @@ ND_PATH = "./network-config"
def parse_args():
"""Parse the command line arguments"""
parser = argparse.ArgumentParser()
parser.add_argument("--password", required=True)
parser.add_argument("--public-key", required=True, type=open)
@ -60,23 +65,34 @@ def parse_args():
def write_user_data(user_data):
"""Write out a temporary user data file"""
with open(UD_PATH, "w", encoding="utf-8") as user_data_file:
user_data_file.write(user_data)
def write_meta_data(meta_data):
"""Write out a temporary meta data file"""
with open(MD_PATH, "w", encoding="utf-8") as meta_data_file:
meta_data_file.write(meta_data)
def write_network_data(network_data):
"""Write out a temporary network data file"""
with open(ND_PATH, "w", encoding="utf-8") as network_data_file:
network_data_file.write(network_data)
def create_image(args):
"""
Create a new image file bashed on the input image, resized to the
specified size.
"""
print("creating image")
cmd = f"qemu-img create -f qcow2 -o preallocation=metadata {args.output_image} {args.image_size}"
cmd = (
"qemu-img create -f qcow2 -o preallocation=metadata "
f"{args.output_image} {args.image_size}"
)
result = subprocess.check_output(cmd, shell=True, universal_newlines=True)
if args.verbose:
@ -92,6 +108,7 @@ def create_image(args):
def virt_install_cmd(args):
"""Build and execute the virt-install command"""
cmd = f"""
sudo virt-install \\
--os-variant {args.os_variant} \\
@ -119,15 +136,21 @@ def virt_install_cmd(args):
def delete_meta_data():
"""Delete the temporary metadata file"""
pathlib.Path.unlink(pathlib.Path(MD_PATH))
def delete_user_data():
"""Delete the temporary userdata file"""
pathlib.Path.unlink(pathlib.Path(UD_PATH))
def install_packages(args):
cmd = "sudo dnf install -y virt-install virt-viewer qemu-img libguestfs.x86_64"
"""Install the packages needed for virt-install to work"""
cmd = (
"sudo dnf install -y virt-install virt-viewer qemu-img "
"libguestfs.x86_64"
)
print("installing needed packages...")
@ -138,6 +161,7 @@ def install_packages(args):
def main():
"""main function"""
args = parse_args()
if args.verbose:

View file

@ -112,7 +112,7 @@ def assign_member_role(args):
def create_public_network(args):
"""Coming soon - create the public network"""
# pylint: disable=unused-argument
# pylint: disable=unused-argument,unused-variable
print("creating public network - NYI")
cmd = (
"network create --external --provider-physical-network datacentre "
@ -128,7 +128,7 @@ def create_public_network(args):
def create_private_network(args):
"""Coming soon - create the private network"""
# pylint: disable=unused-argument
# pylint: disable=unused-argument,unused-variable
cmd = "openstack network create --internal private"
cmd = (
"openstack subnet create private-net "

View file

@ -62,7 +62,7 @@ def destroy_project(args):
f"project delete -f json --domain {args.project_domain} "
f"{args.project_id}"
)
print(f"Project deleted")
print(f"Project {args.project_name} deleted")
else:
print("Project {args.project_name} not found.")
@ -110,7 +110,7 @@ def assign_member_role(args):
def destroy_public_network(args):
"""Coming soon - create the public network"""
# pylint: disable=unused-argument
# pylint: disable=unused-argument,unused-variable
print("creating public network - NYI")
cmd = (
"network create --external --provider-physical-network datacentre "
@ -126,7 +126,7 @@ def destroy_public_network(args):
def destroy_private_network(args):
"""Coming soon - create the private network"""
# pylint: disable=unused-argument
# pylint: disable=unused-argument,unused-variable
cmd = "openstack network create --internal private"
cmd = (
"openstack subnet create private-net "

View file

@ -102,6 +102,7 @@ def build_containers_yaml(args):
def deploy_sh(args):
"""Write out a deploy script"""
home = os.environ.get("HOME")
template = (
@ -122,7 +123,10 @@ def deploy_sh(args):
def set_hostname(args):
pass
"""Set the hostname - NYI"""
# pylint: disable=unused-argument
print("set_hostname is not yet implemented")
def main():