Add os_migrate_setup.py. Not complete
This commit is contained in:
parent
61591542f3
commit
df8f079bc7
1 changed files with 127 additions and 0 deletions
127
os_migrate_setup.py
Normal file
127
os_migrate_setup.py
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
"""
|
||||
Quick and dirty script to help setup project, flavors, networks, images
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def openstack_cmd(cmd):
|
||||
cmd = "OS_CLOUD=standalone openstack " + cmd
|
||||
|
||||
result = subprocess.check_output(cmd, shell=True, universal_newlines=True)
|
||||
return result
|
||||
|
||||
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")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def create_project(args):
|
||||
cmd = "project list -f json"
|
||||
project_exists = [
|
||||
x for x in json.loads(openstack_cmd(cmd))
|
||||
if x["Name"] == args.project_name
|
||||
]
|
||||
|
||||
if project_exists:
|
||||
print(f"Project {args.project_name} already exists. Skipping creation")
|
||||
args.project_id = project_exists[0]["ID"]
|
||||
return
|
||||
|
||||
cmd = (
|
||||
f"project create -f json --description '{args.project_description}' "
|
||||
f"{args.project_name} --domain {args.project_domain}"
|
||||
)
|
||||
|
||||
args.project_id = json.loads(openstack_cmd(cmd))["id"]
|
||||
|
||||
print(f"Project created - id: {args.project_id}")
|
||||
|
||||
def create_user(args):
|
||||
cmd = "user list -f json"
|
||||
user_exists = [
|
||||
x for x in json.loads(openstack_cmd(cmd))
|
||||
if x["Name"] == args.username
|
||||
]
|
||||
|
||||
if user_exists:
|
||||
print(f"User {args.username} already exists. Skipping creation")
|
||||
args.user_id = user_exists[0]["ID"]
|
||||
return
|
||||
|
||||
cmd = (
|
||||
f"user create -f json --project {args.project_id} "
|
||||
f"--password {args.password} {args.username}"
|
||||
)
|
||||
|
||||
args.user_id = json.loads(openstack_cmd(cmd))["id"]
|
||||
|
||||
print(f"User created - id: {args.user_id}")
|
||||
|
||||
def assign_member_role(args):
|
||||
cmd = f"openstack role add --user {args.username} --project {args.project_id} member"
|
||||
print(cmd)
|
||||
|
||||
def create_public_network(args):
|
||||
print("creating public network - NYI")
|
||||
|
||||
def create_private_network(args):
|
||||
print("creating private network - NYI")
|
||||
|
||||
def create_cirros_flavor(args):
|
||||
print("creating cirros flavor - NYI")
|
||||
|
||||
def create_rhel_flavor(args):
|
||||
print("creating rhel flavor - NYI")
|
||||
|
||||
def create_cirros_image(args):
|
||||
print("creating cirros image - NYI")
|
||||
|
||||
def create_rhel_image(args):
|
||||
print("creating rhel image - NYI")
|
||||
|
||||
def create_cirros_instance(args):
|
||||
print("creating cirros instance - NYI")
|
||||
|
||||
def create_rhel_instance(args):
|
||||
print("creating rhel instance - NYI")
|
||||
|
||||
def main():
|
||||
"""main function"""
|
||||
args = parse_args()
|
||||
|
||||
create_project(args)
|
||||
print (args.project_id)
|
||||
create_user(args)
|
||||
assign_member_role(args)
|
||||
|
||||
create_public_network(args)
|
||||
create_private_network(args)
|
||||
|
||||
create_cirros_flavor(args)
|
||||
create_rhel_flavor(args)
|
||||
|
||||
create_cirros_image(args)
|
||||
create_rhel_image(args)
|
||||
|
||||
create_cirros_instance(args)
|
||||
create_rhel_instance(args)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue