-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from scalableminds/python-client
add backup client (python)
- Loading branch information
Showing
6 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
__pycache__ | ||
*.pyc | ||
|
||
fossildbapi_pb2_grpc.py | ||
fossildbapi_pb2.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM python:3.6-stretch | ||
|
||
COPY src/main/protobuf /fossildb/src/main/protobuf | ||
COPY client /fossildb/client | ||
|
||
WORKDIR /fossildb/client | ||
|
||
RUN pip3 install -r requirements.txt | ||
RUN ./update_api.sh | ||
|
||
ENTRYPOINT /fossildb/client/backup-client.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import grpc | ||
import sys | ||
import argparse | ||
|
||
import fossildbapi_pb2 | ||
import fossildbapi_pb2_grpc | ||
|
||
|
||
def main(): | ||
|
||
commands = {'backup': backup, 'restore': restore} | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
'address', metavar='address', default='localhost', nargs='?', | ||
help='address of the fossildb server (default: %(default)s)') | ||
parser.add_argument( | ||
'port', metavar='port', type=int, default=8090, nargs='?', | ||
help='port of the fossildb server (default: %(default)s)') | ||
parser.add_argument( | ||
'command', metavar='command', | ||
help='command to execute, one of {}'.format(list(commands.keys()))) | ||
|
||
args = parser.parse_args() | ||
|
||
full_address = '{}:{}'.format(args.address, args.port) | ||
|
||
print('Requesting RestoreFromBackup to FossilDB at', full_address) | ||
|
||
channel = grpc.insecure_channel(full_address) | ||
stub = fossildbapi_pb2_grpc.FossilDBStub(channel) | ||
|
||
reply = commands[args.command](stub) | ||
|
||
print(reply) | ||
if not reply.success: | ||
sys.exit(1) | ||
|
||
|
||
def restore(stub): | ||
return stub.RestoreFromBackup(fossildbapi_pb2.RestoreFromBackupRequest()) | ||
|
||
|
||
def backup(stub): | ||
return stub.Backup(fossildbapi_pb2.BackupRequest()) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
argparse | ||
grpcio-tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
set -Eeuo pipefail | ||
|
||
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" | ||
|
||
python3 -m grpc_tools.protoc -I$SCRIPTPATH/../src/main/protobuf --python_out=$SCRIPTPATH --grpc_python_out=$SCRIPTPATH $SCRIPTPATH/../src/main/protobuf/fossildbapi.proto |