forked from GoogleCloudPlatform/python-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_cluster.py
More file actions
59 lines (51 loc) · 2.1 KB
/
update_cluster.py
File metadata and controls
59 lines (51 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START vmwareengine_update_cluster_node_count]
from google.api_core import operation
from google.cloud import vmwareengine_v1
def update_cluster_node_count(
project_id: str,
zone: str,
private_cloud_name: str,
cluster_name: str,
node_count: int,
) -> operation.Operation:
"""
Modify the number of nodes in a cluster in a private cloud.
Modifying a cluster is a long-running operation and it may take over an hour.
Args:
project_id: name of the project you want to use.
zone: zone in which your private cloud is located.
private_cloud_name: name of the private cloud hosting the cluster.
cluster_name: name of the cluster.
node_count: desired number of nodes in the cluster.
Returns:
An Operation object related to cluster modification operation.
"""
if node_count < 3:
raise RuntimeError("Cluster needs to have at least 3 nodes")
client = vmwareengine_v1.VmwareEngineClient()
request = vmwareengine_v1.UpdateClusterRequest()
request.cluster = vmwareengine_v1.Cluster()
request.cluster.name = (
f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
f"/clusters/{cluster_name}"
)
request.cluster.node_type_configs = {
"standard-72": vmwareengine_v1.NodeTypeConfig()
}
request.cluster.node_type_configs["standard-72"].node_count = node_count
request.update_mask = "nodeTypeConfigs.*.nodeCount"
return client.update_cluster(request)
# [END vmwareengine_update_cluster_node_count]