Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
docs(samples): adding sample for local SSD disk (#294)
Browse files Browse the repository at this point in the history
* 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
m-strzelczyk and parthea committed Jul 18, 2022
1 parent b595409 commit 6295ade
Show file tree
Hide file tree
Showing 5 changed files with 441 additions and 0 deletions.
41 changes: 41 additions & 0 deletions samples/ingredients/disks/local_ssd.py
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>
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>
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>
Loading

0 comments on commit 6295ade

Please sign in to comment.