AttachTargetGroup
Attaches a target group to the specified network load balancer.
- TypeScript
- Python
import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";
const AttachNetworkLoadBalancerTargetGroupRequest =
cloudApi.loadbalancer.network_load_balancer_service
.AttachNetworkLoadBalancerTargetGroupRequest;
const NetworkLoadBalancer =
cloudApi.loadbalancer.network_load_balancer.NetworkLoadBalancer;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(
serviceClients.NetworkLoadBalancerServiceClient
);
const operation = await client.attachTargetGroup(
AttachNetworkLoadBalancerTargetGroupRequest.fromPartial({
networkLoadBalancerId: "networkLoadBalancerId",
attachedTargetGroup: {
targetGroupId: "targetGroupId",
// healthChecks: [{
// name: "name",
// interval: {
// seconds: 0,
// nanos: 0
// },
// timeout: {
// seconds: 0,
// nanos: 0
// },
// unhealthyThreshold: 0,
// healthyThreshold: 0,
// tcpOptions: {
// port: 0
// },
// httpOptions: {
// port: 0,
// path: "path"
// }
// }]
},
})
);
const finishedOp = await waitForOperation(operation, session);
if (finishedOp.response) {
const result = decodeMessage<typeof NetworkLoadBalancer>(
finishedOp.response
);
console.log(result);
}
})();
import os
import grpc
import yandexcloud
from yandex.cloud.loadbalancer.v1.network_load_balancer_service_pb2 import (
AttachNetworkLoadBalancerTargetGroupMetadata,
)
from yandex.cloud.loadbalancer.v1.network_load_balancer_service_pb2 import (
AttachNetworkLoadBalancerTargetGroupRequest,
)
from yandex.cloud.loadbalancer.v1.network_load_balancer_pb2 import AttachedTargetGroup
from yandex.cloud.loadbalancer.v1.health_check_pb2 import HealthCheck
from yandex.cloud.loadbalancer.v1.network_load_balancer_pb2 import NetworkLoadBalancer
from yandex.cloud.loadbalancer.v1.network_load_balancer_service_pb2_grpc import (
NetworkLoadBalancerServiceStub,
)
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(NetworkLoadBalancerServiceStub)
operation = service.AttachTargetGroup(
AttachNetworkLoadBalancerTargetGroupRequest(
network_load_balancer_id="networkLoadBalancerId",
attached_target_group=AttachedTargetGroup(
target_group_id="targetGroupId",
# health_checks = [HealthCheck(
# name = "name",
# interval = Duration(
# seconds = 0,
# nanos = 0
# ),
# timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# unhealthy_threshold = 0,
# healthy_threshold = 0,
# tcp_options = HealthCheck.TcpOptions(
# port = 0
# ),
# http_options = HealthCheck.HttpOptions(
# port = 0,
# path = "path"
# )
# )]
),
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=NetworkLoadBalancer,
meta_type=AttachNetworkLoadBalancerTargetGroupMetadata,
)
print(operation_result)
AttachNetworkLoadBalancerTargetGroupRequest
networkLoadBalancerId
: string
ID of the network load balancer to attach the target group to. To get the network load balancer ID, use a NetworkLoadBalancerService.List request.
attachedTargetGroup
: AttachedTargetGroup
ID of the attached target group to attach to the network load balancer. To get the network load balancer ID, use a NetworkLoadBalancerService.List request.
AttachedTargetGroup
An AttachedTargetGroup resource. For more information, see Targets and groups.
targetGroupId
: string
ID of the target group.
healthChecks
: HealthCheck
A health check to perform on the target group. For now we accept only one health check per AttachedTargetGroup.
HealthCheck
A HealthCheck resource. For more information, see Health check.
TcpOptions
Configuration option for a TCP health check.
port
: int64
Port to use for TCP health checks.
HttpOptions
Configuration option for an HTTP health check.
port
: int64
Port to use for HTTP health checks.
path
: string
URL path to set for health checking requests for every target in the target group.
For example /ping
. The default path is /
.
name
: string
Name of the health check. The name must be unique for each target group that attached to a single load balancer. 3-63 characters long.
interval
: google.protobuf.Duration
The interval between health checks. The default is 2 seconds.
timeout
: google.protobuf.Duration
Timeout for a target to return a response for the health check. The default is 1 second.
unhealthyThreshold
: int64
Number of failed health checks before changing the status to UNHEALTHY
. The default is 2.
healthyThreshold
: int64
Number of successful health checks required in order to set the HEALTHY
status for the target. The default is 2.
One of options
Protocol to use for the health check. Either TCP or HTTP.
tcpOptions
: TcpOptionsOptions for TCP health check.
httpOptions
: HttpOptionsOptions for HTTP health check.
TcpOptions
Configuration option for a TCP health check.
port
: int64
Port to use for TCP health checks.
HttpOptions
Configuration option for an HTTP health check.
port
: int64
Port to use for HTTP health checks.
path
: string
URL path to set for health checking requests for every target in the target group.
For example /ping
. The default path is /
.
Operation
An Operation resource. For more information, see Operation.
id
: string
ID of the operation.
description
: string
Description of the operation. 0-256 characters long.
createdAt
: google.protobuf.Timestamp
Creation timestamp.
createdBy
: string
ID of the user or service account who initiated the operation.
modifiedAt
: google.protobuf.Timestamp
The time when the Operation resource was last modified.
done
: bool
If the value is false
, it means the operation is still in progress.
If true
, the operation is completed, and either error
or response
is available.
metadata
: google.protobuf.Any
Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.
One of result
The operation result.
If done == false
and there was no failure detected, neither error
nor response
is set.
If done == false
and there was a failure detected, error
is set.
If done == true
, exactly one of error
or response
is set.
error
: google.rpc.StatusThe error result of the operation in case of failure or cancellation.
response
: google.protobuf.AnyThe normal response of the operation in case of success.
If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.