def cluster_update(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster update operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ cluster_id = data[RequestKey.CLUSTER_ID] input_entity: dict = data[RequestKey.INPUT_SPEC] # Validate the input # ToDo: Should the validation be done using a v36 client? rde_validator_factory.get_validator( rde_version=rde_constants.RDEVersion.RDE_2_0_0). \ validate(cloudapi_client=op_ctx.cloudapi_client, entity_id=cluster_id, entity=input_entity, operation=BehaviorOperation.UPDATE_CLUSTER) # TODO Insert RDE converter if needed. # Call the backend to initiate the cluster update operation. rde_in_use = server_utils.get_rde_version_in_use() svc = cluster_service_factory.ClusterServiceFactory(op_ctx). \ get_cluster_service(rde_in_use) NativeEntityClass: Type[AbstractNativeEntity] = rde_factory.get_rde_model( rde_in_use) # noqa: E501 cluster_entity: AbstractNativeEntity = \ NativeEntityClass.from_dict(input_entity) return svc.update_cluster(cluster_id, cluster_entity).to_dict()
def create_cluster(behavior_ctx: BehaviorRequestContext): entity_id: str = behavior_ctx.entity_id input_entity: dict = behavior_ctx.entity cloudapi_client: CloudApiClient = behavior_ctx.op_ctx.cloudapi_client payload_version: str = input_entity.get( rde_constants.PayloadKey.PAYLOAD_VERSION) # noqa: E501 rde_utils.raise_error_if_unsupported_payload_version(payload_version) # Validate the Input payload based on the (Operation, payload_version). # Get the validator based on the payload_version input_rde_version = rde_constants.MAP_INPUT_PAYLOAD_VERSION_TO_RDE_VERSION[ payload_version] # noqa: E501 rde_validator_factory.get_validator( rde_version=input_rde_version). \ validate(cloudapi_client=cloudapi_client, entity=input_entity) # Convert the input entity to runtime rde format. # Based on the runtime rde, call the appropriate backend method. converted_input_entity = rde_utils.convert_input_rde_to_runtime_rde_format( input_entity) # noqa: E501 svc = cluster_service_factory.ClusterServiceFactory( behavior_ctx).get_cluster_service() # noqa: E501 return svc.create_cluster( entity_id=entity_id, input_native_entity=converted_input_entity) # noqa: E501
def update_cluster(behavior_ctx: RequestContext): entity_id: str = behavior_ctx.entity_id input_entity: dict = behavior_ctx.entity cloudapi_client: CloudApiClient = behavior_ctx.op_ctx.cloudapi_client payload_version: str = input_entity.get( rde_constants.PayloadKey.PAYLOAD_VERSION) # noqa: E501 rde_utils.raise_error_if_unsupported_payload_version( payload_version=payload_version) # Validate the Input payload based on the (Operation, payload_version). # Get the validator based on the payload_version kind = input_entity['kind'] is_tkgm_cluster = (kind == ClusterEntityKind.TKG_M.value) sysadmin_client = behavior_ctx.op_ctx.sysadmin_client input_rde_version = rde_constants.MAP_INPUT_PAYLOAD_VERSION_TO_RDE_VERSION[ payload_version] # noqa: E501 rde_validator_factory.get_validator( rde_version=input_rde_version). \ validate(cloudapi_client=cloudapi_client, sysadmin_client=sysadmin_client, operation=BehaviorOperation.UPDATE_CLUSTER, entity_id=entity_id, entity=input_entity, is_tkgm_cluster=is_tkgm_cluster) # Convert the input entity to runtime rde format. # Based on the runtime rde, call the appropriate backend method. converted_input_entity = rde_utils.convert_input_rde_to_runtime_rde_format( input_entity) # noqa: E501 svc = cluster_service_factory.ClusterServiceFactory( behavior_ctx).get_cluster_service() # noqa: E501 return svc.update_cluster( entity_id, input_native_entity=converted_input_entity) # noqa: E501
def cluster_create(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster create operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ input_entity: dict = data[RequestKey.INPUT_SPEC] payload_version = input_entity.get(rde_constants.PayloadKey.PAYLOAD_VERSION) # noqa: E501 rde_utils.raise_error_if_unsupported_payload_version(payload_version) # Validate the Input payload based on the (Operation, payload_version). # Get the validator based on the payload_version # ToDo : Don't use default cloudapi_client. Use the specific versioned one rde_validator_factory.get_validator( rde_version=rde_constants.MAP_INPUT_PAYLOAD_VERSION_TO_RDE_VERSION[ payload_version]).validate(cloudapi_client=op_ctx.cloudapi_client, entity=input_entity) # Convert the input entity to runtime rde format. # Based on the runtime rde, call the appropriate backend method. converted_native_entity = 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 # TODO: Response RDE must be compatible with the request RDE. # Conversions may be needed especially if there is a major version # difference in the input RDE and runtime RDE. return svc.create_cluster(converted_native_entity).to_dict()
def cluster_create(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster create operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ input_entity: dict = data[RequestKey.INPUT_SPEC] payload_version = input_entity.get( rde_constants.PayloadKey.PAYLOAD_VERSION) # noqa: E501 rde_utils.raise_error_if_unsupported_payload_version(payload_version) # Validate the Input payload based on the (Operation, payload_version). # Get the validator based on the payload_version # ToDo : Don't use default cloudapi_client. Use the specific versioned one rde_validator_factory.get_validator( rde_version=rde_constants. MAP_INPUT_PAYLOAD_VERSION_TO_RDE_VERSION[payload_version]).validate( cloudapi_client=op_ctx.cloudapi_client, sysadmin_client=op_ctx.sysadmin_client, entity=input_entity) def_entity_service = entity_service.DefEntityService( op_ctx.cloudapi_client) # noqa: E501 entity_type = server_utils.get_registered_def_entity_type() converted_entity: AbstractNativeEntity = rde_utils.convert_input_rde_to_runtime_rde_format( input_entity) # noqa: E501 def_entity = common_models.DefEntity( entity=converted_entity, entityType=entity_type.id) # noqa: E501 # No need to set org context for non sysadmin users org_context = None if op_ctx.client.is_sysadmin(): org_resource = pyvcloud_utils.get_org( op_ctx.client, org_name=converted_entity.metadata.org_name) # noqa: E501 org_context = org_resource.href.split('/')[-1] _, task_href = def_entity_service.create_entity( entity_type_id=entity_type.id, entity=def_entity, tenant_org_context=org_context, is_request_async=True) task_resource = op_ctx.sysadmin_client.get_resource(task_href) entity_id = task_resource.Owner.get('id') def_entity = def_entity_service.get_entity(entity_id) def_entity.entity.status.task_href = task_href telemetry_handler.record_user_action_details( cse_operation=telemetry_constants.CseOperation.V36_CLUSTER_APPLY, cse_params={ server_constants.CLUSTER_ENTITY: def_entity, telemetry_constants.PayloadKey.SOURCE_DESCRIPTION: thread_local_data.get_thread_local_data( ThreadLocalData.USER_AGENT) # noqa: E501 }) return def_entity.to_dict()
def cluster_update(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster resize operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ cluster_id = data[RequestKey.CLUSTER_ID] input_entity: dict = data[RequestKey.INPUT_SPEC] payload_version = input_entity.get( rde_constants.PayloadKey.PAYLOAD_VERSION) # noqa: E501 rde_utils.raise_error_if_unsupported_payload_version(payload_version) # Validate the Input payload based on the (Operation, payload_version). # Get the validator based on the payload_version # ToDo : Don't use default cloudapi_client. Use the specific versioned one kind = input_entity['kind'] is_tkgm_cluster = (kind == ClusterEntityKind.TKG_M.value) sysadmin_client = op_ctx.sysadmin_client rde_validator_factory.get_validator( rde_version=rde_constants.MAP_INPUT_PAYLOAD_VERSION_TO_RDE_VERSION[ payload_version]). \ validate(cloudapi_client=op_ctx.cloudapi_client, sysadmin_client=sysadmin_client, entity_id=cluster_id, entity=input_entity, operation=BehaviorOperation.UPDATE_CLUSTER, is_tkgm_cluster=is_tkgm_cluster) # Convert the input entity to runtime rde format. # Based on the runtime rde, call the appropriate backend method. def_entity_service = entity_service.DefEntityService( op_ctx.cloudapi_client) # noqa: E501 converted_native_entity: AbstractNativeEntity = rde_utils.convert_input_rde_to_runtime_rde_format( input_entity) # noqa: E501 changes = {'entity.spec': converted_native_entity.spec} updated_def_entity, task_href = def_entity_service.update_entity( entity_id=cluster_id, invoke_hooks=True, is_request_async=True, changes=changes) updated_def_entity.entity.status.task_href = task_href telemetry_handler.record_user_action_details( cse_operation=telemetry_constants.CseOperation.V36_CLUSTER_APPLY, cse_params={ server_constants.CLUSTER_ENTITY: updated_def_entity, telemetry_constants.PayloadKey.SOURCE_DESCRIPTION: thread_local_data.get_thread_local_data( ThreadLocalData.USER_AGENT) # noqa: E501 }) # TODO: Response RDE must be compatible with the request RDE. # Conversions may be needed especially if there is a major version # difference in the input RDE and runtime RDE. return updated_def_entity.to_dict()
def cluster_update(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster resize operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ cluster_id = data[RequestKey.CLUSTER_ID] input_entity: dict = data[RequestKey.INPUT_SPEC] payload_version = input_entity.get( rde_constants.PayloadKey.PAYLOAD_VERSION) # noqa: E501 rde_utils.raise_error_if_unsupported_payload_version(payload_version) # Validate the Input payload based on the (Operation, payload_version). # Get the validator based on the payload_version # ToDo : Don't use default cloudapi_client. Use the specific versioned one rde_validator_factory.get_validator( rde_version=rde_constants.MAP_INPUT_PAYLOAD_VERSION_TO_RDE_VERSION[ payload_version]). \ validate(cloudapi_client=op_ctx.cloudapi_client, entity_id=cluster_id, entity=input_entity, operation=BehaviorOperation.UPDATE_CLUSTER) # Convert the input entity to runtime rde format. # Based on the runtime rde, call the appropriate backend method. def_entity_service = entity_service.DefEntityService( op_ctx.cloudapi_client) # noqa: E501 converted_native_entity: AbstractNativeEntity = rde_utils.convert_input_rde_to_runtime_rde_format( input_entity) # noqa: E501 cluster_def_entity: common_models.DefEntity = def_entity_service.get_entity( cluster_id) # noqa: E501 cluster_def_entity.entity.spec = converted_native_entity.spec updated_def_entity, task_href = def_entity_service.update_entity( entity_id=cluster_id, entity=cluster_def_entity, invoke_hooks=True, is_request_async=True) updated_def_entity.entity.status.task_href = task_href # TODO: Response RDE must be compatible with the request RDE. # Conversions may be needed especially if there is a major version # difference in the input RDE and runtime RDE. return updated_def_entity.to_dict()
def cluster_create(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster create operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ input_entity: dict = data[RequestKey.INPUT_SPEC] # Validate the input rde_validator_factory.get_validator( rde_version=rde_constants.RDEVersion.RDE_2_0_0). \ validate(cloudapi_client=op_ctx.cloudapi_client, entity=input_entity) rde_in_use = server_utils.get_rde_version_in_use() svc = cluster_service_factory.ClusterServiceFactory(op_ctx). \ get_cluster_service(rde_in_use) # TODO Insert RDE converter if needed. NativeEntityClass: Type[AbstractNativeEntity] = rde_factory.get_rde_model( rde_in_use) # noqa: E501 cluster_entity_spec: AbstractNativeEntity = \ NativeEntityClass(**input_entity) return asdict(svc.create_cluster(cluster_entity_spec))
def create_cluster(behavior_ctx: BehaviorRequestContext): entity_id: str = behavior_ctx.entity_id entity: dict = behavior_ctx.entity cloudapi_client: CloudApiClient = behavior_ctx.op_ctx.cloudapi_client api_version: float = behavior_ctx.api_version # Validate the input rde_version_introduced_at_api_version = rde_utils.get_rde_version_introduced_at_api_version( api_version) # noqa: E501 rde_validator_factory.get_validator( rde_version=rde_version_introduced_at_api_version). \ validate(cloudapi_client=cloudapi_client, entity=entity) # TODO Based on the rde_in_use, convert the entity if necessary. # Call the backend to initiate the cluster creation. rde_in_use = server_utils.get_rde_version_in_use() svc = cluster_service_factory.ClusterServiceFactory( behavior_ctx).get_cluster_service(rde_in_use) # noqa: E501 NativeEntityClass: AbstractNativeEntity = rde_factory.get_rde_model( rde_in_use) # noqa: E501 input_entity: AbstractNativeEntity = NativeEntityClass(**entity) return svc.create_cluster(entity_id=entity_id, input_native_entity=input_entity) # noqa: E501