Rearrange for packaging
This commit is contained in:
parent
eb1fbf7eb4
commit
cafecb4d01
10 changed files with 79 additions and 34 deletions
0
src/tripleo_aio_helpers/__init__.py
Normal file
0
src/tripleo_aio_helpers/__init__.py
Normal file
158
src/tripleo_aio_helpers/create_aio_vm.py
Normal file
158
src/tripleo_aio_helpers/create_aio_vm.py
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
import argparse
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
MD_PATH = "./meta-data"
|
||||
UD_PATH = "./user-data"
|
||||
ND_PATH = "./network-config"
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--password", required=True)
|
||||
parser.add_argument("--public-key", required=True, type=open)
|
||||
parser.add_argument(
|
||||
"--local-hostname", default="aio3.gpslab.cbr.redhat.com"
|
||||
)
|
||||
parser.add_argument("--user-data", default="./user-data.tpl", type=open)
|
||||
parser.add_argument("--meta-data", default="./meta-data.tpl", type=open)
|
||||
parser.add_argument(
|
||||
"--network-data", default="./network-config.tpl", type=open
|
||||
)
|
||||
parser.add_argument("--instance-id", default="aio3")
|
||||
parser.add_argument("--output-image", required=True)
|
||||
parser.add_argument("--image-size", default="100G")
|
||||
parser.add_argument("--input-image", required=True)
|
||||
parser.add_argument("--os-variant", required=True)
|
||||
parser.add_argument("--name", required=True)
|
||||
parser.add_argument("--memory", default=2048) # , type="int")
|
||||
parser.add_argument("--gateway", required=True)
|
||||
parser.add_argument("--cidr-1", required=True)
|
||||
parser.add_argument("--cidr-2", required=True)
|
||||
parser.add_argument("--dns", required=True)
|
||||
parser.add_argument("--search-domain", required=True)
|
||||
parser.add_argument("-v", "--verbose", action="store_true")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
args.public_key = args.public_key.read()
|
||||
|
||||
args.user_data = args.user_data.read()
|
||||
args.user_data = args.user_data.format(data=args)
|
||||
|
||||
args.meta_data = args.meta_data.read()
|
||||
args.meta_data = args.meta_data.format(data=args)
|
||||
|
||||
args.network_data = args.network_data.read()
|
||||
args.network_data = args.network_data.format(data=args)
|
||||
|
||||
output_image = pathlib.Path(args.output_image)
|
||||
if output_image.exists():
|
||||
raise ValueError(f"{args.output_image} already exists")
|
||||
args.output_image = output_image
|
||||
|
||||
input_image = pathlib.Path(args.input_image)
|
||||
if not input_image.exists():
|
||||
raise ValueError(f"{args.input_image} not found")
|
||||
args.input_image = input_image
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def write_user_data(user_data):
|
||||
with open(UD_PATH, "w", encoding="utf-8") as user_data_file:
|
||||
user_data_file.write(user_data)
|
||||
|
||||
|
||||
def write_meta_data(meta_data):
|
||||
with open(MD_PATH, "w", encoding="utf-8") as meta_data_file:
|
||||
meta_data_file.write(meta_data)
|
||||
|
||||
|
||||
def write_network_data(network_data):
|
||||
with open(ND_PATH, "w", encoding="utf-8") as network_data_file:
|
||||
network_data_file.write(network_data)
|
||||
|
||||
|
||||
def create_image(args):
|
||||
print("creating image")
|
||||
cmd = f"qemu-img create -f qcow2 -o preallocation=metadata {args.output_image} {args.image_size}"
|
||||
|
||||
result = subprocess.check_output(cmd, shell=True, universal_newlines=True)
|
||||
if args.verbose:
|
||||
print(result)
|
||||
|
||||
print("Resizing image")
|
||||
cmd = f"virt-resize --expand /dev/sda3 {args.input_image} {args.output_image}"
|
||||
|
||||
result = subprocess.check_output(cmd, shell=True, universal_newlines=True)
|
||||
|
||||
if args.verbose:
|
||||
print(result)
|
||||
|
||||
|
||||
def virt_install_cmd(args):
|
||||
cmd = f"""
|
||||
sudo virt-install \\
|
||||
--os-variant {args.os_variant} \\
|
||||
--name {args.name} \\
|
||||
--memory {args.memory} \\
|
||||
--disk {args.output_image} \\
|
||||
--import \\
|
||||
--graphics spice,listen=127.0.0.1 \\
|
||||
--video virtio \\
|
||||
--channel spicevmc \\
|
||||
--wait 0 \\
|
||||
--cloud-init meta-data=./meta-data,user-data=./user-data \\
|
||||
--network bridge=bridge0 \\
|
||||
--network bridge=bridge0
|
||||
"""
|
||||
|
||||
print("running virt-install")
|
||||
|
||||
if args.verbose:
|
||||
print(cmd)
|
||||
|
||||
result = subprocess.check_output(cmd, shell=True, universal_newlines=True)
|
||||
if args.verbose:
|
||||
print(result)
|
||||
|
||||
|
||||
def delete_meta_data():
|
||||
pathlib.Path.unlink(pathlib.Path(MD_PATH))
|
||||
|
||||
|
||||
def delete_user_data():
|
||||
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"
|
||||
|
||||
print("installing needed packages...")
|
||||
|
||||
if args.verbose:
|
||||
print(
|
||||
subprocess.check_output(cmd, shell=True, universal_newlines=True)
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
|
||||
if args.verbose:
|
||||
print(args)
|
||||
|
||||
install_packages(args)
|
||||
create_image(args)
|
||||
write_meta_data(args.meta_data)
|
||||
write_user_data(args.user_data)
|
||||
|
||||
virt_install_cmd(args)
|
||||
|
||||
delete_meta_data()
|
||||
delete_user_data()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
199
src/tripleo_aio_helpers/os_migrate_setup.py
Normal file
199
src/tripleo_aio_helpers/os_migrate_setup.py
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
"""
|
||||
Quick and dirty script to help setup project, flavors, networks, images
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
|
||||
# import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def openstack_cmd(cmd):
|
||||
"""Utility function to run an openstack command agains the standalone cloud"""
|
||||
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")
|
||||
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")
|
||||
|
||||
# export OS_CLOUD=standalone
|
||||
# export STANDALONE_HOST=10.76.23.39
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def create_project(args):
|
||||
"""Create the project if it doesn't already exist"""
|
||||
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):
|
||||
"""Create the user if it doesn't already exist"""
|
||||
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):
|
||||
"""
|
||||
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"
|
||||
|
||||
result = openstack_cmd(cmd)
|
||||
|
||||
cmd = f"role assignment list --user {args.user_id} --role member -f json"
|
||||
result = json.loads(openstack_cmd(cmd))
|
||||
|
||||
if result:
|
||||
print("User has member role")
|
||||
|
||||
|
||||
def create_public_network(args):
|
||||
"""Coming soon - create the public network"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating 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 create_private_network(args):
|
||||
"""Coming soon - create the private network"""
|
||||
# pylint: disable=unused-argument
|
||||
cmd = "openstack network create --internal private"
|
||||
cmd = (
|
||||
"openstack subnet create private-net "
|
||||
f"--subnet-range {args.private_network_cidr} --network private"
|
||||
)
|
||||
print("creating private network - NYI")
|
||||
|
||||
|
||||
def create_cirros_flavor(args):
|
||||
"""Coming soon - create the cirros flavor"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating cirros flavor - NYI")
|
||||
|
||||
|
||||
def create_rhel_flavor(args):
|
||||
"""Coming soon - create the rhel flavor"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating rhel flavor - NYI")
|
||||
|
||||
|
||||
def create_cirros_image(args):
|
||||
"""Coming soon - create the cirros image"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating cirros image - NYI")
|
||||
|
||||
|
||||
def create_rhel_image(args):
|
||||
"""Coming soon - create the rhel image"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating rhel image - NYI")
|
||||
|
||||
|
||||
def create_cirros_instance(args):
|
||||
"""Coming soon - create the cirros instance"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating cirros instance - NYI")
|
||||
|
||||
|
||||
def create_rhel_instance(args):
|
||||
"""Coming soon - create the rhel instance"""
|
||||
# pylint: disable=unused-argument
|
||||
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()
|
||||
195
src/tripleo_aio_helpers/os_migrate_teardown.py
Normal file
195
src/tripleo_aio_helpers/os_migrate_teardown.py
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
"""
|
||||
Quick and dirty script to help setup project, flavors, networks, images
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
|
||||
# import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def openstack_cmd(cmd):
|
||||
"""Utility function to run an openstack command agains the standalone cloud"""
|
||||
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")
|
||||
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")
|
||||
|
||||
# export OS_CLOUD=standalone
|
||||
# export STANDALONE_HOST=10.76.23.39
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def destroy_project(args):
|
||||
"""Delete the project if it exists"""
|
||||
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} exists. Will delete")
|
||||
args.project_id = project_exists[0]["ID"]
|
||||
|
||||
cmd = (
|
||||
f"project delete -f json --domain {args.project_domain} "
|
||||
f"{args.project_id}"
|
||||
)
|
||||
print(f"Project deleted")
|
||||
else:
|
||||
print("Project {args.project_name} not found.")
|
||||
|
||||
|
||||
def destroy_user(args):
|
||||
"""Delete the user if it exists"""
|
||||
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):
|
||||
"""
|
||||
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"
|
||||
|
||||
result = openstack_cmd(cmd)
|
||||
|
||||
cmd = f"role assignment list --user {args.user_id} --role member -f json"
|
||||
result = json.loads(openstack_cmd(cmd))
|
||||
|
||||
if result:
|
||||
print("User has member role")
|
||||
|
||||
|
||||
def destroy_public_network(args):
|
||||
"""Coming soon - create the public network"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating 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 destroy_private_network(args):
|
||||
"""Coming soon - create the private network"""
|
||||
# pylint: disable=unused-argument
|
||||
cmd = "openstack network create --internal private"
|
||||
cmd = (
|
||||
"openstack subnet create private-net "
|
||||
f"--subnet-range {args.private_network_cidr} --network private"
|
||||
)
|
||||
print("creating private network - NYI")
|
||||
|
||||
|
||||
def destroy_cirros_flavor(args):
|
||||
"""Coming soon - create the cirros flavor"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating cirros flavor - NYI")
|
||||
|
||||
|
||||
def destroy_rhel_flavor(args):
|
||||
"""Coming soon - create the rhel flavor"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating rhel flavor - NYI")
|
||||
|
||||
|
||||
def destroy_cirros_image(args):
|
||||
"""Coming soon - create the cirros image"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating cirros image - NYI")
|
||||
|
||||
|
||||
def destroy_rhel_image(args):
|
||||
"""Coming soon - create the rhel image"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating rhel image - NYI")
|
||||
|
||||
|
||||
def destroy_cirros_instance(args):
|
||||
"""Coming soon - create the cirros instance"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating cirros instance - NYI")
|
||||
|
||||
|
||||
def destroy_rhel_instance(args):
|
||||
"""Coming soon - create the rhel instance"""
|
||||
# pylint: disable=unused-argument
|
||||
print("creating rhel instance - NYI")
|
||||
|
||||
|
||||
def main():
|
||||
"""main function"""
|
||||
args = parse_args()
|
||||
|
||||
# destroy_cirros_instance(args)
|
||||
# destroy_rhel_instance(args)
|
||||
|
||||
# destroy_cirros_image(args)
|
||||
# destroy_rhel_image(args)
|
||||
|
||||
# destroy_cirros_flavor(args)
|
||||
# destroy_rhel_flavor(args)
|
||||
|
||||
# destroy_public_network(args)
|
||||
# destroy_private_network(args)
|
||||
|
||||
destroy_user(args)
|
||||
destroy_project(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
152
src/tripleo_aio_helpers/prepare_deployment.py
Normal file
152
src/tripleo_aio_helpers/prepare_deployment.py
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
"""
|
||||
Quick and dirty script to help setup config filers for a RHOSP AIO install
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import yaml
|
||||
|
||||
|
||||
def parse_args():
|
||||
"""Parse the command line arguments"""
|
||||
|
||||
home = os.environ.get("HOME")
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-u", "--username", required=True)
|
||||
parser.add_argument("-p", "--password", required=True)
|
||||
parser.add_argument("-a", "--address", required=True)
|
||||
parser.add_argument("-i", "--interface", default="enp1s0")
|
||||
parser.add_argument("-m", "--netmask", default=24)
|
||||
parser.add_argument(
|
||||
"-d", "--dns", nargs="+", action="append", required=True
|
||||
)
|
||||
parser.add_argument("-D", "--domain", default="aio")
|
||||
parser.add_argument("--using-multiple-nics", action="store_true")
|
||||
parser.add_argument("-U", "--deployment-user")
|
||||
parser.add_argument("--deployment-dir")
|
||||
parser.add_argument("-g", "--gateway")
|
||||
parser.add_argument(
|
||||
"--containers-yaml-out",
|
||||
default=f"{home}/containers-prepare-parameters.yaml.gen",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--standalone-yaml-out",
|
||||
default=f"{home}/standalone_parameters.yaml.gen",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--deploy-script-out", default=f"{home}/deploy.sh.gen", dest="deploy"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.deployment_user:
|
||||
args.deployment_user = os.environ.get("USER")
|
||||
|
||||
if not args.deployment_dir:
|
||||
args.deployment_dir = os.environ.get("HOME")
|
||||
|
||||
if not args.using_multiple_nics and not args.gateway:
|
||||
raise ValueError("Must specify a gateway when using a single nic")
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def get_standalone_parameters(args):
|
||||
"""Build the standalone parameters as a dict ready to serialize as yaml"""
|
||||
sp_dict = {
|
||||
"parameter_defaults": {
|
||||
"CloudName": args.address,
|
||||
"CloudDomain": args.domain,
|
||||
"ControlPlaneStaticRoutes": [],
|
||||
"Debug": True,
|
||||
"DeploymentUser": args.deployment_user,
|
||||
"DnsServers": [dns[0] for dns in args.dns],
|
||||
"NeutronPublicInterface": args.interface,
|
||||
"NeutronDnsDomain": "localdomain",
|
||||
"NeutronBridgeMappings": "datacentre:br-ctlplane",
|
||||
"NeutronPhysicalBridge": "br-ctlplane",
|
||||
"StandaloneEnableRoutedNetworks": False,
|
||||
"StandaloneHomeDir": args.deployment_dir,
|
||||
"StandaloneLocalMtu": 1500,
|
||||
}
|
||||
}
|
||||
|
||||
if not args.using_multiple_nics:
|
||||
sp_dict["parameter_defaults"]["ControlPlaneStaticRoutes"] = [
|
||||
{
|
||||
"ip_netmask": "0.0.0.0/0",
|
||||
"next_hop": args.gateway,
|
||||
"default": True,
|
||||
}
|
||||
]
|
||||
|
||||
return sp_dict
|
||||
|
||||
|
||||
def build_containers_yaml(args):
|
||||
"""Build the containers yaml based on a previously generated file."""
|
||||
|
||||
cmd = "sudo openstack tripleo container image prepare default"
|
||||
result = subprocess.check_output(cmd, shell=True, universal_newlines=True)
|
||||
|
||||
data = yaml.load(result, Loader=yaml.Loader)
|
||||
|
||||
data["parameter_defaults"]["ContainerImageRegistryCredentials"] = {
|
||||
"registry.redhat.io": {args.username: args.password}
|
||||
}
|
||||
|
||||
data["parameter_defaults"]["ContainerImageRegistryLogin"] = True
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def deploy_sh(args):
|
||||
home = os.environ.get("HOME")
|
||||
|
||||
template = (
|
||||
"sudo openstack tripleo deploy \\\n"
|
||||
" --templates \\\n"
|
||||
f" --local-ip={args.address}/{args.netmask} \\\n"
|
||||
" -e /usr/share/openstack-tripleo-heat-templates/"
|
||||
"environments/standalone/standalone-tripleo.yaml \\\n"
|
||||
" -r /usr/share/openstack-tripleo-heat-templates/"
|
||||
"roles/Standalone.yaml \\\n"
|
||||
f" -e {home}/containers-prepare-parameters.yaml \\\n"
|
||||
f" -e {home}/standalone_parameters.yaml \\\n"
|
||||
f" --output-dir {home} \\\n"
|
||||
" --standalone\n"
|
||||
)
|
||||
|
||||
return template
|
||||
|
||||
|
||||
def set_hostname(args):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
"""main function"""
|
||||
args = parse_args()
|
||||
|
||||
containers_yaml = build_containers_yaml(args)
|
||||
with open(
|
||||
args.containers_yaml_out, "w", encoding="utf-8"
|
||||
) as containers_out:
|
||||
containers_out.write(yaml.dump(containers_yaml))
|
||||
print(f"containers yaml written to {args.containers_yaml_out}")
|
||||
|
||||
standalone_parameters = get_standalone_parameters(args)
|
||||
with open(
|
||||
args.standalone_yaml_out, "w", encoding="utf-8"
|
||||
) as parameters_out:
|
||||
parameters_out.write(yaml.dump(standalone_parameters))
|
||||
print(f"standalone parameters yaml written to {args.standalone_yaml_out}")
|
||||
|
||||
with open(args.deploy, "w", encoding="utf-8") as deploy:
|
||||
deploy.write(deploy_sh(args))
|
||||
print(f"deploy script written to {args.deploy}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
2
src/virt-install/meta-data.tpl
Normal file
2
src/virt-install/meta-data.tpl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
instance-id: {data.instance_id}
|
||||
local-hostname: {data.local_hostname}
|
||||
20
src/virt-install/network-config.tpl
Normal file
20
src/virt-install/network-config.tpl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
network:
|
||||
version: 1
|
||||
config:
|
||||
- type: physical
|
||||
name: en0
|
||||
subnets:
|
||||
- type: static
|
||||
address: {data.cidr_1}
|
||||
gateway: {data.gateway}
|
||||
- type: physical
|
||||
name: en1
|
||||
subnets:
|
||||
- type: static
|
||||
address: {data.cidr_2}
|
||||
gateway: {data.gateway}
|
||||
- type: nameserver
|
||||
address:
|
||||
- {data.dns}
|
||||
search:
|
||||
- {data.search_domain}
|
||||
15
src/virt-install/user-data.tpl
Normal file
15
src/virt-install/user-data.tpl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#cloud-config
|
||||
system_info:
|
||||
default_user:
|
||||
name: stack
|
||||
password: {data.password}
|
||||
chpasswd: {{expire: False}}
|
||||
ssh_pwauth: True
|
||||
ssh_authorized_keys:
|
||||
- {data.public_key}
|
||||
|
||||
bootcmd:
|
||||
- "nmcli conn delete 'System eth0'"
|
||||
- "nmcli conn delete 'Wired connection 1'"
|
||||
- "nmcli con add con-name eth0 ifname eth0 type ethernet ip4 {data.cidr_1} gw4 {data.gateway} ipv4.dns {data.dns}"
|
||||
- "nmcli con add con-name eth1 ifname eth1 type ethernet ip4 {data.cidr_2} gw4 {data.gateway} ipv4.dns {data.dns}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue