[#3] Added generate proto script create container method
Signed-off-by: Ilyas Niyazov <i.niyazov@yadro.com>
This commit is contained in:
parent
fba6eaaa9c
commit
d2e0c80f7c
16 changed files with 348 additions and 51 deletions
|
@ -2,6 +2,8 @@ from typing import Optional
|
|||
|
||||
import grpc
|
||||
|
||||
from frostfs_sdk.client.models.client_environment import ClientEnvironment
|
||||
from frostfs_sdk.client.services.context_accessor import ContextAccessor
|
||||
from frostfs_sdk.models.mappers.placement_policy_mapper import PlacementPolicyMapper
|
||||
from frostfs_sdk.models.mappers.owner_id_mapper import OwnerIdMapper
|
||||
from frostfs_sdk.models.mappers.version_mapper import VersionMapper
|
||||
|
@ -12,7 +14,7 @@ from frostfs_sdk.protos.models.container import types_pb2 as types_pb2_container
|
|||
|
||||
class ContainerMapper:
|
||||
@staticmethod
|
||||
def to_grpc_message(container: Container) -> Optional[types_pb2_container.Container]:
|
||||
def to_grpc_message(container: Container, client_context: ClientEnvironment) -> Optional[types_pb2_container.Container]:
|
||||
"""
|
||||
Converts Container DTO to gRPC message
|
||||
|
||||
|
@ -30,18 +32,24 @@ class ContainerMapper:
|
|||
for k, v in container.attributes.items()
|
||||
]
|
||||
|
||||
if container.owner_id:
|
||||
owner_id = OwnerIdMapper.to_grpc_message(container.owner_id)
|
||||
else:
|
||||
owner_id = OwnerIdMapper.to_grpc_message(client_context.owner_id)
|
||||
|
||||
if container.version:
|
||||
version = VersionMapper.to_grpc_message(container.version)
|
||||
else:
|
||||
version = VersionMapper.to_grpc_message(client_context.version)
|
||||
|
||||
grpc_container = types_pb2_container.Container(
|
||||
nonce=container.nonce.bytes,
|
||||
placement_policy=PlacementPolicyMapper.to_grpc_message(container.placementPolicy),
|
||||
owner_id=owner_id,
|
||||
version=version,
|
||||
attributes=attributes
|
||||
)
|
||||
|
||||
if container.owner_id:
|
||||
grpc_container.owner_id = OwnerIdMapper.to_grpc_message(container.owner_id)
|
||||
|
||||
if container.version:
|
||||
grpc_container.version = VersionMapper.to_grpc_message(container.version)
|
||||
|
||||
|
||||
return grpc_container
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue