[#3] Added generate proto script
This commit is contained in:
parent
19282f13cc
commit
f736bfce14
5 changed files with 92 additions and 0 deletions
11
.gitignore
vendored
11
.gitignore
vendored
|
@ -1,4 +1,15 @@
|
||||||
# ---> Python
|
# ---> Python
|
||||||
|
# ignore IDE files
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
venv.*
|
||||||
|
.repo
|
||||||
|
.git
|
||||||
|
.git_shadow
|
||||||
|
|
||||||
|
# ignore folders
|
||||||
|
protos
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
23
frostfs_api/client/frostfs_client.py
Normal file
23
frostfs_api/client/frostfs_client.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Create channel and Stubs
|
||||||
|
import grpc
|
||||||
|
from frostfs_api.client.services.container import ContainerClient
|
||||||
|
|
||||||
|
|
||||||
|
class FrostfsClient:
|
||||||
|
def __init__(self, address):
|
||||||
|
self.channel = grpc.insecure_channel(address)
|
||||||
|
self.container = ContainerClient(self.channel)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.channel.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
client = FrostfsClient("localhost:50051")
|
||||||
|
create_response = client.container.create_container("my_container")
|
||||||
|
print("Container created:", create_response)
|
||||||
|
|
||||||
|
get_response = client.container.get_container(create_response)
|
||||||
|
print("Container details:", get_response)
|
||||||
|
|
||||||
|
client.close()
|
20
frostfs_api/client/services/container.py
Normal file
20
frostfs_api/client/services/container.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# implementation Conainer methods
|
||||||
|
import grpc
|
||||||
|
import protos.models.container.service_pb2_grpc as service_pb2_grpc_container
|
||||||
|
import protos.models.container.service_pb2 as service_pb2_container
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ContainerClient:
|
||||||
|
def __init__(self, channel):
|
||||||
|
self.container_stub = service_pb2_grpc_container.ContainerServiceStub(channel)
|
||||||
|
|
||||||
|
def create_container(self, container_name) -> bytes:
|
||||||
|
request = service_pb2_container.PutRequest(name=container_name)
|
||||||
|
response: service_pb2_container.PutResponse = self.container_stub.Put(request)
|
||||||
|
return response.body.container_id
|
||||||
|
|
||||||
|
def get_container(self, container_id) -> service_pb2_container.GetResponse:
|
||||||
|
request = service_pb2_container.GetRequest(id=container_id)
|
||||||
|
response: service_pb2_container.GetResponse = self.container_stub.Get(request)
|
||||||
|
return response
|
36
generate_proto.sh
Executable file
36
generate_proto.sh
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# TODO: add to MakeFile
|
||||||
|
# chmod +x generate_proto.sh
|
||||||
|
# ./generate_proto.sh
|
||||||
|
|
||||||
|
|
||||||
|
# Define directories
|
||||||
|
PROTOS_DIR="./protos"
|
||||||
|
SOURCE_DIR="${PROTOS_DIR}/source"
|
||||||
|
MODELS_DIR="${PROTOS_DIR}/models"
|
||||||
|
REPO_FROSTFS_API_PROTOS="https://git.frostfs.info/TrueCloudLab/frostfs-api.git"
|
||||||
|
|
||||||
|
rm -rf "$PROTOS_DIR"
|
||||||
|
|
||||||
|
# Step 1: Create folder ./protos
|
||||||
|
echo "1. Create folder ./protos"
|
||||||
|
mkdir -p "$PROTOS_DIR"
|
||||||
|
|
||||||
|
# Step 2: Cloning repository into ./protos/source
|
||||||
|
echo "2. Cloning repository into ./protos/source..."
|
||||||
|
mkdir -p "$SOURCE_DIR"
|
||||||
|
git clone "$REPO_FROSTFS_API_PROTOS" "$SOURCE_DIR"
|
||||||
|
|
||||||
|
# Step 3: Generating Python code from .proto files
|
||||||
|
echo "3. Generating Python code from .proto files to $MODELS_DIR"
|
||||||
|
mkdir -p "$MODELS_DIR"
|
||||||
|
find "$SOURCE_DIR" -name "*.proto" | while read -r proto_file; do
|
||||||
|
python -m grpc_tools.protoc -I "$SOURCE_DIR" --python_out="$MODELS_DIR" --pyi_out="$MODELS_DIR" --grpc_python_out="$MODELS_DIR" "$proto_file"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Step 4: Making ./protos/models a Python package
|
||||||
|
echo "4. Making ./protos/models a Python package..."
|
||||||
|
touch "$MODELS_DIR/__init__.py"
|
||||||
|
|
||||||
|
echo "All steps completed successfully."
|
|
@ -1,4 +1,6 @@
|
||||||
base58==2.1.1
|
base58==2.1.1
|
||||||
ecdsa==0.19.0
|
ecdsa==0.19.0
|
||||||
|
grpcio==1.70.0
|
||||||
|
grpcio-tools==1.70.0
|
||||||
|
|
||||||
pytest==8.3.4
|
pytest==8.3.4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue