🚧 images, logging
This commit is contained in:
parent
0681468b83
commit
846d858c2e
2 changed files with 18 additions and 7 deletions
|
|
@ -4,3 +4,4 @@
|
||||||
# pyflakes==2.5.0
|
# pyflakes==2.5.0
|
||||||
# pylint==2.13.9
|
# pylint==2.13.9
|
||||||
PyYAML==6.0.1
|
PyYAML==6.0.1
|
||||||
|
rich
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ flavors, networks, images have not been created
|
||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
from rich import print
|
from rich import print
|
||||||
|
|
||||||
|
|
@ -29,10 +30,13 @@ def parse_args():
|
||||||
parser.add_argument("--private-network-name", default="private")
|
parser.add_argument("--private-network-name", default="private")
|
||||||
parser.add_argument("--cirros-flavor-name", default="cirros")
|
parser.add_argument("--cirros-flavor-name", default="cirros")
|
||||||
parser.add_argument("--rhel-flavor-name", default="rhel")
|
parser.add_argument("--rhel-flavor-name", default="rhel")
|
||||||
|
parser.add_argument("--cirros-image-name", default="cirros_image")
|
||||||
|
parser.add_argument("--rhel-image-name", default="rhel_image")
|
||||||
parser.add_argument("--cirros-instance-name", default="cirros-test-instance")
|
parser.add_argument("--cirros-instance-name", default="cirros-test-instance")
|
||||||
parser.add_argument("--rhel-instance-name", default="rhel-test-instance")
|
parser.add_argument("--rhel-instance-name", default="rhel-test-instance")
|
||||||
parser.add_argument("--router-name", default="test-router")
|
parser.add_argument("--router-name", default="test-router")
|
||||||
parser.add_argument("--group-name", default="os-migrate")
|
parser.add_argument("--group-name", default="os-migrate")
|
||||||
|
parser.add_argument("-l", "--log-level", default="WARN")
|
||||||
|
|
||||||
# parser.add_argument(
|
# parser.add_argument(
|
||||||
# "--ssh", help="Connection string to run commands on a remote host."
|
# "--ssh", help="Connection string to run commands on a remote host."
|
||||||
|
|
@ -76,6 +80,7 @@ def validate_member_role(args):
|
||||||
Validate that the member role has been assigned to the user.
|
Validate that the member role has been assigned to the user.
|
||||||
"""
|
"""
|
||||||
cmd = f"role assignment list --user {args.username} --names --project {args.project_name} --role member -f json"
|
cmd = f"role assignment list --user {args.username} --names --project {args.project_name} --role member -f json"
|
||||||
|
logging.debug(cmd)
|
||||||
|
|
||||||
if len(openstack_cmd(cmd, args, as_json=True)) > 0:
|
if len(openstack_cmd(cmd, args, as_json=True)) > 0:
|
||||||
passed(f"User has member role in {args.project_name}")
|
passed(f"User has member role in {args.project_name}")
|
||||||
|
|
@ -197,16 +202,19 @@ def validate_cirros_image(args):
|
||||||
"""Validate that the cirros image does not exist"""
|
"""Validate that the cirros image does not exist"""
|
||||||
|
|
||||||
cmd = "image list -f json --all"
|
cmd = "image list -f json --all"
|
||||||
|
images = openstack_cmd(cmd, args, as_json=True)
|
||||||
|
|
||||||
|
logging.debug(images)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image = [
|
image = [
|
||||||
f
|
i
|
||||||
for f in openstack_cmd(cmd, args, as_json=True)
|
for i in images
|
||||||
if f["Name"] == args.cirros_image_name
|
if i["Name"] == args.cirros_image_name
|
||||||
][0]
|
][0]
|
||||||
failed(f"Cirros image found (ID:{image['ID']})", args)
|
failed(f"Cirros image ({args.cirros_image_name}) found (ID:{image['ID']})", args)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
passed("Cirros image not found.")
|
passed(f"Cirros image ({args.cirros_image_name}) not found.")
|
||||||
|
|
||||||
|
|
||||||
def validate_rhel_image(args):
|
def validate_rhel_image(args):
|
||||||
|
|
@ -220,9 +228,9 @@ def validate_rhel_image(args):
|
||||||
for f in openstack_cmd(cmd, args, as_json=True)
|
for f in openstack_cmd(cmd, args, as_json=True)
|
||||||
if f["Name"] == args.rhel_image_name
|
if f["Name"] == args.rhel_image_name
|
||||||
][0]
|
][0]
|
||||||
failed(f"RHEL image found (ID:{image['ID']})", args)
|
failed(f"RHEL image ({args.rhel_image_name}) found (ID:{image['ID']})", args)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
passed("RHEL image not found.")
|
passed(f"RHEL image ({args.rhel_image_name}) not found.")
|
||||||
|
|
||||||
|
|
||||||
def validate_cirros_instance(args):
|
def validate_cirros_instance(args):
|
||||||
|
|
@ -287,6 +295,8 @@ def main():
|
||||||
"""main function"""
|
"""main function"""
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
|
logging.basicConfig(level=args.log_level)
|
||||||
|
|
||||||
validate_user(args)
|
validate_user(args)
|
||||||
validate_project(args)
|
validate_project(args)
|
||||||
validate_member_role(args)
|
validate_member_role(args)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue