-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): adding sample for local SSD disk (#294)
* docs(samples): adding sample for local SSD disk * Updating region tag * Regenerating * Updating snippets Co-authored-by: Anthonios Partheniou <partheniou@google.com>
- Loading branch information
Showing
5 changed files
with
441 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2022 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. | ||
|
||
# This is an ingredient file. It is not meant to be run directly. Check the samples/snippets | ||
# folder for complete code samples that are ready to be used. | ||
# Disabling flake8 for the ingredients file, as it would fail F821 - undefined name check. | ||
# flake8: noqa | ||
from google.cloud import compute_v1 | ||
|
||
|
||
# <INGREDIENT local_ssd_disk> | ||
def local_ssd_disk(zone: str) -> compute_v1.AttachedDisk(): | ||
""" | ||
Create an AttachedDisk object to be used in VM instance creation. The created disk contains | ||
no data and requires formatting before it can be used. | ||
Args: | ||
zone: The zone in which the local SSD drive will be attached. | ||
Returns: | ||
AttachedDisk object configured as a local SSD disk. | ||
""" | ||
disk = compute_v1.AttachedDisk() | ||
disk.type_ = compute_v1.AttachedDisk.Type.SCRATCH.name | ||
initialize_params = compute_v1.AttachedDiskInitializeParams() | ||
initialize_params.disk_type = f"zones/{zone}/diskTypes/local-ssd" | ||
disk.initialize_params = initialize_params | ||
disk.auto_delete = True | ||
return disk | ||
# </INGREDIENT> |
43 changes: 43 additions & 0 deletions
43
compute/compute/ingredients/instances/create_start_instance/create_with_local_ssd.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,43 @@ | ||
# Copyright 2022 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. | ||
|
||
# This is an ingredient file. It is not meant to be run directly. Check the samples/snippets | ||
# folder for complete code samples that are ready to be used. | ||
# Disabling flake8 for the ingredients file, as it would fail F821 - undefined name check. | ||
# flake8: noqa | ||
|
||
from google.cloud import compute_v1 | ||
|
||
# <INGREDIENT create_with_ssd> | ||
def create_with_ssd(project_id: str, zone: str, instance_name: str) -> compute_v1.Instance: | ||
""" | ||
Create a new VM instance with Debian 10 operating system and SSD local disk. | ||
Args: | ||
project_id: project ID or project number of the Cloud project you want to use. | ||
zone: name of the zone to create the instance in. For example: "us-west3-b" | ||
instance_name: name of the new virtual machine (VM) instance. | ||
Returns: | ||
Instance object. | ||
""" | ||
newest_debian = get_image_from_family( | ||
project="debian-cloud", family="debian-10" | ||
) | ||
disk_type = f"zones/{zone}/diskTypes/pd-standard" | ||
disks = [disk_from_image(disk_type, 10, True, newest_debian.self_link, True), | ||
local_ssd_disk(zone)] | ||
instance = create_instance(project_id, zone, instance_name, disks) | ||
return instance | ||
# </INGREDIENT> |
32 changes: 32 additions & 0 deletions
32
compute/compute/recipes/instances/create_start_instance/create_with_local_ssd.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,32 @@ | ||
# Copyright 2022 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. | ||
# flake8: noqa | ||
|
||
# <REGION compute_instances_create_with_local_ssd> | ||
# <IMPORTS/> | ||
|
||
# <INGREDIENT get_image_from_family /> | ||
|
||
# <INGREDIENT disk_from_image /> | ||
|
||
# <INGREDIENT local_ssd_disk /> | ||
|
||
# <INGREDIENT wait_for_extended_operation /> | ||
|
||
|
||
# <INGREDIENT create_instance /> | ||
|
||
|
||
# <INGREDIENT create_with_ssd /> | ||
# </REGION compute_instances_create_with_local_ssd> |
Oops, something went wrong.