From 8e2f3d2721466577ff0896c5f56cdcc91a038a63 Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 15 Aug 2024 10:31:57 -0400 Subject: [PATCH] Added instructions for running sample. Signed-off-by: dblock --- guides/snapshot.md | 1 + samples/{ => snapshot}/Dockerfile | 2 +- samples/snapshot/README.md | 8 ++++++++ samples/snapshot/snapshot_sample.py | 3 ++- 4 files changed, 12 insertions(+), 2 deletions(-) rename samples/{ => snapshot}/Dockerfile (83%) create mode 100644 samples/snapshot/README.md diff --git a/guides/snapshot.md b/guides/snapshot.md index 64e1e24f7..0630fc948 100644 --- a/guides/snapshot.md +++ b/guides/snapshot.md @@ -17,6 +17,7 @@ # Snapshot Actions In this guide, we will look at some snapshot actions that allow you to manage and work with snapshots of your indices. +A complete working sample for this guide can be found in [samples/snapshot](../samples/snapshot). ## Setup Let's create a client instance, and an index named `movies`: diff --git a/samples/Dockerfile b/samples/snapshot/Dockerfile similarity index 83% rename from samples/Dockerfile rename to samples/snapshot/Dockerfile index 92a9befe5..b2f22e3b3 100644 --- a/samples/Dockerfile +++ b/samples/snapshot/Dockerfile @@ -6,4 +6,4 @@ ARG GID=1000 RUN echo 'path.repo: ["/usr/share/opensearch/backups"]' >> $OPENSEARCH_HOME/config/opensearch.yml RUN mkdir -p $OPENSEARCH_HOME/backups -RUN chown -Rv $UID:$GID $OPENSEARCH_HOME/backups \ No newline at end of file +RUN chown -Rv $UID:$GID $OPENSEARCH_HOME/backups diff --git a/samples/snapshot/README.md b/samples/snapshot/README.md new file mode 100644 index 000000000..ff947425f --- /dev/null +++ b/samples/snapshot/README.md @@ -0,0 +1,8 @@ +Run this sample as follows. + +``` +cd samples +docker run --rm -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -it $(docker build -q snapshot ) +poetry install +poetry run python snapshot/snapshot_sample.py +``` diff --git a/samples/snapshot/snapshot_sample.py b/samples/snapshot/snapshot_sample.py index b8081ba1b..267d46700 100644 --- a/samples/snapshot/snapshot_sample.py +++ b/samples/snapshot/snapshot_sample.py @@ -9,6 +9,7 @@ # Modifications Copyright OpenSearch Contributors. See # GitHub history for details. +import os import tempfile from opensearchpy import OpenSearch @@ -17,7 +18,7 @@ HOST = "localhost" PORT = 9200 -auth = ("admin", "admin") # For testing only. Don't store credentials in code. +auth = ("admin", os.getenv("OPENSEARCH_PASSWORD", "admin")) # For testing only. Don't store credentials in code. client = OpenSearch( hosts=[{"host": HOST, "port": PORT}],