Skip to content

Commit 859efd7

Browse files
m-strzelczykgcf-owl-bot[bot]rsamborski
authored
docs(samples): Importing code samples for VMWare Engine (#10292)
* docs(samples): Adding VMWare Engine code samples * docs(samples): Adding samples for VMWare Engine * WIP: creating private cloud * Adding credentials samples * Working on docstrings * Progress... * WIP * Adding region tags and tests * Black + lint * Adding pytest to test stuff * some fixes * Use single project * Testing things * Testing things * Making tests work on 3.7 * Update test_cluster.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Apply suggestions from code review Co-authored-by: Remigiusz Samborski <[email protected]> * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update according to comments * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * lint * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update vmwareengine/cloud-client/update_policy.py Co-authored-by: Remigiusz Samborski <[email protected]> * Applying suggestions --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Remigiusz Samborski <[email protected]>
1 parent bc0c7ec commit 859efd7

33 files changed

+1363
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/recaptcha_enterprise/demosite/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/recaptcha-customer-obsession-reviewers @GoogleCloudPlatform/python-samples-reviewers
3838
/secretmanager/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers
3939
/securitycenter/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers
40+
/vmwareengine/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers
4041
/webrisk/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers
4142

4243
# DEE Platform Ops (DEEPO)

.github/auto-label.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ path:
8484
trace: "cloudtrace"
8585
translate: "translate"
8686
vision: "vision"
87+
vmwareengine: "vmwareengine"
8788
webrisk: "webrisk"
8889
workflows: "workflows"
8990
- labelprefix: "asset: "

.github/blunderbuss.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ assign_issues_by:
3939
- "api: recaptchaenterprise"
4040
- "api: secretmanager"
4141
- "api: securitycenter"
42+
- "api: vmwareengine"
4243
to:
4344
- GoogleCloudPlatform/dee-infra
4445
- labels:

vmwareengine/__init__.py

Whitespace-only changes.

vmwareengine/cloud-client/__init__.py

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START vmwareengine_cancel_cloud_deletion]
16+
from google.api_core import operation
17+
from google.cloud import vmwareengine_v1
18+
19+
20+
def cancel_private_cloud_deletion_by_full_name(cloud_name: str) -> operation.Operation:
21+
"""
22+
Cancels in progress deletion of VMWare Private Cloud.
23+
24+
Args:
25+
cloud_name: identifier of the Private Cloud you want to cancel deletion for.
26+
Expected format:
27+
projects/{project_name}/locations/{zone}/privateClouds/{cloud}
28+
29+
Returns:
30+
An Operation object related to canceling private cloud deletion operation.
31+
"""
32+
client = vmwareengine_v1.VmwareEngineClient()
33+
request = vmwareengine_v1.UndeletePrivateCloudRequest()
34+
request.name = cloud_name
35+
return client.undelete_private_cloud(request)
36+
37+
38+
def cancel_private_cloud_deletion(
39+
project_id: str, zone: str, cloud_name: str
40+
) -> operation.Operation:
41+
"""
42+
Cancels in progress deletion of deletion of VMWare Private Cloud.
43+
44+
Args:
45+
project_id: name of the project hosting the private cloud.
46+
zone: zone in which the private cloud is located in.
47+
cloud_name: name of the private cloud to cancel deletion for.
48+
49+
Returns:
50+
An Operation object related to canceling private cloud deletion operation.
51+
"""
52+
return cancel_private_cloud_deletion_by_full_name(
53+
f"projects/{project_id}/locations/{zone}/privateClouds/{cloud_name}"
54+
)
55+
56+
57+
# [END vmwareengine_cancel_cloud_deletion]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START vmwareengine_create_cluster]
16+
from google.api_core import operation
17+
from google.cloud import vmwareengine_v1
18+
19+
20+
def create_cluster(
21+
project_id: str,
22+
zone: str,
23+
private_cloud_name: str,
24+
cluster_name: str,
25+
node_count: int = 4,
26+
) -> operation.Operation:
27+
"""
28+
Create a new cluster in a private cloud.
29+
30+
Creation of a new cluster is a long-running operation and it might take well over 15 minutes.
31+
32+
Args:
33+
project_id: name of the project you want to use.
34+
zone: region in which your private cloud is located.
35+
private_cloud_name: name of the private cloud hosting the new cluster.
36+
cluster_name: name of the new cluster.
37+
node_count: number of nodes in the new cluster. (Must be >= 3)
38+
39+
Returns:
40+
An Operation object related to started cluster creation operation.
41+
42+
Raises:
43+
ValueError in case an incorrect number of nodes is provided.
44+
"""
45+
if node_count < 3:
46+
raise ValueError("Cluster needs to have at least 3 nodes")
47+
48+
request = vmwareengine_v1.CreateClusterRequest()
49+
request.parent = (
50+
f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
51+
)
52+
53+
request.cluster = vmwareengine_v1.Cluster()
54+
request.cluster.name = cluster_name
55+
56+
# Currently standard-72 is the only supported node type.
57+
request.cluster.node_type_configs = {
58+
"standard-72": vmwareengine_v1.NodeTypeConfig()
59+
}
60+
request.cluster.node_type_configs["standard-72"].node_count = node_count
61+
62+
client = vmwareengine_v1.VmwareEngineClient()
63+
return client.create_cluster(request)
64+
65+
66+
# [END vmwareengine_create_cluster]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START vmwareengine_create_custom_cluster]
16+
from google.api_core import operation
17+
from google.cloud import vmwareengine_v1
18+
19+
20+
def create_custom_cluster(
21+
project_id: str,
22+
zone: str,
23+
private_cloud_name: str,
24+
cluster_name: str,
25+
node_count: int = 4,
26+
core_count: int = 28,
27+
) -> operation.Operation:
28+
"""
29+
Create a new cluster with custom number of cores in its nodes
30+
in a private cloud.
31+
32+
Creation of a new cluster is a long-running operation and it might take well over 15 minutes.
33+
34+
Args:
35+
project_id: name of the project you want to use.
36+
zone: region in which your private cloud is located.
37+
private_cloud_name: name of the private cloud hosting the new cluster.
38+
cluster_name: name of the new cluster.
39+
node_count: number of nodes in the new cluster.
40+
core_count: number of CPU cores in the new cluster nodes.
41+
42+
Returns:
43+
An Operation object related to started cluster creation operation.
44+
45+
Raises:
46+
ValueError in case an incorrect number of nodes is provided.
47+
"""
48+
if node_count < 3:
49+
raise ValueError("Cluster needs to have at least 3 nodes")
50+
51+
request = vmwareengine_v1.CreateClusterRequest()
52+
request.parent = (
53+
f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}"
54+
)
55+
56+
request.cluster = vmwareengine_v1.Cluster()
57+
request.cluster.name = cluster_name
58+
59+
# Currently standard-72 is the only supported node type.
60+
request.cluster.node_type_configs = {
61+
"standard-72": vmwareengine_v1.NodeTypeConfig()
62+
}
63+
request.cluster.node_type_configs["standard-72"].node_count = node_count
64+
request.cluster.node_type_configs["standard-72"].custom_core_count = core_count
65+
66+
client = vmwareengine_v1.VmwareEngineClient()
67+
return client.create_cluster(request)
68+
69+
70+
# [END vmwareengine_create_custom_cluster]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START vmwareengine_create_legacy_network]
16+
from google.cloud import vmwareengine_v1
17+
18+
TIMEOUT = 1200 # 20 minutes
19+
20+
21+
def create_legacy_network(
22+
project_id: str, region: str
23+
) -> vmwareengine_v1.VmwareEngineNetwork:
24+
"""
25+
Creates a new legacy network.
26+
27+
Args:
28+
project_id: name of the project you want to use.
29+
region: name of the region you want to use. I.e. "us-central1"
30+
31+
Returns:
32+
The newly created VmwareEngineNetwork object.
33+
"""
34+
network = vmwareengine_v1.VmwareEngineNetwork()
35+
network.description = (
36+
"Legacy network created using vmwareengine_v1.VmwareEngineNetwork"
37+
)
38+
network.type_ = vmwareengine_v1.VmwareEngineNetwork.Type.LEGACY
39+
40+
request = vmwareengine_v1.CreateVmwareEngineNetworkRequest()
41+
request.parent = f"projects/{project_id}/locations/{region}"
42+
request.vmware_engine_network_id = f"{region}-default"
43+
request.vmware_engine_network = network
44+
45+
client = vmwareengine_v1.VmwareEngineClient()
46+
result = client.create_vmware_engine_network(request, timeout=TIMEOUT).result()
47+
48+
return result
49+
50+
51+
# [END vmwareengine_create_legacy_network]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START vmwareengine_create_policy]
16+
from google.api_core import operation
17+
from google.cloud import vmwareengine_v1
18+
19+
20+
def create_network_policy(
21+
project_id: str,
22+
region: str,
23+
ip_range: str,
24+
internet_access: bool,
25+
external_ip: bool,
26+
) -> operation.Operation:
27+
"""
28+
Creates a new network policy in a given network.
29+
30+
Args:
31+
project_id: name of the project you want to use.
32+
region: name of the region you want to use. I.e. "us-central1"
33+
ip_range: the CIDR range to use for internet access and external IP access gateways,
34+
in CIDR notation. An RFC 1918 CIDR block with a "/26" suffix is required.
35+
internet_access: should internet access be allowed.
36+
external_ip: should external IP addresses be assigned.
37+
38+
Returns:
39+
An operation object representing the started operation. You can call its .result() method to wait for
40+
it to finish.
41+
42+
Raises:
43+
ValueError if the provided ip_range doesn't end with /26.
44+
"""
45+
if not ip_range.endswith("/26"):
46+
raise ValueError(
47+
"The ip_range needs to be an RFC 1918 CIDR block with a '/26' suffix"
48+
)
49+
50+
network_policy = vmwareengine_v1.NetworkPolicy()
51+
network_policy.vmware_engine_network = f"projects/{project_id}/locations/{region}/vmwareEngineNetworks/{region}-default"
52+
network_policy.edge_services_cidr = ip_range
53+
network_policy.internet_access.enabled = internet_access
54+
network_policy.external_ip.enabled = external_ip
55+
56+
request = vmwareengine_v1.CreateNetworkPolicyRequest()
57+
request.network_policy = network_policy
58+
request.parent = f"projects/{project_id}/locations/{region}"
59+
request.network_policy_id = f"{region}-default"
60+
61+
client = vmwareengine_v1.VmwareEngineClient()
62+
return client.create_network_policy(request)
63+
64+
65+
# [END vmwareengine_create_policy]

0 commit comments

Comments
 (0)