def kolla_ansible_generate_certificates(release, passwords_path, globals_path): """ Genereate certificates directory """ cwd = os.getcwd() globals_vol = volume_opt(globals_path, "/etc/kolla/globals.yml") password_vol = volume_opt(passwords_path, "/etc/kolla/passwords.yml") certs_vol = f"-v {cwd}/certificates:/etc/kolla/certificates" cmd = (f"docker run --rm {globals_vol} {password_vol} {certs_vol} " f"breqwatr/kolla-ansible:{release} " "kolla-ansible certificates") shell(cmd)
def kolla_ansible_get_admin_openrc(release, inventory_path, globals_path, passwords_path): """ Save the admin-openrc.sh file to current working directory """ cwd = os.getcwd() inv_vol = volume_opt(inventory_path, "/etc/kolla/inventory") globals_vol = volume_opt(globals_path, "/etc/kolla/globals.yml") passwords_vol = volume_opt(passwords_path, "/etc/kolla/passwords.yml") cwd_vol = f"-v {cwd}:/target " cmd = ("docker run --rm --network host " f"{inv_vol} {globals_vol} {passwords_vol} {cwd_vol} " f"breqwatr/kolla-ansible:{release} " 'bash -c "kolla-ansible post-deploy -i /etc/kolla/inventory && ' 'cp /etc/kolla/admin-openrc.sh /target/"') shell(cmd)
def start(release, openstack_vip, sql_pass, sql_ip, rabbit_ips_list, rabbit_pass, enable_ceph, kolla_ansible_dir, cloud_name): """ Start the arcus api """ rabbit_ips_csv = ",".join(rabbit_ips_list) image = f"breqwatr/arcus-mgr:{release}" env_vars = { "OPENSTACK_VIP": openstack_vip, "SQL_USERNAME": "******", "SQL_PASSWORD": sql_pass, "SQL_IP": sql_ip, "DR_SQL_USERNAME": "******", "DR_SQL_PASSWORD": sql_pass, "DR_SQL_IP": sql_ip, "RABBIT_NODES_CSV": rabbit_ips_csv, "RABBIT_USERNAME": "******", "RABBIT_PASSWORD": rabbit_pass, "ENABLE_CEPH": str(enable_ceph).lower(), "CLOUD_NAME": cloud_name } network = "--network=host" if DEV_MODE: network = "" env_str = env_string(env_vars) vols = volume_opt(kolla_ansible_dir, "/etc/kolla") name = "arcus_mgr" shell(f"docker rm -f {name} 2>/dev/null || true") cmd = f"docker run -d --restart=always --name {name} {network} {env_str} {vols} {image}" shell(cmd)
def start( release, fqdn, rabbit_pass, rabbit_ips_list, sql_ip, sql_password, https, port, secret, ): """ Start the arcus api """ image = f"breqwatr/arcus-api:{release}" rabbit_ips_csv = ",".join(rabbit_ips_list) env_vars = { "OPENSTACK_VIP": fqdn, "PUBLIC_ENDPOINT": "true", "HTTPS_OPENSTACK_APIS": str(https).lower(), "RABBITMQ_USERNAME": "******", "RABBITMQ_PASSWORD": rabbit_pass, "RABBIT_IPS_CSV": rabbit_ips_csv, "SQL_USERNAME": "******", "SQL_PASSWORD": sql_password, "SQL_IP": sql_ip, "ARCUS_INTEGRATION_SECRET": secret, } env_str = env_string(env_vars) daemon = "-d --restart=always" run = "" dev_mount = "" ceph_mount = "" network = "--network host" log_mount = "-v /var/log/arcus-api:/var/log/arcusweb" hosts_mount = "-v /etc/hosts:/etc/hosts" if DEV_MODE: log_mount = "" hosts_mount = "" if "ARCUS_API_DIR" not in os.environ: error("ERROR: must set $ARCUS_API_DIR when $VOITHOS_DEV==true", exit=True) api_dir = os.environ["ARCUS_API_DIR"] assert_path_exists(api_dir) daemon = "-it --rm" dev_mount = volume_opt(api_dir, "/app") network = f"-p 0.0.0.0:{port}:{port}" run = ('bash -c "' "/env_config.py && " "pip install -e . && " "gunicorn --workers 4 --error-logfile=- --access-logfile '-' " "--reload " f"--bind 0.0.0.0:{port}" ' arcusapi.wsgi:app" ') name = "arcus_api" shell(f"docker rm -f {name} 2>/dev/null || true") cmd = (f"docker run --name {name} {daemon} {network} " f"{hosts_mount} {log_mount} " f"{env_str} {ceph_mount} {dev_mount} {image} {run}") shell(cmd)
def smoke_test(release, openrc, image_path, **kwargs): """ Run the smoke test """ assert_path_exists(image_path) image_vol = volume_opt(image_path, "/image.qcow2") openrc_vol = volume_opt(openrc, "/admin-openrc.sh") env_var_list = [] for kwarg in kwargs: key = kwarg.upper() value = kwargs[kwarg] var = f"-e {key}={value}" env_var_list.append(var) env_vars_str = " ".join(env_var_list) run = ('bash -c "' "source /admin-openrc.sh && " ". /var/repos/env/bin/activate && " 'bash /smoke-test.sh"') cmd = ("docker run --rm " f"{openrc_vol} {image_vol} {env_vars_str} " f"breqwatr/openstack-client:{release} {run}") shell(cmd)
def cli_exec(release, openrc_path, command, volume=None, debug=False): """ Execute <command> using breqwatr/openstack-client:<release> Optionally, mount file(s) into the client with the volume arg """ command = "openstack" if command is None else command mount = f"-v {volume} " if volume is not None else " " openrc_vol = volume_opt(openrc_path, "/admin-openrc.sh") image = f"breqwatr/openstack-client:{release}" run = f'bash -c "source /admin-openrc.sh && . /var/repos/env/bin/activate && {command}"' cmd = f"docker run -it --rm --network host {openrc_vol} {mount} {image} {run}" shell(cmd, print_error=False, print_cmd=debug)
def start( release, api_ip, openstack_ip, glance_https, arcus_https=False, cert_path=None, cert_key_path=None, http_port=80, https_port=443, ): """ Start the arcus api """ image = f"breqwatr/arcus-client:{release}" env_vars = { "ARCUS_API_IP": api_ip, "ARCUS_API_PORT": "1234", "OPENSTACK_VIP": openstack_ip, "ARCUS_USE_HTTPS": arcus_https, "GLANCE_HTTPS": str(glance_https).lower(), "VERSION": release, "ARCUS_CLIENT_HTTP_PORT": http_port, "ARCUS_CLIENT_HTTPS_PORT": https_port, } env_str = env_string(env_vars) cert_vol_mounts = "" if cert_path is not None and cert_key_path is not None: cert_mount = volume_opt(cert_path, "/etc/nginx/haproxy.crt") priv_key_mount = volume_opt(cert_key_path, "/etc/nginx/haproxy.key") cert_vol_mounts = f" {cert_mount} {priv_key_mount} " daemon = "-d --restart=always" run = "" dev_mount = "" network = "--network host" log_mount = "-v /var/log/arcus-client:/var/log/nginx" hosts_mount = "-v /etc/hosts:/etc/hosts" if DEV_MODE: log_mount = "" hosts_mount = "" if "ARCUS_CLIENT_DIR" not in os.environ: error("ERROR: must set $ARCUS_CLIENT_DIR when $VOITHOS_DEV==true", exit=True) client_dir = os.environ["ARCUS_CLIENT_DIR"] assert_path_exists(client_dir) https_network = "" if cert_path is None else f"-p 0.0.0.0:{https_port}:{https_port}" network = f"-p 0.0.0.0:{http_port}:{http_port} {https_network}" run = ('bash -c "' "/env_config.py && " "npm install && " "service nginx start && " "grunt && " 'tail -f /dev/null"') sys.stdout.write( "TO REBUILD, EXECUTE:\n docker exec -it arcus_client grunt rebuild\n" ) dev_mount = volume_opt(client_dir, "/app") name = "arcus_client" shell(f"docker rm -f {name} 2>/dev/null || true") cmd = (f"docker run --name {name} " f"{daemon} {network} {env_str} " f"{cert_vol_mounts} {dev_mount} {log_mount} {hosts_mount} " f"{image} {run}") shell(cmd)
def kolla_ansible_exec(release, inventory_path, globals_path, passwords_path, ssh_key_path, certificates_dir, config_dir, command, tag=None, overrides=None): """ Execute kolla-ansible commands """ valid_cmds = [ "deploy", "mariadb_recovery", "prechecks", "post-deploy", "pull", "reconfigure", "upgrade", "check", "stop", "deploy-containers", "prune-images", "bootstrap-servers", "destroy", "destroy --yes-i-really-really-mean-it", "DEBUG", ] if command not in valid_cmds: error( f'ERROR: Invalid command "{command}" - Valid commands: {valid_cmds}', exit=True) config_vol = " " if config_dir is not None: config_vol = volume_opt(config_dir, "/etc/kolla/config") rm_arg = "" inv_vol = volume_opt(inventory_path, "/etc/kolla/inventory") globals_vol = volume_opt(globals_path, "/etc/kolla/globals.yml") passwd_vol = volume_opt(passwords_path, "/etc/kolla/passwords.yml") ssh_vol = volume_opt(ssh_key_path, "/root/.ssh/id_rsa") cert_vol = volume_opt(certificates_dir, "/etc/kolla/certificates") if command == "DEBUG": name = f"kolla-ansible-{release}" rm_arg = f"-d --name {name}" run_cmd = "tail -f /dev/null" shell(f"docker rm -f {name} 2>/dev/null || true") print(f"Starting persistent container named {name} for debugging") else: run_cmd = f"kolla-ansible {command} -i /etc/kolla/inventory" rm_arg = "--rm" tag_opt = "" if tag is None else f"--tag {tag}" override_vol_mnt = "" if overrides is not None: override_vol_mnt = volume_opt(overrides, '/overrides') run_cmd = f"bash -c 'cp -r overrides/* / && {run_cmd}'" cmd = ( f"docker run {rm_arg} --network host {override_vol_mnt} " "-e PY_COLORS=1 -e ANSIBLE_FORCE_COLOR=1 " f"{inv_vol} {globals_vol} {passwd_vol} {ssh_vol} {cert_vol} {config_vol}" f"breqwatr/kolla-ansible:{release} {run_cmd} {tag_opt}") shell(cmd)