diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-01-26 19:49:18 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-01-26 20:02:23 +0300 |
commit | 27b1811df443f5a3d16e2ae0f1744f39b348109d (patch) | |
tree | d32eadbe20b6050cc48bf72bc0c8f7f448891ca7 /contrib | |
parent | 7686d090e4600e50d1ed8e3df64b539705e879fb (diff) | |
download | ydb-27b1811df443f5a3d16e2ae0f1744f39b348109d.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/python/ydb/py3/.dist-info/METADATA | 2 | ||||
-rw-r--r-- | contrib/python/ydb/py3/ya.make | 4 | ||||
-rw-r--r-- | contrib/python/ydb/py3/ydb/__init__.py | 1 | ||||
-rw-r--r-- | contrib/python/ydb/py3/ydb/_apis.py | 26 | ||||
-rw-r--r-- | contrib/python/ydb/py3/ydb/draft/__init__.py | 1 | ||||
-rw-r--r-- | contrib/python/ydb/py3/ydb/draft/dynamic_config.py | 173 | ||||
-rw-r--r-- | contrib/python/ydb/py3/ydb/ydb_version.py | 2 |
7 files changed, 206 insertions, 3 deletions
diff --git a/contrib/python/ydb/py3/.dist-info/METADATA b/contrib/python/ydb/py3/.dist-info/METADATA index 394559f8df..675a1d8825 100644 --- a/contrib/python/ydb/py3/.dist-info/METADATA +++ b/contrib/python/ydb/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: ydb -Version: 3.7.1 +Version: 3.8.0 Summary: YDB Python SDK Home-page: http://github.com/ydb-platform/ydb-python-sdk Author: Yandex LLC diff --git a/contrib/python/ydb/py3/ya.make b/contrib/python/ydb/py3/ya.make index af4882e7d0..484d68aafd 100644 --- a/contrib/python/ydb/py3/ya.make +++ b/contrib/python/ydb/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(3.7.1) +VERSION(3.8.0) LICENSE(Apache-2.0) @@ -66,6 +66,8 @@ PY_SRCS( ydb/dbapi/cursor.py ydb/dbapi/errors.py ydb/default_pem.py + ydb/draft/__init__.py + ydb/draft/dynamic_config.py ydb/driver.py ydb/export.py ydb/global_settings.py diff --git a/contrib/python/ydb/py3/ydb/__init__.py b/contrib/python/ydb/py3/ydb/__init__.py index 902b1e0850..8bfba3a902 100644 --- a/contrib/python/ydb/py3/ydb/__init__.py +++ b/contrib/python/ydb/py3/ydb/__init__.py @@ -18,6 +18,7 @@ from .scripting import * # noqa from .import_client import * # noqa from .tracing import * # noqa from .topic import * # noqa +from .draft import * # noqa try: import ydb.aio as aio # noqa diff --git a/contrib/python/ydb/py3/ydb/_apis.py b/contrib/python/ydb/py3/ydb/_apis.py index 924e14c1b6..9ad2a32f21 100644 --- a/contrib/python/ydb/py3/ydb/_apis.py +++ b/contrib/python/ydb/py3/ydb/_apis.py @@ -11,6 +11,10 @@ try: ydb_topic_v1_pb2_grpc, ) + from ydb.public.api.grpc.draft import ( + ydb_dynamic_config_v1_pb2_grpc, + ) + from ydb.public.api.protos import ( ydb_status_codes_pb2, ydb_discovery_pb2, @@ -20,6 +24,10 @@ try: ydb_operation_pb2, ydb_common_pb2, ) + + from ydb.public.api.protos.draft import ( + ydb_dynamic_config_pb2, + ) except ImportError: from contrib.ydb.public.api.grpc import ( ydb_cms_v1_pb2_grpc, @@ -30,6 +38,10 @@ except ImportError: ydb_topic_v1_pb2_grpc, ) + from contrib.ydb.public.api.grpc.draft import ( + ydb_dynamic_config_v1_pb2_grpc, + ) + from contrib.ydb.public.api.protos import ( ydb_status_codes_pb2, ydb_discovery_pb2, @@ -40,6 +52,10 @@ except ImportError: ydb_common_pb2, ) + from contrib.ydb.public.api.protos.draft import ( + ydb_dynamic_config_pb2, + ) + StatusIds = ydb_status_codes_pb2.StatusIds FeatureFlag = ydb_common_pb2.FeatureFlag @@ -49,6 +65,7 @@ ydb_scheme = ydb_scheme_pb2 ydb_table = ydb_table_pb2 ydb_discovery = ydb_discovery_pb2 ydb_operation = ydb_operation_pb2 +ydb_dynamic_config = ydb_dynamic_config_pb2 class CmsService(object): @@ -108,3 +125,12 @@ class TopicService(object): DropTopic = "DropTopic" StreamRead = "StreamRead" StreamWrite = "StreamWrite" + + +class DynamicConfigService(object): + Stub = ydb_dynamic_config_v1_pb2_grpc.DynamicConfigServiceStub + + ReplaceConfig = "ReplaceConfig" + SetConfig = "SetConfig" + GetConfig = "GetConfig" + GetNodeLabels = "GetNodeLabels" diff --git a/contrib/python/ydb/py3/ydb/draft/__init__.py b/contrib/python/ydb/py3/ydb/draft/__init__.py new file mode 100644 index 0000000000..c34316f2c2 --- /dev/null +++ b/contrib/python/ydb/py3/ydb/draft/__init__.py @@ -0,0 +1 @@ +from .dynamic_config import * # noqa diff --git a/contrib/python/ydb/py3/ydb/draft/dynamic_config.py b/contrib/python/ydb/py3/ydb/draft/dynamic_config.py new file mode 100644 index 0000000000..afec19eca7 --- /dev/null +++ b/contrib/python/ydb/py3/ydb/draft/dynamic_config.py @@ -0,0 +1,173 @@ +import abc +from abc import abstractmethod +from .. import issues, operation, _apis + + +class IDynamicConfigClient(abc.ABC): + @abstractmethod + def __init__(self, driver): + pass + + @abstractmethod + def replace_config(self, config, dry_run, allow_unknown_fields, settings): + pass + + @abstractmethod + def set_config(self, config, dry_run, allow_unknown_fields, settings): + pass + + @abstractmethod + def get_config(self, settings): + pass + + @abstractmethod + def get_node_labels(self, node_id, settings): + pass + + +class DynamicConfig(object): + __slots__ = ("version", "cluster", "config") + + def __init__(self, version, cluster, config, *args, **kwargs): + self.version = version + self.cluster = cluster + self.config = config + + +class NodeLabels(object): + __slots__ = "labels" + + def __init__(self, labels, *args, **kwargs): + self.labels = labels + + +def _replace_config_request_factory(config, dry_run, allow_unknown_fields): + request = _apis.ydb_dynamic_config.ReplaceConfigRequest() + request.config = config + request.dry_run = dry_run + request.allow_unknown_fields = allow_unknown_fields + return request + + +def _set_config_request_factory(config, dry_run, allow_unknown_fields): + request = _apis.ydb_dynamic_config.SetConfigRequest() + request.config = config + request.dry_run = dry_run + request.allow_unknown_fields = allow_unknown_fields + return request + + +def _get_config_request_factory(): + request = _apis.ydb_dynamic_config.GetConfigRequest() + return request + + +def _get_node_labels_request_factory(node_id): + request = _apis.ydb_dynamic_config.GetNodeLabelsRequest() + request.node_id = node_id + return request + + +def _wrap_dynamic_config(config_pb, dynamic_config_cls=None, *args, **kwargs): + dynamic_config_cls = DynamicConfig if dynamic_config_cls is None else dynamic_config_cls + return dynamic_config_cls(config_pb.identity.version, config_pb.identity.cluster, config_pb.config, *args, **kwargs) + + +def _wrap_get_config_response(rpc_state, response): + issues._process_response(response.operation) + message = _apis.ydb_dynamic_config.GetConfigResult() + response.operation.result.Unpack(message) + return _wrap_dynamic_config(message) + + +def _wrap_node_labels(labels_pb, node_labels_cls=None, *args, **kwargs): + node_labels_cls = NodeLabels if node_labels_cls is None else node_labels_cls + return node_labels_cls(dict([(entry.label, entry.value) for entry in labels_pb.labels]), *args, **kwargs) + + +def _wrap_get_node_labels_response(rpc_state, response): + issues._process_response(response.operation) + message = _apis.ydb_dynamic_config.GetNodeLabelsResult() + response.operation.result.Unpack(message) + return _wrap_node_labels(message) + + +class BaseDynamicConfigClient(IDynamicConfigClient): + __slots__ = ("_driver",) + + def __init__(self, driver): + self._driver = driver + + def replace_config(self, config, dry_run, allow_unknown_fields, settings=None): + return self._driver( + _replace_config_request_factory(config, dry_run, allow_unknown_fields), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.ReplaceConfig, + operation.Operation, + settings, + ) + + def set_config(self, config, dry_run, allow_unknown_fields, settings=None): + return self._driver( + _set_config_request_factory(config, dry_run, allow_unknown_fields), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.SetConfig, + operation.Operation, + settings, + ) + + def get_config(self, settings=None): + return self._driver( + _get_config_request_factory(), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.GetConfig, + _wrap_get_config_response, + settings, + ) + + def get_node_labels(self, node_id, settings=None): + return self._driver( + _get_node_labels_request_factory(node_id), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.GetNodeLabels, + _wrap_get_node_labels_response, + settings, + ) + + +class DynamicConfigClient(BaseDynamicConfigClient): + def async_replace_config(self, config, dry_run, allow_unknown_fields, settings=None): + return self._driver.future( + _replace_config_request_factory(config, dry_run, allow_unknown_fields), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.ReplaceConfig, + operation.Operation, + settings, + ) + + def async_set_config(self, config, dry_run, allow_unknown_fields, settings=None): + return self._driver.future( + _set_config_request_factory(config, dry_run, allow_unknown_fields), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.SetConfig, + operation.Operation, + settings, + ) + + def async_get_config(self, settings=None): + return self._driver.future( + _get_config_request_factory(), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.GetConfig, + _wrap_get_config_response, + settings, + ) + + def async_get_node_labels(self, node_id, settings=None): + return self._driver.future( + _get_node_labels_request_factory(node_id), + _apis.DynamicConfigService.Stub, + _apis.DynamicConfigService.GetNodeLabels, + _wrap_get_node_labels_response, + settings, + ) diff --git a/contrib/python/ydb/py3/ydb/ydb_version.py b/contrib/python/ydb/py3/ydb/ydb_version.py index 02e0768899..8173e1e609 100644 --- a/contrib/python/ydb/py3/ydb/ydb_version.py +++ b/contrib/python/ydb/py3/ydb/ydb_version.py @@ -1 +1 @@ -VERSION = "3.7.1" +VERSION = "3.8.0" |