✨ add os_migrate_validate.py
This commit is contained in:
parent
8b2dcd6671
commit
f85e69e08f
1 changed files with 170 additions and 0 deletions
170
src/tripleo_aio_helpers/os_migrate_validate.py
Normal file
170
src/tripleo_aio_helpers/os_migrate_validate.py
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
"""
|
||||
Quick and dirty script to validate that the necessary project, user,roles,
|
||||
flavors, networks, images have been created
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
|
||||
from .utils import openstack_cmd
|
||||
|
||||
|
||||
def parse_args():
|
||||
"""Parse the command line arguments"""
|
||||
|
||||
# home = os.environ.get('HOME')
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
# parser.add_argument("-d", "--project-domain", default="default")
|
||||
parser.add_argument("-n", "--project-name", default="test-project")
|
||||
# parser.add_argument("-D", "--project-description", default="Test project")
|
||||
# parser.add_argument("-u", "--username", default="test-user")
|
||||
# parser.add_argument("-p", "--password", default="secrete123")
|
||||
# parser.add_argument("-c", "--cloud", default="standalone")
|
||||
# parser.add_argument("-g", "--gateway", default="10.76.23.254")
|
||||
# parser.add_argument(
|
||||
# "-C", "--public-network-cider", default="10.76.23.0/24"
|
||||
# )
|
||||
# parser.add_argument("--private-network-cidr", default="192.168.100.0/24")
|
||||
# parser.add_argument("--publice-net-start", default="10.76.23.50")
|
||||
# parser.add_argument("--publice-net-end", default="10.76.23.52")
|
||||
# parser.add_argument("--dns-server", default="10.76.23.245")
|
||||
|
||||
# parser.add_argument("--dry-run", action="store_true")
|
||||
parser.add_argument(
|
||||
"--ssh", help="Connection string to run commands on a remote host."
|
||||
)
|
||||
|
||||
# export OS_CLOUD=standalone
|
||||
# export STANDALONE_HOST=10.76.23.39
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def validate_project(args):
|
||||
"""Validate that the project exists"""
|
||||
cmd = "project list -f json"
|
||||
project_exists = [
|
||||
x
|
||||
for x in json.loads(openstack_cmd(cmd, args))
|
||||
if x["Name"] == args.project_name
|
||||
]
|
||||
|
||||
if project_exists:
|
||||
print(project_exists)
|
||||
else:
|
||||
print("Project {args.project_name} not found.")
|
||||
|
||||
|
||||
def validate_user(args):
|
||||
"""Validate that the user exists"""
|
||||
cmd = "user list -f json"
|
||||
user_exists = [
|
||||
x for x in json.loads(openstack_cmd(cmd, args)) if x["Name"] == args.username
|
||||
]
|
||||
|
||||
if user_exists:
|
||||
print(user_exists)
|
||||
else:
|
||||
print("User not found")
|
||||
|
||||
|
||||
def validate_member_role(args):
|
||||
"""
|
||||
Validate that the member role has been assigned to the user.
|
||||
"""
|
||||
print(args)
|
||||
# cmd = f"role add --user {args.username} --project {args.project_id} member"
|
||||
|
||||
# result = openstack_cmd(cmd, args)
|
||||
|
||||
# cmd = f"role assignment list --user {args.user_id} --role member -f json"
|
||||
# result = json.loads(openstack_cmd(cmd, args))
|
||||
|
||||
# if result:
|
||||
# print("User has member role")
|
||||
|
||||
|
||||
def validate_public_network(args):
|
||||
"""Coming soon - validate the public network"""
|
||||
# pylint: disable=unused-argument,unused-variable
|
||||
print("Validate public network - NYI")
|
||||
cmd = (
|
||||
"network create --external --provider-physical-network datacentre "
|
||||
"--provider-network-type flat public"
|
||||
)
|
||||
cmd = (
|
||||
f"subnet create public-net --subnet-range {args.publice_network_cidr} "
|
||||
f"--no-dhcp --gateway {args.gateway} --allocation-pool "
|
||||
f"start={args.public_net_start},end={args.public_net_end} "
|
||||
"--network public"
|
||||
)
|
||||
|
||||
|
||||
def validate_private_network(args):
|
||||
"""Coming soon - validate the private network"""
|
||||
# pylint: disable=unused-argument,unused-variable
|
||||
cmd = "openstack network create --internal private"
|
||||
cmd = (
|
||||
"openstack subnet create private-net "
|
||||
f"--subnet-range {args.private_network_cidr} --network private"
|
||||
)
|
||||
print("validate private network - NYI")
|
||||
|
||||
|
||||
def validate_cirros_flavor(args):
|
||||
"""Coming soon - create the cirros flavor"""
|
||||
# pylint: disable=unused-argument
|
||||
print("validate cirros flavor - NYI")
|
||||
|
||||
|
||||
def validate_rhel_flavor(args):
|
||||
"""Coming soon - validate the rhel flavor"""
|
||||
# pylint: disable=unused-argument
|
||||
print("validate rhel flavor - NYI")
|
||||
|
||||
|
||||
def validate_cirros_image(args):
|
||||
"""Coming soon - validate the cirros image"""
|
||||
# pylint: disable=unused-argument
|
||||
print("validate cirros image - NYI")
|
||||
|
||||
|
||||
def validate_rhel_image(args):
|
||||
"""Coming soon - validate the rhel image"""
|
||||
# pylint: disable=unused-argument
|
||||
print("validate rhel image - NYI")
|
||||
|
||||
|
||||
def validate_cirros_instance(args):
|
||||
"""Coming soon - validate the cirros instance"""
|
||||
# pylint: disable=unused-argument
|
||||
print("validate cirros instance - NYI")
|
||||
|
||||
|
||||
def validate_rhel_instance(args):
|
||||
"""Coming soon - create the rhel instance"""
|
||||
# pylint: disable=unused-argument
|
||||
print("validate rhel instance - NYI")
|
||||
|
||||
|
||||
def main():
|
||||
"""main function"""
|
||||
args = parse_args()
|
||||
|
||||
validate_user(args)
|
||||
validate_project(args)
|
||||
validate_member_role(args)
|
||||
validate_public_network(args)
|
||||
validate_private_network(args)
|
||||
validate_cirros_flavor(args)
|
||||
validate_rhel_flavor(args)
|
||||
validate_cirros_image(args)
|
||||
validate_rhel_image(args)
|
||||
validate_cirros_instance(args)
|
||||
validate_rhel_instance(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue