Example #1
0
    def setup_compose_file(composefileurl,
                           file_location,
                           enable_transactions=False):
        compose_file_name = composefileurl.rsplit('/', 1)[-1]
        if os.path.isfile(compose_file_name):
            backup_file_name = f"{Helpers.get_current_date_time()}_{compose_file_name}"
            print(
                f"Docker compose file {compose_file_name} exists. Backing it up as {backup_file_name}"
            )
            run_shell_command(f"cp {compose_file_name} {backup_file_name}",
                              shell=True)
        print(f"Downloading new compose file from {composefileurl}")

        req = requests.Request('GET', f'{composefileurl}')
        prepared = req.prepare()
        resp = Helpers.send_request(prepared, print_response=False)

        if not resp.ok:
            print(f" Errored downloading file {composefileurl}. Exitting ... ")
            sys.exit()

        composefile_yaml = yaml.safe_load(resp.content)

        # TODO AutoApprove
        prompt_external_db = input(
            "Do you want to configure data directory for the ledger [Y/n]?:")
        if Helpers.check_Yes(prompt_external_db):
            composefile_yaml = Docker.merge_external_db_config(
                composefile_yaml)

        def represent_none(self, _):
            return self.represent_scalar('tag:yaml.org,2002:null', '')

        yaml.add_representer(type(None), represent_none)

        network_id = Base.get_network_id()
        genesis_json_location = Base.path_to_genesis_json(network_id)

        composefile_yaml = Docker.merge_network_info(composefile_yaml,
                                                     network_id,
                                                     genesis_json_location)
        composefile_yaml = Docker.merge_keyfile_path(composefile_yaml,
                                                     file_location)
        composefile_yaml = Docker.merge_transactions_env_var(
            composefile_yaml, "true" if enable_transactions else "false")
        if os.getenv(IMAGE_OVERRIDE, "False") in ("true", "yes"):
            composefile_yaml = Docker.merge_image_overrides(composefile_yaml)

        with open(compose_file_name, 'w') as f:
            yaml.dump(composefile_yaml,
                      f,
                      default_flow_style=False,
                      explicit_start=True,
                      allow_unicode=True)
Example #2
0
    def download_ansible_file(ansible_dir, file):
        req = requests.Request('GET', f'{ansible_dir}/{file}')
        prepared = req.prepare()

        resp = Helpers.send_request(prepared, print_response=False)
        if not resp.ok:
            print(
                f"{resp.status_code} error retrieving ansible playbook.. Existing the command..."
            )
            sys.exit()

        directory = file.rsplit('/', 1)[0]
        Path(directory).mkdir(parents=True, exist_ok=True)
        with open(file, 'wb') as f:
            f.write(resp.content)
Example #3
0
def latest_release(repo_name="radixdlt/radixdlt"):
    req = requests.Request(
        'GET', f'https://api.github.com/repos/{repo_name}/releases/latest')

    prepared = req.prepare()
    prepared.headers['Content-Type'] = 'application/json'
    prepared.headers['user-agent'] = 'radixnode-cli'
    resp = Helpers.send_request(prepared, print_response=False)
    if not resp.ok:
        print(
            "Failed to get latest release from github. Exitting the command..."
        )
        sys.exit()

    json_response = json.loads(resp.content)
    return json_response["tag_name"]