Skip to content

Commit bf69687

Browse files
m-strzelczykgcf-owl-bot[bot]parthea
authored
docs(samples): Samples for custom vm types (#155)
* chore(docs): Adding samples for Custom VM Types. Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 3a81c03 commit bf69687

File tree

5 files changed

+736
-6
lines changed

5 files changed

+736
-6
lines changed

compute/compute/snippets/quickstart.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
# [START compute_instances_create]
2323
# [START compute_instances_delete]
24+
import re
2425
import sys
2526

2627
# [START compute_instances_list]
@@ -149,8 +150,10 @@ def create_instance(
149150
instance = compute_v1.Instance()
150151
instance.name = instance_name
151152
instance.disks = [disk]
152-
full_machine_type_name = f"zones/{zone}/machineTypes/{machine_type}"
153-
instance.machine_type = full_machine_type_name
153+
if re.match(r"^zones/[a-z\d\-]+/machineTypes/[a-z\d\-]+$", machine_type):
154+
instance.machine_type = machine_type
155+
else:
156+
instance.machine_type = f"zones/{zone}/machineTypes/{machine_type}"
154157
instance.network_interfaces = [network_interface]
155158

156159
# Prepare the request to insert an instance.

compute/compute/snippets/sample_create_vm.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import re
1515
import sys
1616
from typing import List
1717

@@ -194,8 +194,10 @@ def create_with_disks(
194194
instance = compute_v1.Instance()
195195
instance.name = instance_name
196196
instance.disks = disks
197-
full_machine_type_name = f"zones/{zone}/machineTypes/{machine_type}"
198-
instance.machine_type = full_machine_type_name
197+
if re.match(r"^zones/[a-z\d\-]+/machineTypes/[a-z\d\-]+$", machine_type):
198+
instance.machine_type = machine_type
199+
else:
200+
instance.machine_type = f"zones/{zone}/machineTypes/{machine_type}"
199201
instance.network_interfaces = [network_interface]
200202

201203
# Shielded Instance settings

0 commit comments

Comments
 (0)