linter cleanups

This commit is contained in:
Neill Cox 2023-09-18 11:22:38 +00:00
parent f149153c53
commit 3e1c3f4e2e

View file

@ -3,19 +3,23 @@ Quick and dirty script to help setup project, flavors, networks, images
""" """
import argparse import argparse
import json import json
import os
# import os
import subprocess import subprocess
def openstack_cmd(cmd): def openstack_cmd(cmd):
"""Utility function to run an openstack command agains the standalone cloud"""
cmd = "OS_CLOUD=standalone openstack " + cmd cmd = "OS_CLOUD=standalone openstack " + cmd
result = subprocess.check_output(cmd, shell=True, universal_newlines=True) result = subprocess.check_output(cmd, shell=True, universal_newlines=True)
return result return result
def parse_args(): def parse_args():
"""Parse the command line arguments""" """Parse the command line arguments"""
home = os.environ.get('HOME') # home = os.environ.get('HOME')
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-d", "--project-domain", default="default") parser.add_argument("-d", "--project-domain", default="default")
@ -31,9 +35,11 @@ def parse_args():
def create_project(args): def create_project(args):
"""Create the project if it doesn't already exist"""
cmd = "project list -f json" cmd = "project list -f json"
project_exists = [ project_exists = [
x for x in json.loads(openstack_cmd(cmd)) x
for x in json.loads(openstack_cmd(cmd))
if x["Name"] == args.project_name if x["Name"] == args.project_name
] ]
@ -51,11 +57,12 @@ def create_project(args):
print(f"Project created - id: {args.project_id}") print(f"Project created - id: {args.project_id}")
def create_user(args): def create_user(args):
"""Create the user if it doesn't already exist"""
cmd = "user list -f json" cmd = "user list -f json"
user_exists = [ user_exists = [
x for x in json.loads(openstack_cmd(cmd)) x for x in json.loads(openstack_cmd(cmd)) if x["Name"] == args.username
if x["Name"] == args.username
] ]
if user_exists: if user_exists:
@ -72,43 +79,74 @@ def create_user(args):
print(f"User created - id: {args.user_id}") print(f"User created - id: {args.user_id}")
def assign_member_role(args): def assign_member_role(args):
"""
Assign the member role to the user.
Note: it doesn't matter if the role is assigned multiple times, so not
bothering to check.
"""
cmd = f"role add --user {args.username} --project {args.project_id} member" cmd = f"role add --user {args.username} --project {args.project_id} member"
result = openstack_cmd(cmd) result = openstack_cmd(cmd)
cmd = f"role assignment list --user {args.user_id} --role member -f json" cmd = f"role assignment list --user {args.user_id} --role member -f json"
result = json.loads(openstack_cmd(cmd)) result = json.loads(openstack_cmd(cmd))
if result: if result:
print("User has member role") print("User has member role")
def create_public_network(args): def create_public_network(args):
"""Coming soon - create the public network"""
# pylint: disable=unused-argument
print("creating public network - NYI") print("creating public network - NYI")
def create_private_network(args): def create_private_network(args):
"""Coming soon - create the private network"""
# pylint: disable=unused-argument
print("creating private network - NYI") print("creating private network - NYI")
def create_cirros_flavor(args): def create_cirros_flavor(args):
"""Coming soon - create the cirros flavor"""
# pylint: disable=unused-argument
print("creating cirros flavor - NYI") print("creating cirros flavor - NYI")
def create_rhel_flavor(args): def create_rhel_flavor(args):
"""Coming soon - create the rhel flavor"""
# pylint: disable=unused-argument
print("creating rhel flavor - NYI") print("creating rhel flavor - NYI")
def create_cirros_image(args): def create_cirros_image(args):
"""Coming soon - create the cirros image"""
# pylint: disable=unused-argument
print("creating cirros image - NYI") print("creating cirros image - NYI")
def create_rhel_image(args): def create_rhel_image(args):
"""Coming soon - create the rhel image"""
# pylint: disable=unused-argument
print("creating rhel image - NYI") print("creating rhel image - NYI")
def create_cirros_instance(args): def create_cirros_instance(args):
"""Coming soon - create the cirros instance"""
# pylint: disable=unused-argument
print("creating cirros instance - NYI") print("creating cirros instance - NYI")
def create_rhel_instance(args): def create_rhel_instance(args):
"""Coming soon - create the rhel instance"""
# pylint: disable=unused-argument
print("creating rhel instance - NYI") print("creating rhel instance - NYI")
def main(): def main():
"""main function""" """main function"""
args = parse_args() args = parse_args()
@ -131,6 +169,5 @@ def main():
create_rhel_instance(args) create_rhel_instance(args)
if __name__ == "__main__": if __name__ == "__main__":
main() main()