Example #1
0
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)
Example #2
0
def volume_opt(src, dest, require=True):
    """Return a volume's argument for docker run

    Don't use volume_opt with hard-coded linux paths, it will make Windows try and mkdir in
    C:\\WINDOWS\\system32 and fail. volume_opt can handle C:\\... syntax correctly. Instead,
    just use '-v /linux/path:/mount/point and the docker vm on Windows will handle it.
    """
    if require:
        assert_path_exists(src)
    absolute_path = get_absolute_path(src)
    return f'-v "{absolute_path}:{dest}" '
Example #3
0
def zap_disk(disk, force):
    """ Erase filesystem from given disk """
    if not force:
        click.echo("")
        click.echo(
            f"WARNING: This will destroy any filesystem on the drive: {disk}")
        click.echo("Type the drive name again to continue:")
        user_in = input()
        if user_in != disk:
            system.error(f"ERROR: Confirm does not match {disk}", exit=True)
    system.assert_path_exists(disk)
    ceph.zap_disk(disk)
Example #4
0
def create(user, password, https, ip, port):
    """ Creates dashboards """
    current_file_parent_dir = pathlib.Path(__file__).parent.absolute()
    json_file_path = current_file_parent_dir / "../files/grafana/node_config.json"
    assert_path_exists(json_file_path)
    proto = "https" if https else "http"
    url = f"{proto}://{ip}:{port}/api/dashboards/import"
    with open(json_file_path) as json_file:
        post_request = requests.post(
            url,
            verify=False,
            auth=(user, password),
            headers={"Content-Type": "application/json"},
            data=json_file,
        )
        print(post_request.text)
Example #5
0
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)
Example #6
0
def convert(input_format, output_format, input_path, output_path):
    """ Execute qemu-img inside a container that mounts input_path and output_path to itself """
    # mount the input file to /work/<filename> inside the container
    path_in = Path(input_path)
    input_abspath = path_in.absolute().__str__()
    assert_path_exists(input_abspath)
    internal_input_path = f"/input/{path_in.name}"
    in_mount = f"-v {input_abspath}:{internal_input_path}"
    # The mount for the output dir varies depending on if its a file or block device
    path_out = Path(output_path)
    if path_out.is_block_device():
        # directly map the block device to the container
        assert_path_exists(path_out)
        out_mount = f"--device {path_out}"
        internal_output_path = path_out
    else:
        # output is a file (or about to be), so mount the folder it exists in
        output_abspath = path_out.absolute().__str__()
        output_dir = Path(output_abspath).parent.__str__()
        assert_path_exists(output_dir)
        internal_output_dir = "/output"
        internal_output_path = f"{internal_output_dir}/{path_out.name}"
        out_mount = f"-v {output_dir}:{internal_output_dir}"
    name = "qemu-img"
    image = "breqwatr/qemu-img:latest"
    run = (f"qemu-img convert -f {input_format} -O {output_format} "
           f"{internal_input_path} {internal_output_path}")
    cmd = f"docker run -it --name {name} --rm {in_mount} {out_mount} {image} {run}"
    shell(cmd)
Example #7
0
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)