def cluster_resize(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster resize operation. Validate data before actual resize is delegated to cluster service. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ rde_in_use = server_utils.get_rde_version_in_use() svc = cluster_service_factory.ClusterServiceFactory(op_ctx). \ get_cluster_service(rde_in_use) cluster_id = data[RequestKey.CLUSTER_ID] # TODO find out the RDE version from the request spec # TODO Insert RDE converters and validators NativeEntityClass = rde_factory.get_rde_model(rde_in_use) cluster_entity_spec: AbstractNativeEntity = \ NativeEntityClass(**data[RequestKey.INPUT_SPEC]) # noqa: E501 curr_entity = svc.entity_svc.get_entity(cluster_id) request_utils.validate_request_payload( asdict(cluster_entity_spec.spec), asdict(curr_entity.entity.spec), exclude_fields=[ FlattenedClusterSpecKey.WORKERS_COUNT.value, FlattenedClusterSpecKey.NFS_COUNT.value ]) return asdict(svc.resize_cluster(cluster_id, cluster_entity_spec))
def cluster_upgrade(data, op_ctx: ctx.OperationContext): """Request handler for cluster upgrade operation. Validate data before actual upgrade is delegated to cluster service. :return: Dict """ rde_in_use = server_utils.get_rde_version_in_use() svc = cluster_service_factory.ClusterServiceFactory(op_ctx). \ get_cluster_service(rde_in_use) # TODO find out the RDE version from the request spec # TODO Insert RDE converters and validators NativeEntityClass = rde_factory.get_rde_model(rde_in_use) cluster_entity_spec: AbstractNativeEntity = \ NativeEntityClass(**data[RequestKey.INPUT_SPEC]) cluster_id = data[RequestKey.CLUSTER_ID] curr_entity = svc.entity_svc.get_entity(cluster_id) request_utils.validate_request_payload( asdict(cluster_entity_spec.spec), asdict(curr_entity.entity.spec), exclude_fields=[ FlattenedClusterSpecKey.TEMPLATE_NAME.value, FlattenedClusterSpecKey.TEMPLATE_REVISION.value ]) return asdict(svc.upgrade_cluster(cluster_id, cluster_entity_spec))
def cluster_resize(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster resize operation. Validate data before actual resize is delegated to cluster service. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ input_entity: dict = data[RequestKey.INPUT_SPEC] # Convert the input entity to runtime rde format. # Based on the runtime rde, call the appropriate backend method. converted_native_entity: AbstractNativeEntity = rde_utils.convert_input_rde_to_runtime_rde_format( input_entity) # noqa: E501 svc = cluster_service_factory.ClusterServiceFactory( op_ctx).get_cluster_service() # noqa: E501 cluster_id = data[RequestKey.CLUSTER_ID] curr_entity = svc.entity_svc.get_entity(cluster_id) request_utils.validate_request_payload( converted_native_entity.spec.to_dict(), curr_entity.entity.spec.to_dict(), # noqa: E501 exclude_fields=[ FlattenedClusterSpecKey1X.WORKERS_COUNT.value, FlattenedClusterSpecKey1X.NFS_COUNT.value ]) new_rde: common_models.DefEntity = svc.resize_cluster( cluster_id, converted_native_entity) # noqa: E501 # convert the resized rde back to input rde version new_native_entity: AbstractNativeEntity = rde_utils.convert_runtime_rde_to_input_rde_version_format( # noqa: E501 new_rde.entity, rde_constants.RDEVersion.RDE_1_0_0) new_rde.entity = new_native_entity return new_rde.to_dict()
def cluster_resize(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster resize operation. Validate data before actual resize is delegated to cluster service. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ rde_in_use = server_utils.get_rde_version_in_use() input_entity: dict = data[RequestKey.INPUT_SPEC] payload_version = input_entity.get( rde_constants.PayloadKey.PAYLOAD_VERSION_RDE_1_0.value) # noqa: E501 # Reject request >= 2.0 _raise_error_if_unsupported_payload_version(payload_version) # Convert the input entity to runtime rde format converted_native_entity: AbstractNativeEntity = rde_utils.convert_input_rde_to_runtime_rde_format( input_entity) # noqa: E501 # Redirect to generic handler if the backend supports RDE-2.0 if semantic_version.Version(rde_in_use) >= semantic_version.Version( rde_constants.RDEVersion.RDE_2_0_0.value): # noqa: E501 data[RequestKey.INPUT_SPEC] = converted_native_entity.to_dict() rde_data: dict = cluster_handler.cluster_update( data=data, op_ctx=op_ctx) # noqa: E501 new_rde = common_models.DefEntity(**rde_data) else: # Based on the runtime rde, call the appropriate backend method. svc = cluster_service_factory.ClusterServiceFactory( op_ctx).get_cluster_service() # noqa: E501 cluster_id = data[RequestKey.CLUSTER_ID] curr_entity = svc.entity_svc.get_entity(cluster_id) request_utils.validate_request_payload( converted_native_entity.spec.to_dict(), curr_entity.entity.spec.to_dict(), # noqa: E501 exclude_fields=[ FlattenedClusterSpecKey1X.WORKERS_COUNT.value, FlattenedClusterSpecKey1X.NFS_COUNT.value, FlattenedClusterSpecKey1X.EXPOSE.value ]) new_rde: common_models.DefEntity = svc.resize_cluster( cluster_id, converted_native_entity) # noqa: E501 # convert the resized rde back to input rde version return _convert_rde_to_1_0_format(new_rde.to_dict())