Skip to content

Commit fed3d12

Browse files
committed
CreateInstance of GceHelper accepts arch as parameter
1 parent 4d130a1 commit fed3d12

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

tools/baseimage/cmd/create_gce_fixed_kernel/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func createImageMain(project, zone string, opts kernelImageOpts) error {
8484
}
8585
log.Printf("disk created: %q", attachedDiskName)
8686
log.Println("creating instance...")
87-
ins, err := h.CreateInstance(insName)
87+
ins, err := h.CreateInstance(insName, gce.ArchX86)
8888
if err != nil {
8989
return fmt.Errorf("failed to create instance: %w", err)
9090
}

tools/baseimage/cmd/create_gce_x86_64_image/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func createImageMain(project, zone string, opts createImageOpts) error {
8585
}
8686
log.Printf("disk created: %q", attachedDiskName)
8787
log.Println("creating instance...")
88-
ins, err := h.CreateInstance(insName)
88+
ins, err := h.CreateInstance(insName, gce.ArchX86)
8989
if err != nil {
9090
return fmt.Errorf("failed to create instance: %w", err)
9191
}

tools/baseimage/cmd/gce_install_cuttlefish_packages/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func amendImageMain(project, zone string, opts amendImageOpts) error {
184184
defer cleanupDeleteDisk(h, attachedDiskName)
185185

186186
log.Println("creating instance...")
187-
_, err = h.CreateInstance(insName)
187+
_, err = h.CreateInstance(insName, gce.ArchX86)
188188
if err != nil {
189189
return fmt.Errorf("failed to create instance: %w", err)
190190
}

tools/baseimage/pkg/gce/arch.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 The Android Open Source Project
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+
package gce
16+
17+
import (
18+
"fmt"
19+
)
20+
21+
type Arch int
22+
23+
const (
24+
ArchUnknown Arch = iota
25+
ArchX86
26+
ArchArm
27+
)
28+
29+
func ParseArch(s string) (Arch, error) {
30+
switch s {
31+
case "x86_64":
32+
return ArchX86, nil
33+
case "arm64":
34+
return ArchArm, nil
35+
default:
36+
return ArchUnknown, fmt.Errorf("unknown arch %q", s)
37+
}
38+
}

tools/baseimage/pkg/gce/helper.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,25 @@ func (h *GceHelper) DetachDisk(ins, disk string) error {
9191
return h.waitForOperation(op)
9292
}
9393

94-
func (h *GceHelper) CreateInstance(name string) (*compute.Instance, error) {
94+
func (h *GceHelper) CreateInstance(name string, arch Arch) (*compute.Instance, error) {
95+
var machineType, sourceImage string
96+
switch arch {
97+
case ArchX86:
98+
machineType = "n1-standard-16"
99+
sourceImage = "debian-12-bookworm-v20250415"
100+
case ArchArm:
101+
machineType = "t2a-standard-16"
102+
sourceImage = "debian-12-bookworm-arm64-v20250415"
103+
default:
104+
return nil, errors.New("unsupported arch")
105+
}
95106
payload := &compute.Instance{
96-
Name: name,
97-
MachineType: fmt.Sprintf("zones/%s/machineTypes/%s", h.Zone, "n1-standard-16"),
98-
MinCpuPlatform: "Intel Haswell",
107+
Name: name,
108+
MachineType: fmt.Sprintf("zones/%s/machineTypes/%s", h.Zone, machineType),
99109
Disks: []*compute.AttachedDisk{
100110
{
101111
InitializeParams: &compute.AttachedDiskInitializeParams{
102-
SourceImage: "projects/debian-cloud/global/images/debian-12-bookworm-v20250415",
112+
SourceImage: fmt.Sprintf("projects/debian-cloud/global/images/%s", sourceImage),
103113
},
104114
Boot: true,
105115
AutoDelete: true,

0 commit comments

Comments
 (0)