forked from GoogleCloudPlatform/python-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): Importing code samples for VMWare Engine (GoogleCloudP…
…latform#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]>
- Loading branch information
1 parent
bc0c7ec
commit 859efd7
Showing
33 changed files
with
1,363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
57 changes: 57 additions & 0 deletions
57
vmwareengine/cloud-client/cancel_private_cloud_deletion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# 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_cancel_cloud_deletion] | ||
from google.api_core import operation | ||
from google.cloud import vmwareengine_v1 | ||
|
||
|
||
def cancel_private_cloud_deletion_by_full_name(cloud_name: str) -> operation.Operation: | ||
""" | ||
Cancels in progress deletion of VMWare Private Cloud. | ||
Args: | ||
cloud_name: identifier of the Private Cloud you want to cancel deletion for. | ||
Expected format: | ||
projects/{project_name}/locations/{zone}/privateClouds/{cloud} | ||
Returns: | ||
An Operation object related to canceling private cloud deletion operation. | ||
""" | ||
client = vmwareengine_v1.VmwareEngineClient() | ||
request = vmwareengine_v1.UndeletePrivateCloudRequest() | ||
request.name = cloud_name | ||
return client.undelete_private_cloud(request) | ||
|
||
|
||
def cancel_private_cloud_deletion( | ||
project_id: str, zone: str, cloud_name: str | ||
) -> operation.Operation: | ||
""" | ||
Cancels in progress deletion of deletion of VMWare Private Cloud. | ||
Args: | ||
project_id: name of the project hosting the private cloud. | ||
zone: zone in which the private cloud is located in. | ||
cloud_name: name of the private cloud to cancel deletion for. | ||
Returns: | ||
An Operation object related to canceling private cloud deletion operation. | ||
""" | ||
return cancel_private_cloud_deletion_by_full_name( | ||
f"projects/{project_id}/locations/{zone}/privateClouds/{cloud_name}" | ||
) | ||
|
||
|
||
# [END vmwareengine_cancel_cloud_deletion] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# 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_create_cluster] | ||
from google.api_core import operation | ||
from google.cloud import vmwareengine_v1 | ||
|
||
|
||
def create_cluster( | ||
project_id: str, | ||
zone: str, | ||
private_cloud_name: str, | ||
cluster_name: str, | ||
node_count: int = 4, | ||
) -> operation.Operation: | ||
""" | ||
Create a new cluster in a private cloud. | ||
Creation of a new cluster is a long-running operation and it might take well over 15 minutes. | ||
Args: | ||
project_id: name of the project you want to use. | ||
zone: region in which your private cloud is located. | ||
private_cloud_name: name of the private cloud hosting the new cluster. | ||
cluster_name: name of the new cluster. | ||
node_count: number of nodes in the new cluster. (Must be >= 3) | ||
Returns: | ||
An Operation object related to started cluster creation operation. | ||
Raises: | ||
ValueError in case an incorrect number of nodes is provided. | ||
""" | ||
if node_count < 3: | ||
raise ValueError("Cluster needs to have at least 3 nodes") | ||
|
||
request = vmwareengine_v1.CreateClusterRequest() | ||
request.parent = ( | ||
f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}" | ||
) | ||
|
||
request.cluster = vmwareengine_v1.Cluster() | ||
request.cluster.name = cluster_name | ||
|
||
# Currently standard-72 is the only supported node type. | ||
request.cluster.node_type_configs = { | ||
"standard-72": vmwareengine_v1.NodeTypeConfig() | ||
} | ||
request.cluster.node_type_configs["standard-72"].node_count = node_count | ||
|
||
client = vmwareengine_v1.VmwareEngineClient() | ||
return client.create_cluster(request) | ||
|
||
|
||
# [END vmwareengine_create_cluster] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# 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_create_custom_cluster] | ||
from google.api_core import operation | ||
from google.cloud import vmwareengine_v1 | ||
|
||
|
||
def create_custom_cluster( | ||
project_id: str, | ||
zone: str, | ||
private_cloud_name: str, | ||
cluster_name: str, | ||
node_count: int = 4, | ||
core_count: int = 28, | ||
) -> operation.Operation: | ||
""" | ||
Create a new cluster with custom number of cores in its nodes | ||
in a private cloud. | ||
Creation of a new cluster is a long-running operation and it might take well over 15 minutes. | ||
Args: | ||
project_id: name of the project you want to use. | ||
zone: region in which your private cloud is located. | ||
private_cloud_name: name of the private cloud hosting the new cluster. | ||
cluster_name: name of the new cluster. | ||
node_count: number of nodes in the new cluster. | ||
core_count: number of CPU cores in the new cluster nodes. | ||
Returns: | ||
An Operation object related to started cluster creation operation. | ||
Raises: | ||
ValueError in case an incorrect number of nodes is provided. | ||
""" | ||
if node_count < 3: | ||
raise ValueError("Cluster needs to have at least 3 nodes") | ||
|
||
request = vmwareengine_v1.CreateClusterRequest() | ||
request.parent = ( | ||
f"projects/{project_id}/locations/{zone}/privateClouds/{private_cloud_name}" | ||
) | ||
|
||
request.cluster = vmwareengine_v1.Cluster() | ||
request.cluster.name = cluster_name | ||
|
||
# Currently standard-72 is the only supported node type. | ||
request.cluster.node_type_configs = { | ||
"standard-72": vmwareengine_v1.NodeTypeConfig() | ||
} | ||
request.cluster.node_type_configs["standard-72"].node_count = node_count | ||
request.cluster.node_type_configs["standard-72"].custom_core_count = core_count | ||
|
||
client = vmwareengine_v1.VmwareEngineClient() | ||
return client.create_cluster(request) | ||
|
||
|
||
# [END vmwareengine_create_custom_cluster] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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_create_legacy_network] | ||
from google.cloud import vmwareengine_v1 | ||
|
||
TIMEOUT = 1200 # 20 minutes | ||
|
||
|
||
def create_legacy_network( | ||
project_id: str, region: str | ||
) -> vmwareengine_v1.VmwareEngineNetwork: | ||
""" | ||
Creates a new legacy network. | ||
Args: | ||
project_id: name of the project you want to use. | ||
region: name of the region you want to use. I.e. "us-central1" | ||
Returns: | ||
The newly created VmwareEngineNetwork object. | ||
""" | ||
network = vmwareengine_v1.VmwareEngineNetwork() | ||
network.description = ( | ||
"Legacy network created using vmwareengine_v1.VmwareEngineNetwork" | ||
) | ||
network.type_ = vmwareengine_v1.VmwareEngineNetwork.Type.LEGACY | ||
|
||
request = vmwareengine_v1.CreateVmwareEngineNetworkRequest() | ||
request.parent = f"projects/{project_id}/locations/{region}" | ||
request.vmware_engine_network_id = f"{region}-default" | ||
request.vmware_engine_network = network | ||
|
||
client = vmwareengine_v1.VmwareEngineClient() | ||
result = client.create_vmware_engine_network(request, timeout=TIMEOUT).result() | ||
|
||
return result | ||
|
||
|
||
# [END vmwareengine_create_legacy_network] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# 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_create_policy] | ||
from google.api_core import operation | ||
from google.cloud import vmwareengine_v1 | ||
|
||
|
||
def create_network_policy( | ||
project_id: str, | ||
region: str, | ||
ip_range: str, | ||
internet_access: bool, | ||
external_ip: bool, | ||
) -> operation.Operation: | ||
""" | ||
Creates a new network policy in a given network. | ||
Args: | ||
project_id: name of the project you want to use. | ||
region: name of the region you want to use. I.e. "us-central1" | ||
ip_range: the CIDR range to use for internet access and external IP access gateways, | ||
in CIDR notation. An RFC 1918 CIDR block with a "/26" suffix is required. | ||
internet_access: should internet access be allowed. | ||
external_ip: should external IP addresses be assigned. | ||
Returns: | ||
An operation object representing the started operation. You can call its .result() method to wait for | ||
it to finish. | ||
Raises: | ||
ValueError if the provided ip_range doesn't end with /26. | ||
""" | ||
if not ip_range.endswith("/26"): | ||
raise ValueError( | ||
"The ip_range needs to be an RFC 1918 CIDR block with a '/26' suffix" | ||
) | ||
|
||
network_policy = vmwareengine_v1.NetworkPolicy() | ||
network_policy.vmware_engine_network = f"projects/{project_id}/locations/{region}/vmwareEngineNetworks/{region}-default" | ||
network_policy.edge_services_cidr = ip_range | ||
network_policy.internet_access.enabled = internet_access | ||
network_policy.external_ip.enabled = external_ip | ||
|
||
request = vmwareengine_v1.CreateNetworkPolicyRequest() | ||
request.network_policy = network_policy | ||
request.parent = f"projects/{project_id}/locations/{region}" | ||
request.network_policy_id = f"{region}-default" | ||
|
||
client = vmwareengine_v1.VmwareEngineClient() | ||
return client.create_network_policy(request) | ||
|
||
|
||
# [END vmwareengine_create_policy] |
Oops, something went wrong.